eric6/ThirdParty/Pygments/pygments/lexers/rust.py

changeset 7983
54c5cfbb1e29
parent 7701
25f42e208e08
equal deleted inserted replaced
7982:48d210e41c65 7983:54c5cfbb1e29
3 pygments.lexers.rust 3 pygments.lexers.rust
4 ~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for the Rust language. 6 Lexers for the Rust language.
7 7
8 :copyright: Copyright 2006-2020 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 from pygments.lexer import RegexLexer, include, bygroups, words, default 12 from pygments.lexer import RegexLexer, include, bygroups, words, default
13 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ 13 from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
16 __all__ = ['RustLexer'] 16 __all__ = ['RustLexer']
17 17
18 18
19 class RustLexer(RegexLexer): 19 class RustLexer(RegexLexer):
20 """ 20 """
21 Lexer for the Rust programming language (version 1.40). 21 Lexer for the Rust programming language (version 1.47).
22 22
23 .. versionadded:: 1.6 23 .. versionadded:: 1.6
24 """ 24 """
25 name = 'Rust' 25 name = 'Rust'
26 filenames = ['*.rs', '*.rs.in'] 26 filenames = ['*.rs', '*.rs.in']
30 keyword_types = (words(( 30 keyword_types = (words((
31 'u8', 'u16', 'u32', 'u64', 'u128', 'i8', 'i16', 'i32', 'i64', 'i128', 31 'u8', 'u16', 'u32', 'u64', 'u128', 'i8', 'i16', 'i32', 'i64', 'i128',
32 'usize', 'isize', 'f32', 'f64', 'char', 'str', 'bool', 32 'usize', 'isize', 'f32', 'f64', 'char', 'str', 'bool',
33 ), suffix=r'\b'), Keyword.Type) 33 ), suffix=r'\b'), Keyword.Type)
34 34
35 builtin_types = (words(( 35 builtin_funcs_types = (words((
36 'Send', 'Sized', 'Sync', 'Unpin', 36 'Copy', 'Send', 'Sized', 'Sync', 'Unpin',
37 'Drop', 'Fn', 'FnMut', 'FnOnce', 37 'Drop', 'Fn', 'FnMut', 'FnOnce', 'drop',
38 'AsRef', 'AsMut', 'Into', 'From', 38 'Box', 'ToOwned', 'Clone',
39 'PartialEq', 'PartialOrd', 'Eq', 'Ord',
40 'AsRef', 'AsMut', 'Into', 'From', 'Default',
39 'Iterator', 'Extend', 'IntoIterator', 'DoubleEndedIterator', 41 'Iterator', 'Extend', 'IntoIterator', 'DoubleEndedIterator',
40 'ExactSizeIterator', 'Option', 'Result', 42 'ExactSizeIterator',
41 'Box', 'ToOwned', 'String', 'ToString', 'Vec', 43 'Option', 'Some', 'None',
42 'Clone', 'Copy', 'Default', 'Eq', 'Hash', 'Ord', 'PartialEq', 44 'Result', 'Ok', 'Err',
43 'PartialOrd', 'Ord', 45 'String', 'ToString', 'Vec',
44 ), suffix=r'\b'), Name.Builtin) 46 ), suffix=r'\b'), Name.Builtin)
45 47
46 builtin_funcs_macros = (words(( 48 builtin_macros = (words((
47 'drop', 'Some', 'None', 'Ok', 'Err', 49 'asm', 'assert', 'assert_eq', 'assert_ne', 'cfg', 'column',
48 'asm!', 'assert!', 'assert_eq!', 'assert_ne!', 'cfg!', 'column!', 50 'compile_error', 'concat', 'concat_idents', 'dbg', 'debug_assert',
49 'compile_error!', 'concat!', 'concat_idents!', 'dbg!', 'debug_assert!', 51 'debug_assert_eq', 'debug_assert_ne', 'env', 'eprint', 'eprintln',
50 'debug_assert_eq!', 'debug_assert_ne!', 'env!', 'eprint!', 'eprintln!', 52 'file', 'format', 'format_args', 'format_args_nl', 'global_asm',
51 'file!', 'format_args!', 'format_args_nl!', 'global_asm!', 'include!', 53 'include', 'include_bytes', 'include_str',
52 'include_bytes!', 'include_str!', 'line!', 'log_syntax!', 54 'is_aarch64_feature_detected',
53 'module_path!', 'option_env!', 'panic!', 'print!', 'println!', 55 'is_arm_feature_detected',
54 'stringify!', 'thread_local!', 'todo!', 'trace_macros!', 56 'is_mips64_feature_detected',
55 'unimplemented!', 'unreachable!', 'vec!', 'write!', 'writeln!', 57 'is_mips_feature_detected',
56 ), suffix=r'\b'), Name.Builtin) 58 'is_powerpc64_feature_detected',
59 'is_powerpc_feature_detected',
60 'is_x86_feature_detected',
61 'line', 'llvm_asm', 'log_syntax', 'macro_rules', 'matches',
62 'module_path', 'option_env', 'panic', 'print', 'println', 'stringify',
63 'thread_local', 'todo', 'trace_macros', 'unimplemented', 'unreachable',
64 'vec', 'write', 'writeln',
65 ), suffix=r'!'), Name.Function.Magic)
57 66
58 tokens = { 67 tokens = {
59 'root': [ 68 'root': [
60 # rust allows a file to start with a shebang, but if the first line 69 # rust allows a file to start with a shebang, but if the first line
61 # starts with #![ then it's not a shebang but a crate attribute. 70 # starts with #![ then it's not a shebang but a crate attribute.
74 (r'/\*', Comment.Multiline, 'comment'), 83 (r'/\*', Comment.Multiline, 'comment'),
75 84
76 # Macro parameters 85 # Macro parameters
77 (r"""\$([a-zA-Z_]\w*|\(,?|\),?|,?)""", Comment.Preproc), 86 (r"""\$([a-zA-Z_]\w*|\(,?|\),?|,?)""", Comment.Preproc),
78 # Keywords 87 # Keywords
79 (words(( 88 (words(('as', 'async', 'await', 'box', 'const', 'crate', 'dyn',
80 'as', 'async', 'await', 'box', 'const', 'crate', 'dyn', 'else', 89 'else', 'extern', 'for', 'if', 'impl', 'in', 'loop',
81 'extern', 'for', 'if', 'impl', 'in', 'loop', 'match', 'move', 90 'match', 'move', 'mut', 'pub', 'ref', 'return', 'static',
82 'mut', 'pub', 'ref', 'return', 'static', 'super', 'trait', 91 'super', 'trait', 'unsafe', 'use', 'where', 'while'),
83 'try', 'unsafe', 'use', 'where', 'while', 'macro_rules!', 92 suffix=r'\b'), Keyword),
84 ), suffix=r'\b'), Keyword), 93 (words(('abstract', 'become', 'do', 'final', 'macro', 'override',
85 (words(('abstract', 'alignof', 'become', 'do', 'final', 'macro', 94 'priv', 'typeof', 'try', 'unsized', 'virtual', 'yield'),
86 'offsetof', 'override', 'priv', 'proc', 'pure', 'sizeof', 95 suffix=r'\b'), Keyword.Reserved),
87 'typeof', 'unsized', 'virtual', 'yield'), suffix=r'\b'),
88 Keyword.Reserved),
89 (r'(true|false)\b', Keyword.Constant), 96 (r'(true|false)\b', Keyword.Constant),
97 (r'self\b', Name.Builtin.Pseudo),
90 (r'mod\b', Keyword, 'modname'), 98 (r'mod\b', Keyword, 'modname'),
91 (r'let\b', Keyword.Declaration), 99 (r'let\b', Keyword.Declaration),
92 (r'fn\b', Keyword, 'funcname'), 100 (r'fn\b', Keyword, 'funcname'),
93 (r'(struct|enum|type|union)\b', Keyword, 'typename'), 101 (r'(struct|enum|type|union)\b', Keyword, 'typename'),
94 (r'(default)(\s+)(type|fn)\b', bygroups(Keyword, Text, Keyword)), 102 (r'(default)(\s+)(type|fn)\b', bygroups(Keyword, Text, Keyword)),
95 keyword_types, 103 keyword_types,
96 (r'[sS]elf\b', Name.Builtin.Pseudo), 104 (r'[sS]elf\b', Name.Builtin.Pseudo),
97 # Prelude (taken from Rust's src/libstd/prelude.rs) 105 # Prelude (taken from Rust's src/libstd/prelude.rs)
98 builtin_types, 106 builtin_funcs_types,
99 builtin_funcs_macros, 107 builtin_macros,
100 # Path seperators, so types don't catch them. 108 # Path seperators, so types don't catch them.
101 (r'::\b', Text), 109 (r'::\b', Text),
102 # Types in positions. 110 # Types in positions.
103 (r'(?::|->)', Text, 'typename'), 111 (r'(?::|->)', Text, 'typename'),
104 # Labels 112 # Labels
170 ], 178 ],
171 'typename': [ 179 'typename': [
172 (r'\s+', Text), 180 (r'\s+', Text),
173 (r'&', Keyword.Pseudo), 181 (r'&', Keyword.Pseudo),
174 (r"'", Operator, 'lifetime'), 182 (r"'", Operator, 'lifetime'),
175 builtin_types, 183 builtin_funcs_types,
176 keyword_types, 184 keyword_types,
177 (r'[a-zA-Z_]\w*', Name.Class, '#pop'), 185 (r'[a-zA-Z_]\w*', Name.Class, '#pop'),
178 default('#pop'), 186 default('#pop'),
179 ], 187 ],
180 'lifetime': [ 188 'lifetime': [

eric ide

mercurial