|
31 | 31 | alias: 'string'
|
32 | 32 | },
|
33 | 33 | 'attribute': {
|
34 |
| - pattern: /#!?\[[^[\]]*\]/, |
| 34 | + pattern: /#!?\[(?:[^\[\]"]|"(?:\\[\s\S]|[^\\"])*")*\]/, |
35 | 35 | greedy: true,
|
36 | 36 | alias: 'attr-name',
|
37 | 37 | inside: {
|
|
66 | 66 | 'variable': /\$\w+/,
|
67 | 67 |
|
68 | 68 | 'function-definition': {
|
69 |
| - pattern: /(\bfn\s*)\w+/, |
| 69 | + pattern: /(\bfn\s+)\w+/, |
70 | 70 | lookbehind: true,
|
71 | 71 | alias: 'function'
|
72 | 72 | },
|
| 73 | + 'type-definition': { |
| 74 | + pattern: /(\b(?:enum|struct|union)\s+)\w+/, |
| 75 | + lookbehind: true, |
| 76 | + alias: 'class-name' |
| 77 | + }, |
| 78 | + 'module-declaration': [ |
| 79 | + { |
| 80 | + pattern: /(\b(?:crate|mod)\s+)[a-z][a-z_\d]*/, |
| 81 | + lookbehind: true, |
| 82 | + alias: 'namespace' |
| 83 | + }, |
| 84 | + { |
| 85 | + pattern: /(\b(?:crate|self|super)\s*)::\s*[a-z][a-z_\d]*\b(?:\s*::(?:\s*[a-z][a-z_\d]*\s*::)*)?/, |
| 86 | + lookbehind: true, |
| 87 | + alias: 'namespace', |
| 88 | + inside: { |
| 89 | + 'punctuation': /::/ |
| 90 | + } |
| 91 | + } |
| 92 | + ], |
73 | 93 | 'keyword': [
|
74 | 94 | // https://github.com/rust-lang/reference/blob/master/src/keywords.md
|
75 | 95 | /\b(?:abstract|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|final|fn|for|if|impl|in|let|loop|macro|match|mod|move|mut|override|priv|pub|ref|return|self|Self|static|struct|super|trait|try|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\b/,
|
76 |
| - // primitives |
| 96 | + // primitives and str |
77 | 97 | // https://doc.rust-lang.org/stable/rust-by-example/primitives.html
|
78 |
| - /\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char)\b/ |
| 98 | + /\b(?:[ui](?:8|16|32|64|128|size)|f(?:32|64)|bool|char|str)\b/ |
79 | 99 | ],
|
80 | 100 |
|
81 | 101 | // functions can technically start with an upper-case letter, but this will introduce a lot of false positives
|
82 | 102 | // and Rust's naming conventions recommend snake_case anyway.
|
83 | 103 | // https://doc.rust-lang.org/1.0.0/style/style/naming/README.html
|
84 |
| - 'function': /\b[a-z_]\w*(?=\s*(?:::\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*)?\()/, |
| 104 | + 'function': /\b[a-z_]\w*(?=\s*(?:::\s*<|\())/, |
85 | 105 | 'macro': {
|
86 | 106 | pattern: /\w+!/,
|
87 | 107 | alias: 'property'
|
88 | 108 | },
|
| 109 | + 'constant': /\b[A-Z_][A-Z_\d]+\b/, |
| 110 | + 'class-name': /\b[A-Z]\w*\b/, |
| 111 | + |
| 112 | + 'namespace': { |
| 113 | + pattern: /(?:\b[a-z][a-z_\d]*\s*::\s*)*\b[a-z][a-z_\d]*\s*::(?!\s*<)/, |
| 114 | + inside: { |
| 115 | + 'punctuation': /::/ |
| 116 | + } |
| 117 | + }, |
89 | 118 |
|
90 | 119 | // Hex, oct, bin, dec numbers with visual separators and type suffix
|
91 | 120 | 'number': /\b(?:0x[\dA-Fa-f](?:_?[\dA-Fa-f])*|0o[0-7](?:_?[0-7])*|0b[01](?:_?[01])*|(?:\d(?:_?\d)*)?\.?\d(?:_?\d)*(?:[Ee][+-]?\d+)?)(?:_?(?:[iu](?:8|16|32|64|size)?|f32|f64))?\b/,
|
|
0 commit comments