summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthatch <devnull@localhost>2009-01-03 16:26:11 -0600
committerthatch <devnull@localhost>2009-01-03 16:26:11 -0600
commit5ab91c0bb87e55c356a0342020afe6e0f599e5b0 (patch)
tree676d0feab0ec85132bbc6fce2b45e122d022da2b
parentd50fb7bd5a530955611bcdef66b8719085c24136 (diff)
downloadpygments-5ab91c0bb87e55c356a0342020afe6e0f599e5b0.tar.gz
Add analyse_text for all Antlr lexers, comment C version (in favor of C++)
since it's difficult to tell them apart in source files.
-rw-r--r--pygments/lexers/_mapping.py3
-rw-r--r--pygments/lexers/parsers.py63
2 files changed, 49 insertions, 17 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index 6210459a..bdf42719 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -17,11 +17,10 @@ LEXERS = {
'ActionScript3Lexer': ('pygments.lexers.web', 'ActionScript 3', ('as3', 'actionscript3'), ('*.as',), ('application/x-actionscript', 'text/x-actionscript', 'text/actionscript')),
'ActionScriptLexer': ('pygments.lexers.web', 'ActionScript', ('as', 'actionscript'), ('*.as',), ('application/x-actionscript', 'text/x-actionscript', 'text/actionscript')),
'AntlrActionScriptLexer': ('pygments.lexers.parsers', 'ANTLR With ActionScript Target', ('antlr-as', 'antlr-actionscript'), ('*.G', '*.g'), ()),
- 'AntlrCLexer': ('pygments.lexers.parsers', 'ANTLR With C Target', ('antlr-c',), ('*.G', '*.g'), ()),
'AntlrCSharpLexer': ('pygments.lexers.parsers', 'ANTLR With C# Target', ('antlr-csharp', 'antlr-c#'), ('*.G', '*.g'), ()),
'AntlrCppLexer': ('pygments.lexers.parsers', 'ANTLR With CPP Target', ('antlr-cpp',), ('*.G', '*.g'), ()),
'AntlrJavaLexer': ('pygments.lexers.parsers', 'ANTLR With Java Target', ('antlr-java',), ('*.G', '*.g'), ()),
- 'AntlrLexer': ('pygments.lexers.parsers', 'ANTLR', ('antlr',), ('*.G', '*.g'), ()),
+ 'AntlrLexer': ('pygments.lexers.parsers', 'ANTLR', ('antlr',), (), ()),
'AntlrObjectiveCLexer': ('pygments.lexers.parsers', 'ANTLR With ObjectiveC Target', ('antlr-objc',), ('*.G', '*.g'), ()),
'AntlrPerlLexer': ('pygments.lexers.parsers', 'ANTLR With Perl Target', ('antlr-perl',), ('*.G', '*.g'), ()),
'AntlrPythonLexer': ('pygments.lexers.parsers', 'ANTLR With Python Target', ('antlr-python',), ('*.G', '*.g'), ()),
diff --git a/pygments/lexers/parsers.py b/pygments/lexers/parsers.py
index 65ded89a..00f1ee3e 100644
--- a/pygments/lexers/parsers.py
+++ b/pygments/lexers/parsers.py
@@ -29,7 +29,8 @@ __all__ = ['RagelLexer', 'RagelEmbeddedLexer', 'RagelCLexer', 'RagelDLexer',
'RagelCppLexer', 'RagelObjectiveCLexer', 'RagelRubyLexer',
'RagelJavaLexer', 'AntlrLexer', 'AntlrPythonLexer',
'AntlrPerlLexer', 'AntlrRubyLexer', 'AntlrCppLexer',
- 'AntlrCLexer', 'AntlrCSharpLexer', 'AntlrObjectiveCLexer',
+ #'AntlrCLexer',
+ 'AntlrCSharpLexer', 'AntlrObjectiveCLexer',
'AntlrJavaLexer', "AntlrActionScriptLexer"]
class RagelLexer(RegexLexer):
@@ -324,7 +325,7 @@ class AntlrLexer(RegexLexer):
name = 'ANTLR'
aliases = ['antlr']
- filenames = ['*.G', '*.g']
+ filenames = []
_id = r'[A-Za-z][A-Za-z_0-9]*'
_TOKEN_REF = r'[A-Z][A-Za-z_0-9]*'
@@ -501,19 +502,27 @@ class AntlrLexer(RegexLexer):
# http://www.antlr.org/wiki/display/ANTLR3/Code+Generation+Targets
-class AntlrCLexer(DelegatingLexer):
- """
- ANTLR with C Target
-
- *New in Pygments 1.1*
- """
-
- name = 'ANTLR With C Target'
- aliases = ['antlr-c']
- filenames = ['*.G', '*.g']
-
- def __init__(self, **options):
- super(AntlrCLexer, self).__init__(CLexer, AntlrLexer, **options)
+# TH: I'm not aware of any language features of C++ that will cause
+# incorrect lexing of C files. Antlr doesn't appear to make a distinction,
+# so just assume they're C++. No idea how to make Objective C work in the
+# future.
+
+#class AntlrCLexer(DelegatingLexer):
+# """
+# ANTLR with C Target
+#
+# *New in Pygments 1.1*
+# """
+#
+# name = 'ANTLR With C Target'
+# aliases = ['antlr-c']
+# filenames = ['*.G', '*.g']
+#
+# def __init__(self, **options):
+# super(AntlrCLexer, self).__init__(CLexer, AntlrLexer, **options)
+#
+# def analyse_text(text):
+# return re.match(r'^\s*language\s*=\s*C\s*;', text)
class AntlrCppLexer(DelegatingLexer):
"""
@@ -529,6 +538,9 @@ class AntlrCppLexer(DelegatingLexer):
def __init__(self, **options):
super(AntlrCppLexer, self).__init__(CppLexer, AntlrLexer, **options)
+ def analyse_text(text):
+ return re.match(r'^\s*language\s*=\s*C\s*;', text, re.M)
+
class AntlrObjectiveCLexer(DelegatingLexer):
"""
ANTLR with ObjectiveC Target
@@ -544,6 +556,9 @@ class AntlrObjectiveCLexer(DelegatingLexer):
super(AntlrObjectiveCLexer, self).__init__(ObjectiveCLexer,
AntlrLexer, **options)
+ def analyse_text(text):
+ return re.match(r'^\s*language\s*=\s*C\s*;', text)
+
class AntlrCSharpLexer(DelegatingLexer):
"""
ANTLR with C# Target
@@ -559,6 +574,9 @@ class AntlrCSharpLexer(DelegatingLexer):
super(AntlrCSharpLexer, self).__init__(CSharpLexer, AntlrLexer,
**options)
+ def analyse_text(text):
+ return re.match(r'^\s*language\s*=\s*CSharp2\s*;', text, re.M)
+
class AntlrPythonLexer(DelegatingLexer):
"""
ANTLR with Python Target
@@ -574,6 +592,9 @@ class AntlrPythonLexer(DelegatingLexer):
super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer,
**options)
+ def analyse_text(text):
+ return re.match(r'^\s*language\s*=\s*Python\s*;', text, re.M)
+
class AntlrJavaLexer(DelegatingLexer):
"""
@@ -590,6 +611,9 @@ class AntlrJavaLexer(DelegatingLexer):
super(AntlrJavaLexer, self).__init__(JavaLexer, AntlrLexer,
**options)
+ def analyse_text(text):
+ return 0.5 # Antlr is Java if not specified
+
class AntlrRubyLexer(DelegatingLexer):
"""
@@ -606,6 +630,9 @@ class AntlrRubyLexer(DelegatingLexer):
super(AntlrRubyLexer, self).__init__(RubyLexer, AntlrLexer,
**options)
+ def analyse_text(text):
+ return re.match(r'^\s*language\s*=\s*Ruby\s*;', text, re.M)
+
class AntlrPerlLexer(DelegatingLexer):
"""
ANTLR with Perl Target
@@ -621,6 +648,9 @@ class AntlrPerlLexer(DelegatingLexer):
super(AntlrPerlLexer, self).__init__(PerlLexer, AntlrLexer,
**options)
+ def analyse_text(text):
+ return re.match(r'^\s*language\s*=\s*Perl5\s*;', text, re.M)
+
class AntlrActionScriptLexer(DelegatingLexer):
"""
ANTLR with ActionScript Target
@@ -635,3 +665,6 @@ class AntlrActionScriptLexer(DelegatingLexer):
def __init__(self, **options):
super(AntlrActionScriptLexer, self).__init__(ActionScriptLexer,
AntlrLexer, **options)
+
+ def analyse_text(text):
+ return re.match(r'^\s*language\s*=\s*ActionScript\s*;', text, re.M)