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 |
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) |