diff options
author | thatch <devnull@localhost> | 2009-01-03 12:41:22 -0600 |
---|---|---|
committer | thatch <devnull@localhost> | 2009-01-03 12:41:22 -0600 |
commit | 99557ce09b851ee33c74cb88fa9c077e063fdcc0 (patch) | |
tree | bd21609322f20d4afd18f7d21d75d562b46e737f /pygments/lexers/parsers.py | |
parent | fdcc6045ce39d603ff76df9d2b6b7e584e78c47a (diff) | |
download | pygments-99557ce09b851ee33c74cb88fa9c077e063fdcc0.tar.gz |
Add analyse_text to Ragel parsers, fix roundtrip error (the following text
demonstrates it on the antlr lexer itself, even without delegating):
{{{
t$WS,FLzL;7HcxdYq"Afx:~@(oreV-8X_/d2-yC`
}}}
Diffstat (limited to 'pygments/lexers/parsers.py')
-rw-r--r-- | pygments/lexers/parsers.py | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/pygments/lexers/parsers.py b/pygments/lexers/parsers.py index b2b460e7..c70d134e 100644 --- a/pygments/lexers/parsers.py +++ b/pygments/lexers/parsers.py @@ -191,7 +191,10 @@ class RagelEmbeddedLexer(RegexLexer): (r'}%%', Punctuation, '#pop'), ] - } + } + + def analyse_text(text): + return '@LANG: indep' in text class RagelRubyLexer(DelegatingLexer): """ @@ -203,7 +206,11 @@ class RagelRubyLexer(DelegatingLexer): filenames = ['*.rl'] def __init__(self, **options): - super(RagelRubyLexer, self).__init__(RubyLexer, RagelEmbeddedLexer, **options) + super(RagelRubyLexer, self).__init__(RubyLexer, RagelEmbeddedLexer, + **options) + + def analyse_text(text): + return '@LANG: ruby' in text class RagelCLexer(DelegatingLexer): """ @@ -215,7 +222,11 @@ class RagelCLexer(DelegatingLexer): filenames = ['*.rl'] def __init__(self, **options): - super(RagelCLexer, self).__init__(CLexer, RagelEmbeddedLexer, **options) + super(RagelCLexer, self).__init__(CLexer, RagelEmbeddedLexer, + **options) + + def analyse_text(text): + return '@LANG: c' in text class RagelDLexer(DelegatingLexer): """ @@ -229,6 +240,9 @@ class RagelDLexer(DelegatingLexer): def __init__(self, **options): super(RagelDLexer, self).__init__(DLexer, RagelEmbeddedLexer, **options) + def analyse_text(text): + return '@LANG: d' in text + class RagelCppLexer(DelegatingLexer): """ A lexer for Ragel in a CPP host file @@ -241,6 +255,9 @@ class RagelCppLexer(DelegatingLexer): def __init__(self, **options): super(RagelCppLexer, self).__init__(CppLexer, RagelEmbeddedLexer, **options) + def analyse_text(text): + return '@LANG: c++' in text + class RagelObjectiveCLexer(DelegatingLexer): """ A lexer for Ragel in an Objective C host file @@ -254,6 +271,9 @@ class RagelObjectiveCLexer(DelegatingLexer): super(RagelObjectiveCLexer, self).__init__(ObjectiveCLexer, \ RagelEmbeddedLexer, **options) + def analyse_text(text): + return '@LANG: objc' in text + class RagelJavaLexer(DelegatingLexer): """ A lexer for Ragel in a Java host file @@ -266,6 +286,9 @@ class RagelJavaLexer(DelegatingLexer): def __init__(self, **options): super(RagelJavaLexer, self).__init__(JavaLexer, RagelEmbeddedLexer, **options) + def analyse_text(text): + return '@LANG: java' in text + class AntlrLexer(RegexLexer): """ Generic ANTLR Lexer. @@ -335,7 +358,7 @@ class AntlrLexer(RegexLexer): # throwsSpec (r'(throws)(\s+)(' + _id + ')', bygroups(Keyword, Whitespace, \ Name.Label)), - (r'((,)(\s*)(' + _id + '))+', bygroups(Punctuation, Whitespace, \ + (r'(?:(,)(\s*)(' + _id + '))+', bygroups(Punctuation, Whitespace, \ Name.Label)), # Additional throws # optionsSpec (r'options\b', Keyword, 'options'), |