diff options
author | Georg Brandl <georg@python.org> | 2017-01-22 17:53:46 +0000 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2017-01-22 17:53:46 +0000 |
commit | 0e2314f0cebe65594af7a1eb0b2164cce827558c (patch) | |
tree | d1d8595b8f78cc5949bba6a7634ecddd4e675d0e /pygments/lexers/rust.py | |
parent | 045732d3501cdb693537145393bc25411a4eeb84 (diff) | |
parent | b1bad5b7f9f574a6345587fad2850b18b2707eb7 (diff) | |
download | pygments-0e2314f0cebe65594af7a1eb0b2164cce827558c.tar.gz |
Merged in belak/pygments-main/lexer-delphi-dpr-ext (pull request #655)
Match .dpr files as Delphi
Diffstat (limited to 'pygments/lexers/rust.py')
-rw-r--r-- | pygments/lexers/rust.py | 71 |
1 files changed, 41 insertions, 30 deletions
diff --git a/pygments/lexers/rust.py b/pygments/lexers/rust.py index d3d98ee8..6914f54d 100644 --- a/pygments/lexers/rust.py +++ b/pygments/lexers/rust.py @@ -5,7 +5,7 @@ Lexers for the Rust language. - :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. + :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. """ @@ -27,6 +27,35 @@ class RustLexer(RegexLexer): aliases = ['rust'] mimetypes = ['text/rust'] + keyword_types = ( + words(('u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'i32', 'i64', + 'usize', 'isize', 'f32', 'f64', 'str', 'bool'), + suffix=r'\b'), + Keyword.Type) + + builtin_types = (words(( + # Reexported core operators + 'Copy', 'Send', 'Sized', 'Sync', + 'Drop', 'Fn', 'FnMut', 'FnOnce', + + # Reexported types and traits + 'Box', + 'ToOwned', + 'Clone', + 'PartialEq', 'PartialOrd', 'Eq', 'Ord', + 'AsRef', 'AsMut', 'Into', 'From', + 'Default', + 'Iterator', 'Extend', 'IntoIterator', + 'DoubleEndedIterator', 'ExactSizeIterator', + 'Option', + 'Some', 'None', + 'Result', + 'Ok', 'Err', + 'SliceConcatExt', + 'String', 'ToString', + 'Vec'), suffix=r'\b'), + Name.Builtin) + tokens = { 'root': [ # rust allows a file to start with a shebang, but if the first line @@ -64,36 +93,14 @@ class RustLexer(RegexLexer): (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), + keyword_types, (r'self\b', Name.Builtin.Pseudo), # Prelude (taken from Rust’s src/libstd/prelude.rs) - (words(( - # Reexported core operators - 'Copy', 'Send', 'Sized', 'Sync', - 'Drop', 'Fn', 'FnMut', 'FnOnce', - - # Reexported functions - 'drop', - - # Reexported types and traits - 'Box', - 'ToOwned', - 'Clone', - 'PartialEq', 'PartialOrd', 'Eq', 'Ord', - 'AsRef', 'AsMut', 'Into', 'From', - 'Default', - 'Iterator', 'Extend', 'IntoIterator', - 'DoubleEndedIterator', 'ExactSizeIterator', - 'Option', - 'Some', 'None', - 'Result', - 'Ok', 'Err', - 'SliceConcatExt', - 'String', 'ToString', - 'Vec'), suffix=r'\b'), - Name.Builtin), + builtin_types, + # Path seperators, so types don't catch them. + (r'::\b', Text), + # Types in positions. + (r'(?::|->)', Text, 'typename'), # Labels (r'(break|continue)(\s*)(\'[A-Za-z_]\w*)?', bygroups(Keyword, Text.Whitespace, Name.Label)), @@ -112,7 +119,8 @@ class RustLexer(RegexLexer): (r'0[xX][0-9a-fA-F_]+', Number.Hex, 'number_lit'), # Decimal Literal (r'[0-9][0-9_]*(\.[0-9_]+[eE][+\-]?[0-9_]+|' - r'\.[0-9_]*(?!\.)|[eE][+\-]?[0-9_]+)', Number.Float, 'number_lit'), + r'\.[0-9_]*(?!\.)|[eE][+\-]?[0-9_]+)', Number.Float, + 'number_lit'), (r'[0-9][0-9_]*', Number.Integer, 'number_lit'), # String Literal (r'b"', String, 'bytestring'), @@ -164,6 +172,9 @@ class RustLexer(RegexLexer): ], 'typename': [ (r'\s+', Text), + (r'&', Keyword.Pseudo), + builtin_types, + keyword_types, (r'[a-zA-Z_]\w*', Name.Class, '#pop'), default('#pop'), ], |