comparison MoinMoin/support/pygments/lexers/parsers.py @ 6009:b48a69886ca4

upgrade bundled pygments to 1.6
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 05 Jan 2014 02:49:41 +0100
parents f76914e77229
children 815981fad7fd
comparison
equal deleted inserted replaced
6008:d72a5e95c7c0 6009:b48a69886ca4
3 pygments.lexers.parsers 3 pygments.lexers.parsers
4 ~~~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for parser generators. 6 Lexers for parser generators.
7 7
8 :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import re 12 import re
13 13
26 'RagelCppLexer', 'RagelObjectiveCLexer', 'RagelRubyLexer', 26 'RagelCppLexer', 'RagelObjectiveCLexer', 'RagelRubyLexer',
27 'RagelJavaLexer', 'AntlrLexer', 'AntlrPythonLexer', 27 'RagelJavaLexer', 'AntlrLexer', 'AntlrPythonLexer',
28 'AntlrPerlLexer', 'AntlrRubyLexer', 'AntlrCppLexer', 28 'AntlrPerlLexer', 'AntlrRubyLexer', 'AntlrCppLexer',
29 #'AntlrCLexer', 29 #'AntlrCLexer',
30 'AntlrCSharpLexer', 'AntlrObjectiveCLexer', 30 'AntlrCSharpLexer', 'AntlrObjectiveCLexer',
31 'AntlrJavaLexer', "AntlrActionScriptLexer"] 31 'AntlrJavaLexer', "AntlrActionScriptLexer",
32 'TreetopLexer']
32 33
33 34
34 class RagelLexer(RegexLexer): 35 class RagelLexer(RegexLexer):
35 """ 36 """
36 A pure `Ragel <http://www.complang.org/ragel/>`_ lexer. Use this for 37 A pure `Ragel <http://www.complang.org/ragel/>`_ lexer. Use this for
70 'identifiers': [ 71 'identifiers': [
71 (r'[a-zA-Z_][a-zA-Z_0-9]*', Name.Variable), 72 (r'[a-zA-Z_][a-zA-Z_0-9]*', Name.Variable),
72 ], 73 ],
73 'operators': [ 74 'operators': [
74 (r',', Operator), # Join 75 (r',', Operator), # Join
75 (r'\||&|-|--', Operator), # Union, Intersection and Subtraction 76 (r'\||&|--?', Operator), # Union, Intersection and Subtraction
76 (r'\.|<:|:>|:>>', Operator), # Concatention 77 (r'\.|<:|:>>?', Operator), # Concatention
77 (r':', Operator), # Label 78 (r':', Operator), # Label
78 (r'->', Operator), # Epsilon Transition 79 (r'->', Operator), # Epsilon Transition
79 (r'(>|\$|%|<|@|<>)(/|eof\b)', Operator), # EOF Actions 80 (r'(>|\$|%|<|@|<>)(/|eof\b)', Operator), # EOF Actions
80 (r'(>|\$|%|<|@|<>)(!|err\b)', Operator), # Global Error Actions 81 (r'(>|\$|%|<|@|<>)(!|err\b)', Operator), # Global Error Actions
81 (r'(>|\$|%|<|@|<>)(\^|lerr\b)', Operator), # Local Error Actions 82 (r'(>|\$|%|<|@|<>)(\^|lerr\b)', Operator), # Local Error Actions
391 (r'\[', Punctuation, 'nested-arg-action'), 392 (r'\[', Punctuation, 'nested-arg-action'),
392 (r'\{', Punctuation, 'action'), 393 (r'\{', Punctuation, 'action'),
393 # throwsSpec 394 # throwsSpec
394 (r'(throws)(\s+)(' + _id + ')', 395 (r'(throws)(\s+)(' + _id + ')',
395 bygroups(Keyword, Whitespace, Name.Label)), 396 bygroups(Keyword, Whitespace, Name.Label)),
396 (r'(?:(,)(\s*)(' + _id + '))+', 397 (r'(,)(\s*)(' + _id + ')',
397 bygroups(Punctuation, Whitespace, Name.Label)), # Additional throws 398 bygroups(Punctuation, Whitespace, Name.Label)), # Additional throws
398 # optionsSpec 399 # optionsSpec
399 (r'options\b', Keyword, 'options'), 400 (r'options\b', Keyword, 'options'),
400 # ruleScopeSpec - scope followed by target language code or name of action 401 # ruleScopeSpec - scope followed by target language code or name of action
401 # TODO finish implementing other possibilities for scope 402 # TODO finish implementing other possibilities for scope
691 AntlrLexer, **options) 692 AntlrLexer, **options)
692 693
693 def analyse_text(text): 694 def analyse_text(text):
694 return AntlrLexer.analyse_text(text) and \ 695 return AntlrLexer.analyse_text(text) and \
695 re.search(r'^\s*language\s*=\s*ActionScript\s*;', text, re.M) 696 re.search(r'^\s*language\s*=\s*ActionScript\s*;', text, re.M)
697
698 class TreetopBaseLexer(RegexLexer):
699 """
700 A base lexer for `Treetop <http://treetop.rubyforge.org/>`_ grammars.
701 Not for direct use; use TreetopLexer instead.
702
703 *New in Pygments 1.6.*
704 """
705
706 tokens = {
707 'root': [
708 include('space'),
709 (r'require[ \t]+[^\n\r]+[\n\r]', Other),
710 (r'module\b', Keyword.Namespace, 'module'),
711 (r'grammar\b', Keyword, 'grammar'),
712 ],
713 'module': [
714 include('space'),
715 include('end'),
716 (r'module\b', Keyword, '#push'),
717 (r'grammar\b', Keyword, 'grammar'),
718 (r'[A-Z][A-Za-z_0-9]*(?:::[A-Z][A-Za-z_0-9]*)*', Name.Namespace),
719 ],
720 'grammar': [
721 include('space'),
722 include('end'),
723 (r'rule\b', Keyword, 'rule'),
724 (r'include\b', Keyword, 'include'),
725 (r'[A-Z][A-Za-z_0-9]*', Name),
726 ],
727 'include': [
728 include('space'),
729 (r'[A-Z][A-Za-z_0-9]*(?:::[A-Z][A-Za-z_0-9]*)*', Name.Class, '#pop'),
730 ],
731 'rule': [
732 include('space'),
733 include('end'),
734 (r'"(\\\\|\\"|[^"])*"', String.Double),
735 (r"'(\\\\|\\'|[^'])*'", String.Single),
736 (r'([A-Za-z_][A-Za-z_0-9]*)(:)', bygroups(Name.Label, Punctuation)),
737 (r'[A-Za-z_][A-Za-z_0-9]*', Name),
738 (r'[()]', Punctuation),
739 (r'[?+*/&!~]', Operator),
740 (r'\[(?:\\.|\[:\^?[a-z]+:\]|[^\\\]])+\]', String.Regex),
741 (r'([0-9]*)(\.\.)([0-9]*)',
742 bygroups(Number.Integer, Operator, Number.Integer)),
743 (r'(<)([^>]+)(>)', bygroups(Punctuation, Name.Class, Punctuation)),
744 (r'{', Punctuation, 'inline_module'),
745 (r'\.', String.Regex),
746 ],
747 'inline_module': [
748 (r'{', Other, 'ruby'),
749 (r'}', Punctuation, '#pop'),
750 (r'[^{}]+', Other),
751 ],
752 'ruby': [
753 (r'{', Other, '#push'),
754 (r'}', Other, '#pop'),
755 (r'[^{}]+', Other),
756 ],
757 'space': [
758 (r'[ \t\n\r]+', Whitespace),
759 (r'#[^\n]*', Comment.Single),
760 ],
761 'end': [
762 (r'end\b', Keyword, '#pop'),
763 ],
764 }
765
766 class TreetopLexer(DelegatingLexer):
767 """
768 A lexer for `Treetop <http://treetop.rubyforge.org/>`_ grammars.
769
770 *New in Pygments 1.6.*
771 """
772
773 name = 'Treetop'
774 aliases = ['treetop']
775 filenames = ['*.treetop', '*.tt']
776
777 def __init__(self, **options):
778 super(TreetopLexer, self).__init__(RubyLexer, TreetopBaseLexer, **options)