highlight: Support Radiance lexical regions
0d710a9ad26edcb69805d4d4135a579c962a468e
Recognize region parameters, bounds, and scoped bindings so Radiance source receives the appropriate syntax scopes. Add coverage for region bindings, arena sessions, and character literals. Assisted-by: Codex:gpt-6
1 parent
cbdbfe7a
crates/highlight/syntaxes/radiance.json
+63 -4
| 9 | 9 | "include": "#comments" |
|
| 10 | 10 | }, |
|
| 11 | 11 | { |
|
| 12 | 12 | "include": "#strings" |
|
| 13 | 13 | }, |
|
| 14 | + | { |
|
| 15 | + | "include": "#regions" |
|
| 16 | + | }, |
|
| 14 | 17 | { |
|
| 15 | 18 | "include": "#builtins" |
|
| 16 | 19 | }, |
|
| 20 | + | { |
|
| 21 | + | "include": "#bindings" |
|
| 22 | + | }, |
|
| 17 | 23 | { |
|
| 18 | 24 | "include": "#modules" |
|
| 19 | 25 | }, |
|
| 20 | 26 | { |
|
| 21 | 27 | "include": "#namespaces" |
| 35 | 41 | { |
|
| 36 | 42 | "include": "#punctuation" |
|
| 37 | 43 | } |
|
| 38 | 44 | ], |
|
| 39 | 45 | "repository": { |
|
| 46 | + | "bindings": { |
|
| 47 | + | "patterns": [ |
|
| 48 | + | { |
|
| 49 | + | "captures": { |
|
| 50 | + | "1": { |
|
| 51 | + | "name": "keyword.control.radiance" |
|
| 52 | + | }, |
|
| 53 | + | "2": { |
|
| 54 | + | "name": "variable.other.radiance" |
|
| 55 | + | }, |
|
| 56 | + | "3": { |
|
| 57 | + | "name": "keyword.operator.radiance" |
|
| 58 | + | } |
|
| 59 | + | }, |
|
| 60 | + | "match": "\\b(let)\\s+([A-Za-z_][A-Za-z0-9_]*)\\s*(:)(?=\\s*'[A-Za-z_])", |
|
| 61 | + | "name": "meta.binding.region.radiance" |
|
| 62 | + | }, |
|
| 63 | + | { |
|
| 64 | + | "captures": { |
|
| 65 | + | "1": { |
|
| 66 | + | "name": "keyword.control.radiance" |
|
| 67 | + | }, |
|
| 68 | + | "2": { |
|
| 69 | + | "name": "variable.other.radiance" |
|
| 70 | + | }, |
|
| 71 | + | "3": { |
|
| 72 | + | "name": "keyword.control.radiance" |
|
| 73 | + | } |
|
| 74 | + | }, |
|
| 75 | + | "match": "\\b(as)\\s+([A-Za-z_][A-Za-z0-9_]*)\\s+(in)\\b", |
|
| 76 | + | "name": "meta.binding.session.radiance" |
|
| 77 | + | } |
|
| 78 | + | ] |
|
| 79 | + | }, |
|
| 40 | 80 | "builtins": { |
|
| 41 | 81 | "patterns": [ |
|
| 42 | 82 | { |
|
| 43 | 83 | "match": "@[A-Za-z_][A-Za-z0-9_]*", |
|
| 44 | 84 | "name": "support.function.builtin.radiance" |
| 66 | 106 | ] |
|
| 67 | 107 | }, |
|
| 68 | 108 | "functions": { |
|
| 69 | 109 | "patterns": [ |
|
| 70 | 110 | { |
|
| 71 | - | "match": "\\b[A-Za-z_][A-Za-z0-9_]*\\b(?=\\s*\\??\\()", |
|
| 111 | + | "match": "\\b[A-Za-z_][A-Za-z0-9_]*\\b(?=\\s*(?:'[A-Za-z_][A-Za-z0-9_]*\\s*)*\\??\\()", |
|
| 72 | 112 | "name": "entity.name.function.radiance" |
|
| 73 | 113 | } |
|
| 74 | 114 | ] |
|
| 75 | 115 | }, |
|
| 76 | 116 | "keywords": { |
| 82 | 122 | { |
|
| 83 | 123 | "match": "\\b(?:false|nil|true|undefined)\\b", |
|
| 84 | 124 | "name": "constant.language.radiance" |
|
| 85 | 125 | }, |
|
| 86 | 126 | { |
|
| 87 | - | "match": "\\b(?:align|and|as|assert|break|case|catch|constant|continue|else|export|fn|for|if|in|instance|instantiate|let|log|loop|match|mod|mut|not|or|panic|record|return|set|static|super|throw|throws|trait|try|union|unsafe|use|while)\\b", |
|
| 127 | + | "match": "\\b(?:align|and|as|assert|break|case|catch|constant|continue|else|export|fn|for|if|in|instance|instantiate|let|log|loop|match|mod|mut|not|or|panic|record|return|set|static|super|throw|throws|trait|try|union|unsafe|use|where|while)\\b", |
|
| 88 | 128 | "name": "keyword.control.radiance" |
|
| 89 | 129 | }, |
|
| 90 | 130 | { |
|
| 91 | 131 | "match": "\\b_\\b", |
|
| 92 | 132 | "name": "constant.language.placeholder.radiance" |
| 113 | 153 | }, |
|
| 114 | 154 | "2": { |
|
| 115 | 155 | "name": "entity.name.namespace.radiance" |
|
| 116 | 156 | } |
|
| 117 | 157 | }, |
|
| 118 | - | "match": "\\b(use)\\s+([A-Za-z_][A-Za-z0-9_]*)\\b" |
|
| 158 | + | "match": "\\b(use)\\s+([A-Za-z_][A-Za-z0-9_]*)(?=\\s*(?:::|;))" |
|
| 119 | 159 | } |
|
| 120 | 160 | ] |
|
| 121 | 161 | }, |
|
| 122 | 162 | "namespaces": { |
|
| 123 | 163 | "patterns": [ |
| 173 | 213 | "match": "[,;]", |
|
| 174 | 214 | "name": "punctuation.separator.radiance" |
|
| 175 | 215 | } |
|
| 176 | 216 | ] |
|
| 177 | 217 | }, |
|
| 218 | + | "regions": { |
|
| 219 | + | "patterns": [ |
|
| 220 | + | { |
|
| 221 | + | "captures": { |
|
| 222 | + | "1": { |
|
| 223 | + | "name": "punctuation.definition.region.radiance" |
|
| 224 | + | }, |
|
| 225 | + | "2": { |
|
| 226 | + | "name": "entity.name.type.region.radiance" |
|
| 227 | + | } |
|
| 228 | + | }, |
|
| 229 | + | "match": "(')([A-Za-z_][A-Za-z0-9_]*)(?!')\\b" |
|
| 230 | + | } |
|
| 231 | + | ] |
|
| 232 | + | }, |
|
| 178 | 233 | "strings": { |
|
| 179 | 234 | "patterns": [ |
|
| 180 | 235 | { |
|
| 181 | 236 | "begin": "\"", |
|
| 182 | 237 | "beginCaptures": { |
| 201 | 256 | "name": "invalid.illegal.escape.radiance" |
|
| 202 | 257 | } |
|
| 203 | 258 | ] |
|
| 204 | 259 | }, |
|
| 205 | 260 | { |
|
| 206 | - | "begin": "'", |
|
| 261 | + | "match": "'[A-Za-z_][A-Za-z0-9_]*'", |
|
| 262 | + | "name": "string.quoted.single.radiance" |
|
| 263 | + | }, |
|
| 264 | + | { |
|
| 265 | + | "begin": "'(?![A-Za-z_])", |
|
| 207 | 266 | "beginCaptures": { |
|
| 208 | 267 | "0": { |
|
| 209 | 268 | "name": "punctuation.definition.string.begin.radiance" |
|
| 210 | 269 | } |
|
| 211 | 270 | }, |
crates/highlight/tests/syntaxes.rs
+71 -0
| 353 | 353 | import_scopes.contains(&"entity.name.namespace.radiance"), |
|
| 354 | 354 | "{import_scopes:?}" |
|
| 355 | 355 | ); |
|
| 356 | 356 | } |
|
| 357 | 357 | ||
| 358 | + | #[test] |
|
| 359 | + | fn radiance_highlights_lexical_regions() { |
|
| 360 | + | let grammar = Grammar::from_str(syntaxes::RADIANCE).unwrap(); |
|
| 361 | + | let scopes = tokenize_scopes( |
|
| 362 | + | &grammar, |
|
| 363 | + | "fn store 'long 'short (dst: &'short mut ?&'long u32) where 'long: 'short {}", |
|
| 364 | + | ); |
|
| 365 | + | let where_scopes = tokenize_scopes(&grammar, "where"); |
|
| 366 | + | let character_scopes = tokenize_scopes(&grammar, "let ch = 'region';"); |
|
| 367 | + | ||
| 368 | + | assert!( |
|
| 369 | + | scopes.contains(&"entity.name.function.radiance"), |
|
| 370 | + | "{scopes:?}" |
|
| 371 | + | ); |
|
| 372 | + | assert!( |
|
| 373 | + | scopes.contains(&"entity.name.type.region.radiance"), |
|
| 374 | + | "{scopes:?}" |
|
| 375 | + | ); |
|
| 376 | + | assert!( |
|
| 377 | + | where_scopes.contains(&"keyword.control.radiance"), |
|
| 378 | + | "{where_scopes:?}" |
|
| 379 | + | ); |
|
| 380 | + | assert!( |
|
| 381 | + | !scopes.contains(&"string.quoted.single.radiance"), |
|
| 382 | + | "{scopes:?}" |
|
| 383 | + | ); |
|
| 384 | + | assert!( |
|
| 385 | + | character_scopes.contains(&"string.quoted.single.radiance"), |
|
| 386 | + | "{character_scopes:?}" |
|
| 387 | + | ); |
|
| 388 | + | assert!( |
|
| 389 | + | !character_scopes.contains(&"entity.name.type.region.radiance"), |
|
| 390 | + | "{character_scopes:?}" |
|
| 391 | + | ); |
|
| 392 | + | } |
|
| 393 | + | ||
| 394 | + | #[test] |
|
| 395 | + | fn radiance_highlights_scoped_region_bindings() { |
|
| 396 | + | let grammar = Grammar::from_str(syntaxes::RADIANCE).unwrap(); |
|
| 397 | + | let session_scopes = tokenize_scopes(&grammar, "use arena as objects in {"); |
|
| 398 | + | let region_scopes = tokenize_scopes( |
|
| 399 | + | &grammar, |
|
| 400 | + | "let resolved: 'phase = &*res where 'arena: 'phase in {", |
|
| 401 | + | ); |
|
| 402 | + | ||
| 403 | + | assert!( |
|
| 404 | + | session_scopes.contains(&"meta.binding.session.radiance"), |
|
| 405 | + | "{session_scopes:?}" |
|
| 406 | + | ); |
|
| 407 | + | assert!( |
|
| 408 | + | session_scopes.contains(&"variable.other.radiance"), |
|
| 409 | + | "{session_scopes:?}" |
|
| 410 | + | ); |
|
| 411 | + | assert!( |
|
| 412 | + | !session_scopes.contains(&"entity.name.namespace.radiance"), |
|
| 413 | + | "{session_scopes:?}" |
|
| 414 | + | ); |
|
| 415 | + | assert!( |
|
| 416 | + | region_scopes.contains(&"meta.binding.region.radiance"), |
|
| 417 | + | "{region_scopes:?}" |
|
| 418 | + | ); |
|
| 419 | + | assert!( |
|
| 420 | + | region_scopes.contains(&"variable.other.radiance"), |
|
| 421 | + | "{region_scopes:?}" |
|
| 422 | + | ); |
|
| 423 | + | assert!( |
|
| 424 | + | region_scopes.contains(&"entity.name.type.region.radiance"), |
|
| 425 | + | "{region_scopes:?}" |
|
| 426 | + | ); |
|
| 427 | + | } |
|
| 428 | + | ||
| 358 | 429 | #[test] |
|
| 359 | 430 | fn ril_highlights_language_constructs() { |
|
| 360 | 431 | let grammar = Grammar::from_str(syntaxes::RIL).unwrap(); |
|
| 361 | 432 | let scopes = tokenize_scopes(&grammar, "br.ult w32 %7 3 @guard#pass $WORDS;"); |
|
| 362 | 433 | let quoted_scopes = tokenize_scopes(&grammar, "fn w32 $\"quoted.name\"() {"); |