diff options
author | William Fulton <wsf@fultondesigns.co.uk> | 2013-05-11 18:35:23 +0100 |
---|---|---|
committer | William Fulton <wsf@fultondesigns.co.uk> | 2013-05-11 18:35:23 +0100 |
commit | 32249bab14fbdb7191e95b26e4f0ed3ee6235bb2 (patch) | |
tree | da3d5864810fa24a28145915ce592fb09ce1c3c9 /pygments/lexers/compiled.py | |
parent | f47132e321f179ec3f8124ffb87e420cf737bf29 (diff) | |
download | pygments-32249bab14fbdb7191e95b26e4f0ed3ee6235bb2.tar.gz |
Detect SWIG directives in 'analyse_text'. Some commonly known directives are detected with high priority. Unlisted, but possible SWIG directives are given a lower priority, but there is a conflict with Matlab comments. Perhaps the Matlab lexer should be improved?
Diffstat (limited to 'pygments/lexers/compiled.py')
-rw-r--r-- | pygments/lexers/compiled.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index 1d0cdf08..a536ef40 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -249,8 +249,38 @@ class SwigLexer(CppLexer): inherit, ], } + + # This is a far from complete set of SWIG directives + swig_directives = ( \ + # Most common directives + '%apply', '%define', '%director', '%enddef', '%exception', '%extend', + '%feature', '%fragment', '%ignore', '%immutable', '%import', '%include', + '%inline', '%insert', '%module', '%newobject', '%nspace', '%pragma', + '%rename', '%shared_ptr', '%template', '%typecheck', '%typemap', + # Less common directives + '%arg', '%attribute', '%bang', '%begin', '%callback', '%catches', '%clear', + '%constant', '%copyctor', '%csconst', '%csconstvalue', '%csenum', + '%csmethodmodifiers', '%csnothrowexception', '%default', '%defaultctor', + '%defaultdtor', '%defined', '%delete', '%delobject', '%descriptor', + '%exceptionclass', '%exceptionvar', '%extend_smart_pointer', '%fragments', + '%header', '%ifcplusplus', '%ignorewarn', '%implicit', '%implicitconv', + '%init', '%javaconst', '%javaconstvalue', '%javaenum', '%javaexception', + '%javamethodmodifiers', '%kwargs', '%luacode', '%mutable', '%naturalvar', + '%nestedworkaround', '%perlcode', '%pythonabc', '%pythonappend', + '%pythoncallback', '%pythoncode', '%pythondynamic', '%pythonmaybecall', + '%pythonnondynamic', '%pythonprepend', '%refobject', '%shadow', '%sizeof', + '%trackobjects', '%types', '%unrefobject', '%varargs', '%warn', '%warnfilter') + def analyse_text(text): - return 0.1 + rv = 0.1 # Same as C/C++ + matches = re.findall(r'%[a-z_][a-z0-9_]*', text, re.M) # Search for SWIG directive + for m in matches: + if m in SwigLexer.swig_directives: + rv = 0.98 + break + else: + rv = 0.91 # Fraction higher than MatlabLexer + return rv class ECLexer(CLexer): |