| 1 | { |
| 2 | "name": "Rust", |
| 3 | "scopeName": "source.rust", |
| 4 | "fileTypes": ["rs"], |
| 5 | "repository": { |
| 6 | "block_doc_comment": { |
| 7 | "comment": "Block documentation comment", |
| 8 | "name": "comment.block.documentation.rust", |
| 9 | "begin": "/\\*[\\*!](?![\\*/])", |
| 10 | "end": "\\*/", |
| 11 | "patterns": [ |
| 12 | { |
| 13 | "include": "#block_doc_comment" |
| 14 | }, |
| 15 | { |
| 16 | "include": "#block_comment" |
| 17 | } |
| 18 | ] |
| 19 | }, |
| 20 | "block_comment": { |
| 21 | "comment": "Block comment", |
| 22 | "name": "comment.block.rust", |
| 23 | "begin": "/\\*", |
| 24 | "end": "\\*/", |
| 25 | "patterns": [ |
| 26 | { |
| 27 | "include": "#block_doc_comment" |
| 28 | }, |
| 29 | { |
| 30 | "include": "#block_comment" |
| 31 | } |
| 32 | ] |
| 33 | }, |
| 34 | "line_doc_comment": { |
| 35 | "comment": "Single-line documentation comment", |
| 36 | "name": "comment.line.documentation.rust", |
| 37 | "begin": "//[!/](?=[^/])", |
| 38 | "end": "$" |
| 39 | }, |
| 40 | "line_comment": { |
| 41 | "comment": "Single-line comment", |
| 42 | "name": "comment.line.double-slash.rust", |
| 43 | "begin": "//", |
| 44 | "end": "$" |
| 45 | }, |
| 46 | "escaped_character": { |
| 47 | "name": "constant.character.escape.rust", |
| 48 | "match": "\\\\(x\\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)" |
| 49 | }, |
| 50 | "string_literal": { |
| 51 | "comment": "Double-quote string literal", |
| 52 | "name": "string.quoted.double.rust", |
| 53 | "begin": "b?\"", |
| 54 | "end": "\"", |
| 55 | "patterns": [ |
| 56 | { |
| 57 | "include": "#escaped_character" |
| 58 | } |
| 59 | ] |
| 60 | }, |
| 61 | "raw_string_literal": { |
| 62 | "comment": "Raw double-quote string literal", |
| 63 | "name": "string.quoted.double.raw.rust", |
| 64 | "begin": "b?r(#*)\"", |
| 65 | "end": "\"\\1" |
| 66 | }, |
| 67 | "sigils": { |
| 68 | "comment": "Sigil", |
| 69 | "name": "keyword.operator.sigil.rust", |
| 70 | "match": "[&*](?=[a-zA-Z0-9_\\(\\[\\|\\\"]+)" |
| 71 | }, |
| 72 | "self": { |
| 73 | "comment": "Self variable", |
| 74 | "name": "variable.language.rust", |
| 75 | "match": "\\bself\\b" |
| 76 | }, |
| 77 | "mut": { |
| 78 | "comment": "Mutable storage modifier", |
| 79 | "name": "storage.modifier.mut.rust", |
| 80 | "match": "\\bmut\\b" |
| 81 | }, |
| 82 | "box": { |
| 83 | "comment": "Box storage modifier", |
| 84 | "name": "storage.modifier.box.rust", |
| 85 | "match": "\\bbox\\b" |
| 86 | }, |
| 87 | "const": { |
| 88 | "comment": "Const storage modifier", |
| 89 | "name": "storage.modifier.const.rust", |
| 90 | "match": "\\bconst\\b" |
| 91 | }, |
| 92 | "pub": { |
| 93 | "comment": "Visibility modifier", |
| 94 | "name": "storage.modifier.visibility.rust", |
| 95 | "match": "\\bpub\\b" |
| 96 | }, |
| 97 | "lifetime": { |
| 98 | "comment": "Named lifetime", |
| 99 | "name": "storage.modifier.lifetime.rust", |
| 100 | "match": "'([a-zA-Z_][a-zA-Z0-9_]*)\\b", |
| 101 | "captures": { |
| 102 | "1": { |
| 103 | "name": "entity.name.lifetime.rust" |
| 104 | } |
| 105 | } |
| 106 | }, |
| 107 | "ref_lifetime": { |
| 108 | "comment": "Reference with named lifetime", |
| 109 | "match": "&('([a-zA-Z_][a-zA-Z0-9_]*))\\b", |
| 110 | "captures": { |
| 111 | "1": { |
| 112 | "name": "storage.modifier.lifetime.rust" |
| 113 | }, |
| 114 | "2": { |
| 115 | "name": "entity.name.lifetime.rust" |
| 116 | } |
| 117 | } |
| 118 | }, |
| 119 | "core_types": { |
| 120 | "comment": "Built-in/core type", |
| 121 | "name": "storage.type.core.rust", |
| 122 | "match": "\\b(bool|char|usize|isize|u8|u16|u32|u64|i8|i16|i32|i64|f32|f64|str|Self|Option|Result)\\b" |
| 123 | }, |
| 124 | "core_vars": { |
| 125 | "comment": "Core type variant", |
| 126 | "name": "support.constant.core.rust", |
| 127 | "match": "\\b(Some|None|Ok|Err)\\b" |
| 128 | }, |
| 129 | "core_marker": { |
| 130 | "comment": "Core trait (marker)", |
| 131 | "name": "support.type.marker.rust", |
| 132 | "match": "\\b(Copy|Send|Sized|Sync)\\b" |
| 133 | }, |
| 134 | "core_traits": { |
| 135 | "comment": "Core trait", |
| 136 | "name": "support.type.core.rust", |
| 137 | "match": "\\b(Drop|Fn|FnMut|FnOnce|Clone|PartialEq|PartialOrd|Eq|Ord|AsRef|AsMut|Into|From|Default|Iterator|Extend|IntoIterator|DoubleEndedIterator|ExactSizeIterator)\\b" |
| 138 | }, |
| 139 | "where": { |
| 140 | "comment": "Where clause", |
| 141 | "name": "keyword.other.rust", |
| 142 | "match": "\\bwhere\\b" |
| 143 | }, |
| 144 | "std_types": { |
| 145 | "comment": "Standard library type", |
| 146 | "name": "storage.class.std.rust", |
| 147 | "match": "\\b(Box|String|Vec|Path|PathBuf)\\b" |
| 148 | }, |
| 149 | "std_traits": { |
| 150 | "comment": "Standard library trait", |
| 151 | "name": "support.type.std.rust", |
| 152 | "match": "\\b(ToOwned|ToString)\\b" |
| 153 | }, |
| 154 | "type_params": { |
| 155 | "comment": "Type parameters", |
| 156 | "name": "meta.type_params.rust", |
| 157 | "begin": "<(?![=<])", |
| 158 | "end": ">", |
| 159 | "patterns": [ |
| 160 | { |
| 161 | "include": "#block_comment" |
| 162 | }, |
| 163 | { |
| 164 | "include": "#line_comment" |
| 165 | }, |
| 166 | { |
| 167 | "include": "#sigils" |
| 168 | }, |
| 169 | { |
| 170 | "include": "#mut" |
| 171 | }, |
| 172 | { |
| 173 | "include": "#lifetime" |
| 174 | }, |
| 175 | { |
| 176 | "include": "#core_types" |
| 177 | }, |
| 178 | { |
| 179 | "include": "#core_marker" |
| 180 | }, |
| 181 | { |
| 182 | "include": "#core_traits" |
| 183 | }, |
| 184 | { |
| 185 | "include": "#std_types" |
| 186 | }, |
| 187 | { |
| 188 | "include": "#std_traits" |
| 189 | }, |
| 190 | { |
| 191 | "include": "#type_params" |
| 192 | } |
| 193 | ] |
| 194 | } |
| 195 | }, |
| 196 | "patterns": [ |
| 197 | { |
| 198 | "include": "#block_doc_comment" |
| 199 | }, |
| 200 | { |
| 201 | "include": "#block_comment" |
| 202 | }, |
| 203 | { |
| 204 | "include": "#line_doc_comment" |
| 205 | }, |
| 206 | { |
| 207 | "include": "#line_comment" |
| 208 | }, |
| 209 | { |
| 210 | "comment": "Attribute", |
| 211 | "name": "meta.attribute.rust", |
| 212 | "begin": "#\\!?\\[", |
| 213 | "end": "\\]", |
| 214 | "patterns": [ |
| 215 | { |
| 216 | "include": "#string_literal" |
| 217 | } |
| 218 | ] |
| 219 | }, |
| 220 | { |
| 221 | "comment": "Single-quote string literal (character)", |
| 222 | "name": "string.quoted.single.rust", |
| 223 | "match": "b?'([^'\\\\]|\\\\(x\\h{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.))'" |
| 224 | }, |
| 225 | { |
| 226 | "include": "#string_literal" |
| 227 | }, |
| 228 | { |
| 229 | "include": "#raw_string_literal" |
| 230 | }, |
| 231 | { |
| 232 | "comment": "Floating point literal (fraction)", |
| 233 | "name": "constant.numeric.float.rust", |
| 234 | "match": "\\b[0-9][0-9_]*\\.[0-9][0-9_]*([eE][+-]?[0-9_]+)?(f32|f64)?\\b" |
| 235 | }, |
| 236 | { |
| 237 | "comment": "Floating point literal (exponent)", |
| 238 | "name": "constant.numeric.float.rust", |
| 239 | "match": "\\b[0-9][0-9_]*(\\.[0-9][0-9_]*)?[eE][+-]?[0-9_]+(f32|f64)?\\b" |
| 240 | }, |
| 241 | { |
| 242 | "comment": "Floating point literal (typed)", |
| 243 | "name": "constant.numeric.float.rust", |
| 244 | "match": "\\b[0-9][0-9_]*(\\.[0-9][0-9_]*)?([eE][+-]?[0-9_]+)?(f32|f64)\\b" |
| 245 | }, |
| 246 | { |
| 247 | "comment": "Integer literal (decimal)", |
| 248 | "name": "constant.numeric.integer.decimal.rust", |
| 249 | "match": "\\b[0-9][0-9_]*([ui](8|16|32|64|s|size))?\\b" |
| 250 | }, |
| 251 | { |
| 252 | "comment": "Integer literal (hexadecimal)", |
| 253 | "name": "constant.numeric.integer.hexadecimal.rust", |
| 254 | "match": "\\b0x[a-fA-F0-9_]+([ui](8|16|32|64|s|size))?\\b" |
| 255 | }, |
| 256 | { |
| 257 | "comment": "Integer literal (octal)", |
| 258 | "name": "constant.numeric.integer.octal.rust", |
| 259 | "match": "\\b0o[0-7_]+([ui](8|16|32|64|s|size))?\\b" |
| 260 | }, |
| 261 | { |
| 262 | "comment": "Integer literal (binary)", |
| 263 | "name": "constant.numeric.integer.binary.rust", |
| 264 | "match": "\\b0b[01_]+([ui](8|16|32|64|s|size))?\\b" |
| 265 | }, |
| 266 | { |
| 267 | "comment": "Static storage modifier", |
| 268 | "name": "storage.modifier.static.rust", |
| 269 | "match": "\\bstatic\\b" |
| 270 | }, |
| 271 | { |
| 272 | "comment": "Boolean constant", |
| 273 | "name": "constant.language.boolean.rust", |
| 274 | "match": "\\b(true|false)\\b" |
| 275 | }, |
| 276 | { |
| 277 | "comment": "Control keyword", |
| 278 | "name": "keyword.control.rust", |
| 279 | "match": "\\b(break|continue|else|if|in|for|loop|match|return|while)\\b" |
| 280 | }, |
| 281 | { |
| 282 | "comment": "Keyword", |
| 283 | "name": "keyword.other.rust", |
| 284 | "match": "\\b(crate|extern|mod|let|proc|ref|use|super|as|where|move)\\b" |
| 285 | }, |
| 286 | { |
| 287 | "comment": "Unsafe code keyword", |
| 288 | "name": "keyword.other.unsafe.rust", |
| 289 | "match": "\\bunsafe\\b" |
| 290 | }, |
| 291 | { |
| 292 | "include": "#sigils" |
| 293 | }, |
| 294 | { |
| 295 | "include": "#self" |
| 296 | }, |
| 297 | { |
| 298 | "include": "#mut" |
| 299 | }, |
| 300 | { |
| 301 | "include": "#box" |
| 302 | }, |
| 303 | { |
| 304 | "include": "#lifetime" |
| 305 | }, |
| 306 | { |
| 307 | "include": "#ref_lifetime" |
| 308 | }, |
| 309 | { |
| 310 | "include": "#const" |
| 311 | }, |
| 312 | { |
| 313 | "include": "#pub" |
| 314 | }, |
| 315 | { |
| 316 | "comment": "Miscellaneous operator", |
| 317 | "name": "keyword.operator.misc.rust", |
| 318 | "match": "(=>|::|\\bas\\b)" |
| 319 | }, |
| 320 | { |
| 321 | "comment": "Comparison operator", |
| 322 | "name": "keyword.operator.comparison.rust", |
| 323 | "match": "(&&|\\|\\||==|!=)" |
| 324 | }, |
| 325 | { |
| 326 | "comment": "Assignment operator", |
| 327 | "name": "keyword.operator.assignment.rust", |
| 328 | "match": "(\\+=|-=|/=|\\*=|%=|\\^=|&=|\\|=|<<=|>>=|=)" |
| 329 | }, |
| 330 | { |
| 331 | "comment": "Arithmetic operator", |
| 332 | "name": "keyword.operator.arithmetic.rust", |
| 333 | "match": "(!|\\+|-|/|\\*|%|\\^|&|\\||<<|>>)" |
| 334 | }, |
| 335 | { |
| 336 | "comment": "Comparison operator (second group because of regex precedence)", |
| 337 | "name": "keyword.operator.comparison.rust", |
| 338 | "match": "(<=|>=|<|>)" |
| 339 | }, |
| 340 | { |
| 341 | "include": "#core_types" |
| 342 | }, |
| 343 | { |
| 344 | "include": "#core_vars" |
| 345 | }, |
| 346 | { |
| 347 | "include": "#core_marker" |
| 348 | }, |
| 349 | { |
| 350 | "include": "#core_traits" |
| 351 | }, |
| 352 | { |
| 353 | "include": "#std_types" |
| 354 | }, |
| 355 | { |
| 356 | "include": "#std_traits" |
| 357 | }, |
| 358 | { |
| 359 | "comment": "Built-in macro", |
| 360 | "name": "support.function.builtin.rust", |
| 361 | "match": "\\b(macro_rules|format_args|env|option_env|concat_idents|concat|log_syntax|line|column|file|stringify|include|include_str|include_bytes|module_path|asm|cfg|trace_macros)!" |
| 362 | }, |
| 363 | { |
| 364 | "comment": "Core macro", |
| 365 | "name": "support.function.core.rust", |
| 366 | "match": "\\b(panic|assert|assert_eq|debug_assert|debug_assert_eq|try|write|writeln|unreachable|unimplemented)!" |
| 367 | }, |
| 368 | { |
| 369 | "comment": "Standard library macro", |
| 370 | "name": "support.function.std.rust", |
| 371 | "match": "\\b(format|print|println|select|vec)!" |
| 372 | }, |
| 373 | { |
| 374 | "comment": "Logging macro", |
| 375 | "name": "support.function.log.rust", |
| 376 | "match": "\\b(log|error|warn|info|debug|trace|log_enabled)!" |
| 377 | }, |
| 378 | { |
| 379 | "comment": "Invokation of a macro", |
| 380 | "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*\\!)\\s*[({\\[]", |
| 381 | "captures": { |
| 382 | "1": { |
| 383 | "name": "entity.name.function.macro.rust" |
| 384 | } |
| 385 | } |
| 386 | }, |
| 387 | { |
| 388 | "comment": "Function call", |
| 389 | "match": "\\b([a-zA-Z_][a-zA-Z0-9_]*)\\s*\\(", |
| 390 | "captures": { |
| 391 | "1": { |
| 392 | "name": "entity.name.function.rust" |
| 393 | } |
| 394 | } |
| 395 | }, |
| 396 | { |
| 397 | "comment": "Function definition", |
| 398 | "begin": "\\b(fn)\\s+([a-zA-Z_][a-zA-Z0-9_]*)", |
| 399 | "end": "[\\{;]", |
| 400 | "beginCaptures": { |
| 401 | "1": { |
| 402 | "name": "keyword.other.fn.rust" |
| 403 | }, |
| 404 | "2": { |
| 405 | "name": "entity.name.function.rust" |
| 406 | } |
| 407 | }, |
| 408 | "patterns": [ |
| 409 | { |
| 410 | "include": "#block_comment" |
| 411 | }, |
| 412 | { |
| 413 | "include": "#line_comment" |
| 414 | }, |
| 415 | { |
| 416 | "include": "#sigils" |
| 417 | }, |
| 418 | { |
| 419 | "include": "#self" |
| 420 | }, |
| 421 | { |
| 422 | "include": "#mut" |
| 423 | }, |
| 424 | { |
| 425 | "include": "#ref_lifetime" |
| 426 | }, |
| 427 | { |
| 428 | "include": "#core_types" |
| 429 | }, |
| 430 | { |
| 431 | "include": "#core_marker" |
| 432 | }, |
| 433 | { |
| 434 | "include": "#core_traits" |
| 435 | }, |
| 436 | { |
| 437 | "include": "#std_types" |
| 438 | }, |
| 439 | { |
| 440 | "include": "#std_traits" |
| 441 | }, |
| 442 | { |
| 443 | "include": "#type_params" |
| 444 | }, |
| 445 | { |
| 446 | "include": "#const" |
| 447 | }, |
| 448 | { |
| 449 | "include": "#where" |
| 450 | } |
| 451 | ] |
| 452 | }, |
| 453 | { |
| 454 | "comment": "Type declaration", |
| 455 | "begin": "\\b(enum|struct|trait)\\s+([a-zA-Z_][a-zA-Z0-9_]*)", |
| 456 | "end": "[\\{\\(;]", |
| 457 | "beginCaptures": { |
| 458 | "1": { |
| 459 | "name": "storage.type.rust" |
| 460 | }, |
| 461 | "2": { |
| 462 | "name": "entity.name.type.rust" |
| 463 | } |
| 464 | }, |
| 465 | "patterns": [ |
| 466 | { |
| 467 | "include": "#block_comment" |
| 468 | }, |
| 469 | { |
| 470 | "include": "#line_comment" |
| 471 | }, |
| 472 | { |
| 473 | "include": "#core_traits" |
| 474 | }, |
| 475 | { |
| 476 | "include": "#std_traits" |
| 477 | }, |
| 478 | { |
| 479 | "include": "#type_params" |
| 480 | }, |
| 481 | { |
| 482 | "include": "#core_types" |
| 483 | }, |
| 484 | { |
| 485 | "include": "#pub" |
| 486 | }, |
| 487 | { |
| 488 | "include": "#where" |
| 489 | } |
| 490 | ] |
| 491 | }, |
| 492 | { |
| 493 | "comment": "Type alias", |
| 494 | "begin": "\\b(type)\\s+([a-zA-Z_][a-zA-Z0-9_]*)", |
| 495 | "end": ";", |
| 496 | "beginCaptures": { |
| 497 | "1": { |
| 498 | "name": "storage.type.rust" |
| 499 | }, |
| 500 | "2": { |
| 501 | "name": "entity.name.type.rust" |
| 502 | } |
| 503 | }, |
| 504 | "patterns": [ |
| 505 | { |
| 506 | "include": "#block_comment" |
| 507 | }, |
| 508 | { |
| 509 | "include": "#line_comment" |
| 510 | }, |
| 511 | { |
| 512 | "include": "#sigils" |
| 513 | }, |
| 514 | { |
| 515 | "include": "#mut" |
| 516 | }, |
| 517 | { |
| 518 | "include": "#ref_lifetime" |
| 519 | }, |
| 520 | { |
| 521 | "include": "#core_types" |
| 522 | }, |
| 523 | { |
| 524 | "include": "#core_marker" |
| 525 | }, |
| 526 | { |
| 527 | "include": "#core_traits" |
| 528 | }, |
| 529 | { |
| 530 | "include": "#std_types" |
| 531 | }, |
| 532 | { |
| 533 | "include": "#std_traits" |
| 534 | }, |
| 535 | { |
| 536 | "include": "#type_params" |
| 537 | } |
| 538 | ] |
| 539 | }, |
| 540 | { |
| 541 | "comment": "Implementation", |
| 542 | "begin": "\\b(impl)\\b", |
| 543 | "end": "\\{", |
| 544 | "beginCaptures": { |
| 545 | "1": { |
| 546 | "name": "storage.type.rust" |
| 547 | } |
| 548 | }, |
| 549 | "patterns": [ |
| 550 | { |
| 551 | "include": "#block_comment" |
| 552 | }, |
| 553 | { |
| 554 | "include": "#line_comment" |
| 555 | }, |
| 556 | { |
| 557 | "include": "#sigils" |
| 558 | }, |
| 559 | { |
| 560 | "include": "#mut" |
| 561 | }, |
| 562 | { |
| 563 | "include": "#ref_lifetime" |
| 564 | }, |
| 565 | { |
| 566 | "include": "#core_types" |
| 567 | }, |
| 568 | { |
| 569 | "include": "#core_marker" |
| 570 | }, |
| 571 | { |
| 572 | "include": "#core_traits" |
| 573 | }, |
| 574 | { |
| 575 | "include": "#std_types" |
| 576 | }, |
| 577 | { |
| 578 | "include": "#std_traits" |
| 579 | }, |
| 580 | { |
| 581 | "include": "#type_params" |
| 582 | }, |
| 583 | { |
| 584 | "name": "storage.type.rust", |
| 585 | "match": "\\bfor\\b" |
| 586 | }, |
| 587 | { |
| 588 | "include": "#where" |
| 589 | } |
| 590 | ] |
| 591 | } |
| 592 | ] |
| 593 | } |