diff options
author | William Fulton <wsf@fultondesigns.co.uk> | 2013-05-12 13:04:32 +0100 |
---|---|---|
committer | William Fulton <wsf@fultondesigns.co.uk> | 2013-05-12 13:04:32 +0100 |
commit | c3be8e9b4f0396cf68ca5f02e5f72ee6d4c90003 (patch) | |
tree | 0bb158613f4edac350e59996c40a605ec52c0d10 | |
parent | 7b0a0375405276d5d4b6e855a1a47ce41696bd42 (diff) | |
download | pygments-c3be8e9b4f0396cf68ca5f02e5f72ee6d4c90003.tar.gz |
Less greedy detection of SWIG directives in 'analyse_text'
-rw-r--r-- | pygments/lexers/compiled.py | 7 |
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 |