Commits

William Fulton  committed bf208af Draft

Add support for SWIG - http://www.swig.org. SWIG is an extension to C++ hence the implementation is derived from CppLexer with additions to identify SWIG's special variables, such as _type, and the SWIG directives which begin with %.

  • Participants
  • Parent commits 157c9fe

Comments (0)

Files changed (2)

File pygments/lexers/_mapping.py

     'SquidConfLexer': ('pygments.lexers.text', 'SquidConf', ('squidconf', 'squid.conf', 'squid'), ('squid.conf',), ('text/x-squidconf',)),
     'SspLexer': ('pygments.lexers.templates', 'Scalate Server Page', ('ssp',), ('*.ssp',), ('application/x-ssp',)),
     'StanLexer': ('pygments.lexers.math', 'Stan', ('stan',), ('*.stan',), ()),
+    'SwigLexer': ('pygments.lexers.compiled', 'SWIG', ('swig',), ('*.swg', '*.i'), ('text/x-c++hdr', 'text/x-c++src')),
     'SystemVerilogLexer': ('pygments.lexers.hdl', 'systemverilog', ('systemverilog', 'sv'), ('*.sv', '*.svh'), ('text/x-systemverilog',)),
     'TclLexer': ('pygments.lexers.agile', 'Tcl', ('tcl',), ('*.tcl',), ('text/x-tcl', 'text/x-script.tcl', 'application/x-tcl')),
     'TcshLexer': ('pygments.lexers.shell', 'Tcsh', ('tcsh', 'csh'), ('*.tcsh', '*.csh'), ('application/x-csh',)),

File pygments/lexers/compiled.py

            'FelixLexer', 'AdaLexer', 'Modula2Lexer', 'BlitzMaxLexer',
            'NimrodLexer', 'FantomLexer', 'RustLexer', 'CudaLexer', 'MonkeyLexer',
            'DylanLidLexer', 'DylanConsoleLexer', 'CobolLexer',
-           'CobolFreeformatLexer', 'LogosLexer']
+           'SwigLexer', 'CobolFreeformatLexer', 'LogosLexer']
 
 
 class CFamilyLexer(RegexLexer):
         return 0.1
 
 
+class SwigLexer(CppLexer):
+    """
+    For `SWIG <http://www.swig.org/>`_ source code.
+    """
+    name = 'SWIG'
+    aliases = ['swig']
+    filenames = ['*.swg', '*.i']
+    mimetypes = []
+    priority = 0.1
+
+    tokens = {
+        'statements': [
+            (r'(%[a-z_]+)\b', Name.Tag),
+            ('[$][*]*[&]?[a-zA-Z0-9_]+', Name),
+            inherit,
+         ],
+    }
+    def analyse_text(text):
+        return 0.1
+
+
 class ECLexer(CLexer):
     """
     For eC source code with preprocessor directives.