diff options
author | Jon Morton <jonanin@gmail.com> | 2012-04-06 09:50:57 -0500 |
---|---|---|
committer | Jon Morton <jonanin@gmail.com> | 2012-04-06 09:50:57 -0500 |
commit | bcc1d6f6d25e4401f92a1add54b09ad0f98b0e4d (patch) | |
tree | 1488e19be3aa4476bb1555536300b8dd74ef611f /pygments | |
parent | b70d989a1b9c06b62e816a65675402f8c44ab363 (diff) | |
download | pygments-bcc1d6f6d25e4401f92a1add54b09ad0f98b0e4d.tar.gz |
Add Rust syntax highlighting
Diffstat (limited to 'pygments')
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/compiled.py | 68 |
2 files changed, 68 insertions, 1 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 8bcc1744..feb6d580 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -211,6 +211,7 @@ LEXERS = { 'RstLexer': ('pygments.lexers.text', 'reStructuredText', ('rst', 'rest', 'restructuredtext'), ('*.rst', '*.rest'), ('text/x-rst', 'text/prs.fallenstein.rst')), 'RubyConsoleLexer': ('pygments.lexers.agile', 'Ruby irb session', ('rbcon', 'irb'), (), ('text/x-ruby-shellsession',)), 'RubyLexer': ('pygments.lexers.agile', 'Ruby', ('rb', 'ruby', 'duby'), ('*.rb', '*.rbw', 'Rakefile', '*.rake', '*.gemspec', '*.rbx', '*.duby'), ('text/x-ruby', 'application/x-ruby')), + 'RustLexer': ('pygments.lexers.compiled', 'Rust', ('rs', 'rc'), ('*.rs', '*.rc'), ('text/x-rustsrc')), 'SLexer': ('pygments.lexers.math', 'S', ('splus', 's', 'r'), ('*.S', '*.R'), ('text/S-plus', 'text/S', 'text/R')), 'SMLLexer': ('pygments.lexers.functional', 'Standard ML', ('sml',), ('*.sml', '*.sig', '*.fun'), ('text/x-standardml', 'application/x-standardml')), 'SassLexer': ('pygments.lexers.web', 'Sass', ('sass', 'SASS'), ('*.sass',), ('text/x-sass',)), diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index 04077ec6..c024e970 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -27,7 +27,7 @@ __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer', 'DylanLexer', 'ObjectiveCLexer', 'FortranLexer', 'GLShaderLexer', 'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer', 'FelixLexer', 'AdaLexer', 'Modula2Lexer', 'BlitzMaxLexer', - 'NimrodLexer', 'FantomLexer'] + 'NimrodLexer', 'FantomLexer', 'RustLexer'] class CLexer(RegexLexer): @@ -2889,3 +2889,69 @@ class FantomLexer(RegexLexer): (r'.', Text) ], } + +class RustLexer(RegexLexer): + """ + Lexer for Mozilla's Rust programming language + """ + name = 'Rust' + filenames = ['*.rs', '*.rc'] + aliases = ['rust'] + mimetypes = ['text/x-rustsrc'] + + tokens = { + 'root': [ + # Whitespace and Comments + (r'\n', Text), + (r'\s+', Text), + (r'//(.*?)\n', Comment.Single), + (r'/[*](.|\n)*?[*]/', Comment.Multiline), + + # Keywords + (r'(alt|as|assert|be|break|check|claim|class|const' + r'|cont|copy|crust|do|else|enum|export|fail' + r'|false|fn|for|if|iface|impl|import|let|log' + r'|loop|mod|mut|native|pure|resource|ret|true' + r'|type|unsafe|use|white|note|bind|prove|unchecked' + r'|with|syntax)', Keyword), + + # Character Literal + (r"""'(\\['"?\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" + r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|.)'""", + String.Char), + # Binary Literal + (r'0[Bb][01_]+([ui](8|16|32|64)?)?', Number), + # Octal Literal + (r'0[0-7_]+([ui](8|16|32|64))?', Number.Oct), + # Hexadecimal Literal + (r'0[xX][0-9a-fA-F_]+([ui](8|16|32|64))?', Number.Hex), + # Decimal Literal + (r'[0-9][0-9_]*(([ui](8|16|32|64)?)|(\.[0-9_]+[eE][+\-]?' + r'[0-9_]+|\.[0-9_]*|[eE][+\-]?[0-9_]+))?(f(32|64)?)?', Number), + # String Literal + (r'"', String, 'string'), + + # Operators and Punctuation + (r'[{}()\[\],.;]', Punctuation), + (r'[+\-*/%&|<>^!~@=:?]', Operator), + + # Identifier + (r'[a-zA-Z_$][a-zA-Z0-9_]*', Name), + + # Attributes / Preprocessor + (r'#\[', Comment.Preproc, 'attribute') + ], + 'string': { + (r'"', String, '#pop'), + (r"""\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" + r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}""", String.Escape), + (r'[^\\"]+', String), + (r'\\', String) + }, + 'attribute': { + (r'"', String, 'string'), + (r'\];?', Comment.Preproc, '#pop'), + (r'[^"\]]+', Comment.Preproc) + } + } + |