diff options
author | Georg Brandl <georg@python.org> | 2016-05-17 07:29:04 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2016-05-17 07:29:04 +0200 |
commit | 4ab5f6eeb7f11ea022eb227ec47ceaada646acdc (patch) | |
tree | c1ad8b39c62e1904f3f8997d336abb6257a9a12b | |
parent | c80f19dba196d93a5e3005cf1536ecf523a33eee (diff) | |
download | pygments-git-4ab5f6eeb7f11ea022eb227ec47ceaada646acdc.tar.gz |
Rust: update keywords, highlight type and fn names
-rw-r--r-- | pygments/lexers/_mapping.py | 2 | ||||
-rw-r--r-- | pygments/lexers/rust.py | 41 |
2 files changed, 31 insertions, 12 deletions
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index dba6d69a..f8dbb918 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -278,7 +278,7 @@ LEXERS = { 'NewLispLexer': ('pygments.lexers.lisp', 'NewLisp', ('newlisp',), ('*.lsp', '*.nl'), ('text/x-newlisp', 'application/x-newlisp')), 'NewspeakLexer': ('pygments.lexers.smalltalk', 'Newspeak', ('newspeak',), ('*.ns2',), ('text/x-newspeak',)), 'NginxConfLexer': ('pygments.lexers.configs', 'Nginx configuration file', ('nginx',), (), ('text/x-nginx-conf',)), - 'NimrodLexer': ('pygments.lexers.nimrod', 'Nimrod', ('nimrod', 'nim'), ('*.nim', '*.nimrod'), ('text/x-nimrod',)), + 'NimrodLexer': ('pygments.lexers.nimrod', 'Nimrod', ('nim', 'nimrod'), ('*.nim', '*.nimrod'), ('text/x-nim',)), 'NitLexer': ('pygments.lexers.nit', 'Nit', ('nit',), ('*.nit',), ()), 'NixLexer': ('pygments.lexers.nix', 'Nix', ('nixos', 'nix'), ('*.nix',), ('text/x-nix',)), 'NumPyLexer': ('pygments.lexers.python', 'NumPy', ('numpy',), (), ()), diff --git a/pygments/lexers/rust.py b/pygments/lexers/rust.py index 5d1162b8..d3d98ee8 100644 --- a/pygments/lexers/rust.py +++ b/pygments/lexers/rust.py @@ -18,7 +18,7 @@ __all__ = ['RustLexer'] class RustLexer(RegexLexer): """ - Lexer for the Rust programming language (version 1.0). + Lexer for the Rust programming language (version 1.10). .. versionadded:: 1.6 """ @@ -49,17 +49,21 @@ class RustLexer(RegexLexer): (r"""\$([a-zA-Z_]\w*|\(,?|\),?|,?)""", Comment.Preproc), # Keywords (words(( - 'as', 'box', 'crate', 'do', 'else', 'enum', 'extern', # break and continue are in labels - 'fn', 'for', 'if', 'impl', 'in', 'loop', 'match', 'mut', 'priv', - 'proc', 'pub', 'ref', 'return', 'static', 'struct', - 'trait', 'true', 'type', 'unsafe', 'while'), suffix=r'\b'), + 'as', 'box', 'const', 'crate', 'else', 'extern', + 'for', 'if', 'impl', 'in', 'loop', 'match', 'move', + 'mut', 'pub', 'ref', 'return', 'static', 'super', + 'trait', 'unsafe', 'use', 'where', 'while'), suffix=r'\b'), Keyword), - (words(('alignof', 'be', 'const', 'offsetof', 'pure', 'sizeof', - 'typeof', 'once', 'unsized', 'yield'), suffix=r'\b'), + (words(('abstract', 'alignof', 'become', 'do', 'final', 'macro', + 'offsetof', 'override', 'priv', 'proc', 'pure', 'sizeof', + 'typeof', 'unsized', 'virtual', 'yield'), suffix=r'\b'), Keyword.Reserved), - (r'(mod|use)\b', Keyword.Namespace), (r'(true|false)\b', Keyword.Constant), + (r'mod\b', Keyword, 'modname'), (r'let\b', Keyword.Declaration), + (r'fn\b', Keyword, 'funcname'), + (r'(struct|enum|type|union)\b', Keyword, 'typename'), + (r'(default)(\s+)(type|fn)\b', bygroups(Keyword, Text, Keyword)), (words(('u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'i32', 'i64', 'usize', 'isize', 'f32', 'f64', 'str', 'bool'), suffix=r'\b'), Keyword.Type), @@ -88,11 +92,11 @@ class RustLexer(RegexLexer): 'Ok', 'Err', 'SliceConcatExt', 'String', 'ToString', - 'Vec', - ), suffix=r'\b'), + 'Vec'), suffix=r'\b'), Name.Builtin), # Labels - (r'(break|continue)(\s*)(\'[A-Za-z_]\w*)?', bygroups(Keyword, Text.Whitespace, Name.Label)), + (r'(break|continue)(\s*)(\'[A-Za-z_]\w*)?', + bygroups(Keyword, Text.Whitespace, Name.Label)), # Character Literal (r"""'(\\['"\\nrt]|\\x[0-7][0-9a-fA-F]|\\0""" r"""|\\u\{[0-9a-fA-F]{1,6}\}|.)'""", @@ -148,6 +152,21 @@ class RustLexer(RegexLexer): (r'\*/', String.Doc, '#pop'), (r'[*/]', String.Doc), ], + 'modname': [ + (r'\s+', Text), + (r'[a-zA-Z_]\w*', Name.Namespace, '#pop'), + default('#pop'), + ], + 'funcname': [ + (r'\s+', Text), + (r'[a-zA-Z_]\w*', Name.Function, '#pop'), + default('#pop'), + ], + 'typename': [ + (r'\s+', Text), + (r'[a-zA-Z_]\w*', Name.Class, '#pop'), + default('#pop'), + ], 'number_lit': [ (r'[ui](8|16|32|64|size)', Keyword, '#pop'), (r'f(32|64)', Keyword, '#pop'), |