diff options
author | Chris Morgan <me@chrismorgan.info> | 2015-03-28 17:35:12 +1100 |
---|---|---|
committer | Chris Morgan <me@chrismorgan.info> | 2015-03-28 17:35:12 +1100 |
commit | db77d4873ca2858446132608272f05bb83aa7ada (patch) | |
tree | 41adadfe742649f5ebbdea8161a49213b7c63b40 | |
parent | 3e3640376657ce29367df2eae36d0856a2405f81 (diff) | |
download | pygments-db77d4873ca2858446132608272f05bb83aa7ada.tar.gz |
Rust lexer updates for language changes.
- In strings and character and byte literals,
``\uXXXX`` and ``\UXXXXXXXX`` have been replaced with ``\u{X}``.
- ``int`` and ``uint`` are now ``isize`` and ``usize``,
including their literal form suffixes.
- ``crate`` is a keyword.
- Prelude items are updated.
-rw-r--r-- | pygments/lexers/rust.py | 67 |
1 files changed, 19 insertions, 48 deletions
diff --git a/pygments/lexers/rust.py b/pygments/lexers/rust.py index e64657c9..354ab2be 100644 --- a/pygments/lexers/rust.py +++ b/pygments/lexers/rust.py @@ -40,7 +40,7 @@ class RustLexer(RegexLexer): (r"""\$([a-zA-Z_]\w*|\(,?|\),?|,?)""", Comment.Preproc), # Keywords (words(( - 'as', 'box', 'do', 'else', 'enum', 'extern', # break and continue are in labels + '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'), @@ -51,77 +51,48 @@ class RustLexer(RegexLexer): (r'(mod|use)\b', Keyword.Namespace), (r'(true|false)\b', Keyword.Constant), (r'let\b', Keyword.Declaration), - (words(('u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'i32', 'i64', 'uint', - 'int', 'f32', 'f64', 'str', 'bool'), suffix=r'\b'), + (words(('u8', 'u16', 'u32', 'u64', 'i8', 'i16', 'i32', 'i64', 'usize', + 'isize', 'f32', 'f64', 'str', 'bool'), suffix=r'\b'), Keyword.Type), (r'self\b', Name.Builtin.Pseudo), # Prelude (taken from Rust’s src/libstd/prelude.rs) (words(( # Reexported core operators 'Copy', 'Send', 'Sized', 'Sync', - 'Add', 'Sub', 'Mul', 'Div', 'Rem', 'Neg', 'Not', - 'BitAnd', 'BitOr', 'BitXor', - 'Drop', 'Deref', 'DerefMut', - 'Shl', 'Shr', - 'Index', 'IndexMut', - 'Slice', 'SliceMut', - 'Fn', 'FnMut', 'FnOnce', + 'Drop', 'Fn', 'FnMut', 'FnOnce', # Reexported functions - 'range', 'drop', - 'from_str', # Reexported types and traits - 'Ascii', 'AsciiCast', 'OwnedAsciiCast', 'AsciiStr', - 'IntoBytes', - 'IntoCow', - 'ToCStr', - 'Char', 'UnicodeChar', + 'Box', 'Clone', + 'IntoCow', 'PartialEq', 'PartialOrd', 'Eq', 'Ord', - 'Ordering', 'Equiv', - 'Less', 'Equal', 'Greater', - 'FromIterator', 'Extend', 'ExactSizeIterator', - 'Iterator', 'IteratorExt', 'DoubleEndedIterator', - 'DoubleEndedIteratorExt', 'CloneIteratorExt', - 'RandomAccessIterator', 'IteratorCloneExt', - 'IteratorOrdExt', 'MutableDoubleEndedIterator', - 'ToPrimitive', 'FromPrimitive', - 'Box', + 'AsRef', 'AsMut', 'Into', 'From', + 'DoubleEndedIterator', + 'ExactSizeIterator', + 'Iterator', 'IteratorExt', 'Extend', 'Option', 'Some', 'None', - 'GenericPath', 'Path', 'PosixPath', 'WindowsPath', - 'RawPtr', 'RawMutPtr', 'Result', 'Ok', 'Err', - 'Buffer', 'Writer', 'Reader', 'Seek', 'BufferPrelude', - 'Str', 'StrVector', 'StrPrelude', - 'StrAllocating', 'UnicodeStrPrelude', - 'Tuple1', 'Tuple2', 'Tuple3', 'Tuple4', - 'Tuple5', 'Tuple6', 'Tuple7', 'Tuple8', - 'Tuple9', 'Tuple10', 'Tuple11', 'Tuple12', - 'SlicePrelude', 'AsSlice', 'CloneSlicePrelude', - 'VectorVector', 'PartialEqSlicePrelude', 'OrdSlicePrelude', - 'CloneSliceAllocPrelude', 'OrdSliceAllocPrelude', 'SliceAllocPrelude', - 'BoxedSlicePrelude', - 'IntoString', 'String', 'ToString', + 'SliceConcatExt', 'AsSlice', + 'Str', + 'String', 'ToString', 'Vec', - # Reexported runtime types - 'sync_channel', 'channel', - 'SyncSender', 'Sender', 'Receiver', - 'spawn', + 'Wrapping', 'WrappingOps', ), suffix=r'\b'), Name.Builtin), # Labels (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]{4}|\\U[0-9a-fA-F]{8}|.)'""", + r"""|\\u\{[0-9a-fA-F]{1,6}\}|.)'""", String.Char), (r"""b'(\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\0""" - r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|.)'""", + r"""|\\u\{[0-9a-fA-F]{1,6}\}|.)'""", String.Char), # Binary Literal (r'0b[01_]+', Number.Bin, 'number_lit'), @@ -131,7 +102,7 @@ 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'), @@ -166,14 +137,14 @@ class RustLexer(RegexLexer): (r'[*/]', Comment.Multiline), ], 'number_lit': [ - (r'[ui](8|16|32|64)?', Keyword, '#pop'), + (r'[ui](8|16|32|64|size)', Keyword, '#pop'), (r'f(32|64)', Keyword, '#pop'), default('#pop'), ], 'string': [ (r'"', String, '#pop'), (r"""\\['"\\nrt]|\\x[0-7][0-9a-fA-F]|\\0""" - r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}""", String.Escape), + r"""|\\u\{[0-9a-fA-F]{1,6}\}""", String.Escape), (r'[^\\"]+', String), (r'\\', String), ], |