Anonymous avatar Anonymous committed e48424a

Fix ANTLR analyse_text functions.

Comments (0)

Files changed (1)

pygments/lexers/parsers.py

         ]
     }
 
+    def analyse_text(text):
+        return re.search(r'^\s*grammar\s+[a-zA-Z0-9]+\s*;', text, re.M)
+
 # http://www.antlr.org/wiki/display/ANTLR3/Code+Generation+Targets
 
 # TH: I'm not aware of any language features of C++ that will cause
         super(AntlrCppLexer, self).__init__(CppLexer, AntlrLexer, **options)
 
     def analyse_text(text):
-        return re.match(r'^\s*language\s*=\s*C\s*;', text, re.M)
+        return AntlrLexer.analyse_text(text) and \
+               re.search(r'^\s*language\s*=\s*C\s*;', text, re.M)
 
 
 class AntlrObjectiveCLexer(DelegatingLexer):
                                                    AntlrLexer, **options)
 
     def analyse_text(text):
-        return re.match(r'^\s*language\s*=\s*ObjC\s*;', text)
+        return AntlrLexer.analyse_text(text) and \
+               re.search(r'^\s*language\s*=\s*ObjC\s*;', text)
 
 
 class AntlrCSharpLexer(DelegatingLexer):
                                                **options)
 
     def analyse_text(text):
-        return re.match(r'^\s*language\s*=\s*CSharp2\s*;', text, re.M)
+        return AntlrLexer.analyse_text(text) and \
+               re.search(r'^\s*language\s*=\s*CSharp2\s*;', text, re.M)
 
 
 class AntlrPythonLexer(DelegatingLexer):
                                                **options)
 
     def analyse_text(text):
-        return re.match(r'^\s*language\s*=\s*Python\s*;', text, re.M)
+        return AntlrLexer.analyse_text(text) and \
+               re.search(r'^\s*language\s*=\s*Python\s*;', text, re.M)
 
 
 class AntlrJavaLexer(DelegatingLexer):
                                              **options)
 
     def analyse_text(text):
-        return 0.5 # Antlr is Java if not specified
+        # Antlr language is Java by default
+        return AntlrLexer.analyse_text(text) and 0.9
 
 
 class AntlrRubyLexer(DelegatingLexer):
                                              **options)
 
     def analyse_text(text):
-        return re.match(r'^\s*language\s*=\s*Ruby\s*;', text, re.M)
+        return AntlrLexer.analyse_text(text) and \
+               re.search(r'^\s*language\s*=\s*Ruby\s*;', text, re.M)
 
 
 class AntlrPerlLexer(DelegatingLexer):
                                              **options)
 
     def analyse_text(text):
-        return re.match(r'^\s*language\s*=\s*Perl5\s*;', text, re.M)
+        return AntlrLexer.analyse_text(text) and \
+               re.search(r'^\s*language\s*=\s*Perl5\s*;', text, re.M)
 
 
 class AntlrActionScriptLexer(DelegatingLexer):
                                                      AntlrLexer, **options)
 
     def analyse_text(text):
-        return re.match(r'^\s*language\s*=\s*ActionScript\s*;', text, re.M)
+        return AntlrLexer.analyse_text(text) and \
+               re.search(r'^\s*language\s*=\s*ActionScript\s*;', text, re.M)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.