summaryrefslogtreecommitdiff
path: root/pygments/lexers/compiled.py
diff options
context:
space:
mode:
authorWilliam Fulton <wsf@fultondesigns.co.uk>2013-05-12 13:04:32 +0100
committerWilliam Fulton <wsf@fultondesigns.co.uk>2013-05-12 13:04:32 +0100
commitc3be8e9b4f0396cf68ca5f02e5f72ee6d4c90003 (patch)
tree0bb158613f4edac350e59996c40a605ec52c0d10 /pygments/lexers/compiled.py
parent7b0a0375405276d5d4b6e855a1a47ce41696bd42 (diff)
downloadpygments-c3be8e9b4f0396cf68ca5f02e5f72ee6d4c90003.tar.gz
Less greedy detection of SWIG directives in 'analyse_text'
Diffstat (limited to 'pygments/lexers/compiled.py')
-rw-r--r--pygments/lexers/compiled.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py
index 86714aa2..c76d113d 100644
--- a/pygments/lexers/compiled.py
+++ b/pygments/lexers/compiled.py
@@ -252,7 +252,7 @@ class SwigLexer(CppLexer):
}
# This is a far from complete set of SWIG directives
- swig_directives = ( \
+ swig_directives = (
# Most common directives
'%apply', '%define', '%director', '%enddef', '%exception', '%extend',
'%feature', '%fragment', '%ignore', '%immutable', '%import', '%include',
@@ -274,7 +274,10 @@ class SwigLexer(CppLexer):
def analyse_text(text):
rv = 0.1 # Same as C/C++
- matches = re.findall(r'%[a-z_][a-z0-9_]*', text, re.M) # Search for SWIG directive
+ # Search for SWIG directives, which are conventionally at the beginning of
+ # a line. The probability of them being within a line is low, so let another
+ # lexer win in this case.
+ matches = re.findall(r'^\s*(%[a-z_][a-z0-9_]*)', text, re.M)
for m in matches:
if m in SwigLexer.swig_directives:
rv = 0.98