summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pygments/lexer.py21
-rw-r--r--pygments/lexers/compiled.py26
2 files changed, 18 insertions, 29 deletions
diff --git a/pygments/lexer.py b/pygments/lexer.py
index 8535d086..b8cf69fb 100644
--- a/pygments/lexer.py
+++ b/pygments/lexer.py
@@ -442,7 +442,7 @@ class RegexLexerMeta(LexerMeta):
if isinstance(tdef, _inherit):
# processed already
continue
-
+
assert type(tdef) is tuple, "wrong rule def %r" % tdef
try:
@@ -494,30 +494,29 @@ class RegexLexerMeta(LexerMeta):
try:
inherit_ndx = items.index(inherit)
- except:
- inherit_ndx = -1
-
- if inherit_ndx != -1:
- inheritable[state] = inherit_ndx
+ except ValueError:
+ continue
+
+ inheritable[state] = inherit_ndx
continue
-
+
inherit_ndx = inheritable.pop(state, None)
if inherit_ndx is None:
continue
# Replace the "inherit" value with the items
curitems[inherit_ndx:inherit_ndx+1] = items
-
+
try:
new_inh_ndx = items.index(inherit)
- except:
+ except ValueError:
new_inh_ndx = -1
-
+
if new_inh_ndx != -1:
inheritable[state] = inherit_ndx + new_inh_ndx
return tokens
-
+
def __call__(cls, *args, **kwds):
"""Instantiate cls after preprocessing its token definitions."""
if '_tokens' not in cls.__dict__:
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py
index 5ecc7759..83865e26 100644
--- a/pygments/lexers/compiled.py
+++ b/pygments/lexers/compiled.py
@@ -181,12 +181,7 @@ class CLexer(CFamilyLexer):
aliases = ['c']
filenames = ['*.c', '*.h', '*.idc']
mimetypes = ['text/x-chdr', 'text/x-csrc']
- priority = 0.5
-
- def analyse_text(text):
- # We return 0.5 to allow other C-family languages that use .h files
- # to check them to see if they are, in fact, not plain C
- return 0.5
+ priority = 0.1
class CppLexer(CFamilyLexer):
"""
@@ -198,8 +193,8 @@ class CppLexer(CFamilyLexer):
'*.cc', '*.hh', '*.cxx', '*.hxx',
'*.C', '*.H', '*.cp', '*.CPP']
mimetypes = ['text/x-c++hdr', 'text/x-c++src']
- priority = 0.5
-
+ priority = 0.1
+
tokens = {
'statements': [
(r'(asm|catch|const_cast|delete|dynamic_cast|explicit|'
@@ -225,11 +220,6 @@ class CppLexer(CFamilyLexer):
],
}
- def analyse_text(text):
- # We return 0.5 to allow other C-family languages that use .h files
- # to check them to see if they are, in fact, not plain C++
- return 0.5
-
class ECLexer(CLexer):
"""
For eC source code with preprocessor directives.
@@ -263,7 +253,7 @@ class ECLexer(CLexer):
(r'\s*(?=>)', Text, '#pop'),
],
}
-
+
class DLexer(RegexLexer):
"""
For D source.
@@ -1059,8 +1049,8 @@ class ObjectiveCLexer(objective(CLexer)):
aliases = ['objective-c', 'objectivec', 'obj-c', 'objc']
filenames = ['*.m', '*.h']
mimetypes = ['text/x-objective-c']
- priority = 0.25
-
+ priority = 0.05 # Lower than C
+
class ObjectiveCppLexer(objective(CppLexer)):
"""
For Objective-C++ source code with preprocessor directives.
@@ -1070,8 +1060,8 @@ class ObjectiveCppLexer(objective(CppLexer)):
aliases = ['objective-c++', 'objectivec++', 'obj-c++', 'objc++']
filenames = ['*.mm', '*.hh']
mimetypes = ['text/x-objective-c++']
- priority = 0.25
-
+ priority = 0.05 # Lower than C++
+
class FortranLexer(RegexLexer):
"""
Lexer for FORTRAN 90 code.