| 1 |
filetype: rust |
| 2 |
|
| 3 |
detect: |
| 4 |
filename: "\\.rs$" |
| 5 |
|
| 6 |
rules: |
| 7 |
# function definition |
| 8 |
- identifier: "fn [a-z0-9_]+" |
| 9 |
# Reserved words |
| 10 |
- statement: "\\b(abstract|alignof|as|async|await|become|box|break|const|continue|crate|do|dyn|else|enum|extern|false|final|fn|for|gen|if|impl|in|let|loop|macro|match|mod|move|mut|offsetof|override|priv|pub|pure|ref|return|sizeof|static|self|struct|super|true|trait|type|typeof|try|union|unsafe|unsized|use|virtual|where|while|yield)\\b" |
| 11 |
# macros |
| 12 |
- special: "[a-z_]+!" |
| 13 |
# Constants |
| 14 |
- constant: "\\b[A-Z][A-Z_0-9]+\\b" |
| 15 |
# Numbers |
| 16 |
- constant.number: "\\b[0-9]+\\b" |
| 17 |
# Booleans |
| 18 |
- constant: "\\b(true|false)\\b" |
| 19 |
# Traits/Enums/Structs/Types/etc. |
| 20 |
- type: "\\b[A-Z]+[a-zA-Z_0-9]*[a-z]+[a-zA-Z_0-9]*\\b" |
| 21 |
# Builtin types that start with lowercase. |
| 22 |
- type: "\\b(bool|str|char|((i|u)(8|16|32|64|128|size))|f(16|32|64|128))\\b" |
| 23 |
|
| 24 |
- constant.string: |
| 25 |
start: "[bc]?\"" |
| 26 |
end: "\"" |
| 27 |
skip: '\\.' |
| 28 |
rules: |
| 29 |
- constant.specialChar: '\\.' |
| 30 |
|
| 31 |
- constant.string: |
| 32 |
start: "[bc]?r#\"" |
| 33 |
end: "\"#" |
| 34 |
rules: [] |
| 35 |
|
| 36 |
- constant.string: |
| 37 |
start: "[bc]?r##\"" |
| 38 |
end: "\"##" |
| 39 |
rules: [] |
| 40 |
|
| 41 |
- constant.string: |
| 42 |
start: "[bc]?r###\"" |
| 43 |
end: "\"###" |
| 44 |
rules: [] |
| 45 |
|
| 46 |
- constant.string: |
| 47 |
start: "[bc]?r####+\"" |
| 48 |
end: "\"####+" |
| 49 |
rules: [] |
| 50 |
|
| 51 |
# Character literals |
| 52 |
# NOTE: This is an ugly hack to work around the fact that rust uses |
| 53 |
# single quotes both for character literals and lifetimes. |
| 54 |
# Match all character literals. |
| 55 |
- constant.string: "'(\\\\.|.)'" |
| 56 |
# Match the '"' literal which would otherwise match |
| 57 |
# as a double quoted string and destroy the highlighting. |
| 58 |
- constant.string: |
| 59 |
start: "'\"" |
| 60 |
end: "'" |
| 61 |
rules: [] |
| 62 |
|
| 63 |
- comment: |
| 64 |
start: "//" |
| 65 |
end: "$" |
| 66 |
rules: |
| 67 |
- todo: "(TODO|XXX|FIXME):?" |
| 68 |
|
| 69 |
- comment: |
| 70 |
start: "/\\*" |
| 71 |
end: "\\*/" |
| 72 |
rules: |
| 73 |
- todo: "(TODO|XXX|FIXME):?" |
| 74 |
|
| 75 |
- special: |
| 76 |
start: "#!\\[" |
| 77 |
end: "\\]" |
| 78 |
rules: [] |