diff options
author | Chris Morgan <me@chrismorgan.info> | 2014-12-03 12:57:06 +1100 |
---|---|---|
committer | Chris Morgan <me@chrismorgan.info> | 2014-12-03 12:57:06 +1100 |
commit | e7d23aec8848e48e2d5d5112a4bdba4c1c769a15 (patch) | |
tree | dd98d7cd47b4813ea05895f00b805f8750a1b133 /pygments/lexers/rust.py | |
parent | 5baa8b0de1081e303c9cf9659f9e08840739c1f4 (diff) | |
download | pygments-e7d23aec8848e48e2d5d5112a4bdba4c1c769a15.tar.gz |
Highlight strings more properly in Rust.
- Raw strings are now ``String`` rather than the unofficial ``String.Raw``
which isn?t styled by default;
- Byte strings weren?t being handled at all;
- ``\x80`` and above aren?t valid in non-byte strings;
- ``\0`` is a thing, ``\777`` for octal 7 is *not* a thing, nor has it ever
been, to the best of my knowledge. Not sure why that one was in there at all.
Diffstat (limited to 'pygments/lexers/rust.py')
-rw-r--r-- | pygments/lexers/rust.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/pygments/lexers/rust.py b/pygments/lexers/rust.py index 78ecc305..c2bea123 100644 --- a/pygments/lexers/rust.py +++ b/pygments/lexers/rust.py @@ -85,7 +85,10 @@ class RustLexer(RegexLexer): # Labels (r'(break|continue)(\s*)(\'[A-Za-z_]\w*)?', bygroups(Keyword, Text.Whitespace, Name.Label)), # Character Literal - (r"""'(\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" + (r"""'(\\['"\\nrt]|\\x[0-7][0-9a-fA-F]|\\0""" + r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|.)'""", + 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}|.)'""", String.Char), # Binary Literal @@ -99,8 +102,9 @@ class RustLexer(RegexLexer): 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'), (r'"', String, 'string'), - (r'r(#*)".*?"\1', String.Raw), + (r'b?r(#*)".*?"\1', String), # Lifetime (r"""'static""", Name.Builtin), @@ -136,11 +140,15 @@ class RustLexer(RegexLexer): ], 'string': [ (r'"', String, '#pop'), - (r"""\\['"\\nrt]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}""" + (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'[^\\"]+', String), (r'\\', String), ], + 'bytestring': [ + (r"""\\x[89a-fA-F][0-9a-fA-F]""", String.Escape), + include('string'), + ], 'macro{': [ (r'\{', Operator, '#push'), (r'\}', Operator, '#pop'), |