highlight: Add Radiance and RIL syntaxes

f611042b735682bc66a0dadfd87ef3a1fc3c6d91
Bundle grammars and registration for Radiance and RIL so source files
receive language-aware highlighting. Cover Radiance module and import
namespaces to keep declaration and use-site colors consistent.

Assisted-by: Codex:gpt-5.6-sol
Alexis Sellier committed ago 1 parent f7c69f46
crates/diff/src/builtins.rs +13 -1
17 17
/// Built-in syntax theme JSON.
18 18
const THEME: &str = include_str!("themes/rustik-catppuccin-mocha.json");
19 19
/// Relative directory containing user-defined TextMate grammars.
20 20
const CUSTOM_SYNTAX_DIR: &str = "rustik/highlight/grammars";
21 21
/// Common syntax grammars loaded by the interactive pager.
22 -
const SYNTAXES: [SyntaxAsset; 20] = [
22 +
const SYNTAXES: [SyntaxAsset; 22] = [
23 23
    SyntaxAsset {
24 24
        source: syntax::syntaxes::C,
25 25
        file_types: &["c", "h"],
26 26
        dependencies: &[],
27 27
    },
85 85
    SyntaxAsset {
86 86
        source: syntax::syntaxes::PYTHON,
87 87
        file_types: &["py", "pyw"],
88 88
        dependencies: &[],
89 89
    },
90 +
    SyntaxAsset {
91 +
        source: syntax::syntaxes::RADIANCE,
92 +
        file_types: &["rad"],
93 +
        dependencies: &[],
94 +
    },
95 +
    SyntaxAsset {
96 +
        source: syntax::syntaxes::RIL,
97 +
        file_types: &["ril"],
98 +
        dependencies: &[],
99 +
    },
90 100
    SyntaxAsset {
91 101
        source: syntax::syntaxes::RUBY,
92 102
        file_types: &["rb", "rake", "gemspec"],
93 103
        dependencies: &[],
94 104
    },
313 323
            "rules.mk",
314 324
            "index.html.erb",
315 325
            "config.fish",
316 326
            "init.lua",
317 327
            "script.py",
328 +
            "main.rad",
329 +
            "main.ril",
318 330
            "task.rb",
319 331
            "build.sh",
320 332
            "Cargo.toml",
321 333
            "schema.sql",
322 334
            "component.tsx",
script\n\ +0 -0
{path}\n\ +0 -0
crates/highlight/src/syntaxes.rs +5 -0
37 37
/// Python grammar source.
38 38
pub const PYTHON: &str = include_str!("../syntaxes/python.json");
39 39
40 40
/// Ruby grammar source.
41 41
pub const RUBY: &str = include_str!("../syntaxes/ruby.json");
42 +
/// Radiance grammar source.
43 +
pub const RADIANCE: &str = include_str!("../syntaxes/radiance.json");
44 +
45 +
/// Radiance IL grammar source.
46 +
pub const RIL: &str = include_str!("../syntaxes/ril.json");
42 47
43 48
/// Rust grammar source.
44 49
pub const RUST: &str = include_str!("../syntaxes/rust.json");
45 50
46 51
/// Shell grammar source.
crates/highlight/syntaxes/radiance.json added +234 -0
1 +
{
2 +
  "displayName": "Radiance",
3 +
  "fileTypes": [
4 +
    "rad"
5 +
  ],
6 +
  "name": "radiance",
7 +
  "patterns": [
8 +
    {
9 +
      "include": "#comments"
10 +
    },
11 +
    {
12 +
      "include": "#strings"
13 +
    },
14 +
    {
15 +
      "include": "#builtins"
16 +
    },
17 +
    {
18 +
      "include": "#modules"
19 +
    },
20 +
    {
21 +
      "include": "#namespaces"
22 +
    },
23 +
    {
24 +
      "include": "#functions"
25 +
    },
26 +
    {
27 +
      "include": "#keywords"
28 +
    },
29 +
    {
30 +
      "include": "#numbers"
31 +
    },
32 +
    {
33 +
      "include": "#operators"
34 +
    },
35 +
    {
36 +
      "include": "#punctuation"
37 +
    }
38 +
  ],
39 +
  "repository": {
40 +
    "builtins": {
41 +
      "patterns": [
42 +
        {
43 +
          "match": "@[A-Za-z_][A-Za-z0-9_]*",
44 +
          "name": "support.function.builtin.radiance"
45 +
        }
46 +
      ]
47 +
    },
48 +
    "comments": {
49 +
      "patterns": [
50 +
        {
51 +
          "begin": "//|--",
52 +
          "beginCaptures": {
53 +
            "0": {
54 +
              "name": "punctuation.definition.comment.radiance"
55 +
            }
56 +
          },
57 +
          "end": "$",
58 +
          "name": "comment.line.radiance",
59 +
          "patterns": [
60 +
            {
61 +
              "match": "\\b(?:TODO|FIXME)\\b",
62 +
              "name": "keyword.other.todo.radiance"
63 +
            }
64 +
          ]
65 +
        }
66 +
      ]
67 +
    },
68 +
    "functions": {
69 +
      "patterns": [
70 +
        {
71 +
          "match": "\\b[A-Za-z_][A-Za-z0-9_]*\\b(?=\\s*\\??\\()",
72 +
          "name": "entity.name.function.radiance"
73 +
        }
74 +
      ]
75 +
    },
76 +
    "keywords": {
77 +
      "patterns": [
78 +
        {
79 +
          "match": "\\b(?:bit|bool|f32|i8|i16|i32|i64|opaque|u8|u16|u32|u64|void)\\b",
80 +
          "name": "storage.type.radiance"
81 +
        },
82 +
        {
83 +
          "match": "\\b(?:false|nil|true|undefined)\\b",
84 +
          "name": "constant.language.radiance"
85 +
        },
86 +
        {
87 +
          "match": "\\b(?:align|and|as|assert|break|case|catch|constant|continue|else|export|fn|for|if|in|instance|let|log|loop|match|mod|mut|not|or|panic|record|return|set|static|super|throw|throws|trait|try|union|use|while)\\b",
88 +
          "name": "keyword.control.radiance"
89 +
        },
90 +
        {
91 +
          "match": "\\b_\\b",
92 +
          "name": "constant.language.placeholder.radiance"
93 +
        }
94 +
      ]
95 +
    },
96 +
    "modules": {
97 +
      "patterns": [
98 +
        {
99 +
          "captures": {
100 +
            "1": {
101 +
              "name": "keyword.control.radiance"
102 +
            },
103 +
            "2": {
104 +
              "name": "entity.name.namespace.radiance"
105 +
            }
106 +
          },
107 +
          "match": "\\b(mod)\\s+([A-Za-z_][A-Za-z0-9_]*)\\b"
108 +
        },
109 +
        {
110 +
          "captures": {
111 +
            "1": {
112 +
              "name": "keyword.control.radiance"
113 +
            },
114 +
            "2": {
115 +
              "name": "entity.name.namespace.radiance"
116 +
            }
117 +
          },
118 +
          "match": "\\b(use)\\s+([A-Za-z_][A-Za-z0-9_]*)\\b"
119 +
        }
120 +
      ]
121 +
    },
122 +
    "namespaces": {
123 +
      "patterns": [
124 +
        {
125 +
          "match": "\\b[A-Za-z_][A-Za-z0-9_]*\\b(?=\\s*::)",
126 +
          "name": "entity.name.namespace.radiance"
127 +
        },
128 +
        {
129 +
          "match": "::",
130 +
          "name": "punctuation.accessor.double-colon.radiance"
131 +
        }
132 +
      ]
133 +
    },
134 +
    "numbers": {
135 +
      "patterns": [
136 +
        {
137 +
          "match": "(?<![A-Za-z0-9_])[+-]?0[xX][0-9A-Fa-f]+",
138 +
          "name": "constant.numeric.integer.hexadecimal.radiance"
139 +
        },
140 +
        {
141 +
          "match": "(?<![A-Za-z0-9_])[+-]?0[bB][01]+",
142 +
          "name": "constant.numeric.integer.binary.radiance"
143 +
        },
144 +
        {
145 +
          "match": "(?<![A-Za-z0-9_])[+-]?(?:[0-9]+\\.[0-9]+|[0-9]+)",
146 +
          "name": "constant.numeric.radiance"
147 +
        }
148 +
      ]
149 +
    },
150 +
    "operators": {
151 +
      "patterns": [
152 +
        {
153 +
          "match": "=>|->|\\.\\.|<<=|>>=|==|<>|<=|>=|\\+=|-=|\\*=|/=|%=|&=|\\|=|\\^=|<<|>>|[.!?~&|^%+\\-*/=<>:]",
154 +
          "name": "keyword.operator.radiance"
155 +
        }
156 +
      ]
157 +
    },
158 +
    "punctuation": {
159 +
      "patterns": [
160 +
        {
161 +
          "match": "[{}]",
162 +
          "name": "punctuation.section.block.radiance"
163 +
        },
164 +
        {
165 +
          "match": "[()]",
166 +
          "name": "punctuation.section.group.radiance"
167 +
        },
168 +
        {
169 +
          "match": "[\\[\\]]",
170 +
          "name": "punctuation.section.brackets.radiance"
171 +
        },
172 +
        {
173 +
          "match": "[,;]",
174 +
          "name": "punctuation.separator.radiance"
175 +
        }
176 +
      ]
177 +
    },
178 +
    "strings": {
179 +
      "patterns": [
180 +
        {
181 +
          "begin": "\"",
182 +
          "beginCaptures": {
183 +
            "0": {
184 +
              "name": "punctuation.definition.string.begin.radiance"
185 +
            }
186 +
          },
187 +
          "end": "\"",
188 +
          "endCaptures": {
189 +
            "0": {
190 +
              "name": "punctuation.definition.string.end.radiance"
191 +
            }
192 +
          },
193 +
          "name": "string.quoted.double.radiance",
194 +
          "patterns": [
195 +
            {
196 +
              "match": "\\\\[\\\"'nrtvfab\\\\]",
197 +
              "name": "constant.character.escape.radiance"
198 +
            },
199 +
            {
200 +
              "match": "\\\\.",
201 +
              "name": "invalid.illegal.escape.radiance"
202 +
            }
203 +
          ]
204 +
        },
205 +
        {
206 +
          "begin": "'",
207 +
          "beginCaptures": {
208 +
            "0": {
209 +
              "name": "punctuation.definition.string.begin.radiance"
210 +
            }
211 +
          },
212 +
          "end": "'",
213 +
          "endCaptures": {
214 +
            "0": {
215 +
              "name": "punctuation.definition.string.end.radiance"
216 +
            }
217 +
          },
218 +
          "name": "string.quoted.single.radiance",
219 +
          "patterns": [
220 +
            {
221 +
              "match": "\\\\[\\\"'nrtvfab\\\\]",
222 +
              "name": "constant.character.escape.radiance"
223 +
            },
224 +
            {
225 +
              "match": "\\\\.",
226 +
              "name": "invalid.illegal.escape.radiance"
227 +
            }
228 +
          ]
229 +
        }
230 +
      ]
231 +
    }
232 +
  },
233 +
  "scopeName": "source.radiance"
234 +
}
crates/highlight/syntaxes/ril.json added +193 -0
1 +
{
2 +
  "displayName": "Radiance IL",
3 +
  "fileTypes": [
4 +
    "ril"
5 +
  ],
6 +
  "name": "ril",
7 +
  "patterns": [
8 +
    {
9 +
      "include": "#comments"
10 +
    },
11 +
    {
12 +
      "include": "#symbols"
13 +
    },
14 +
    {
15 +
      "include": "#strings"
16 +
    },
17 +
    {
18 +
      "include": "#labels"
19 +
    },
20 +
    {
21 +
      "include": "#registers"
22 +
    },
23 +
    {
24 +
      "include": "#branches"
25 +
    },
26 +
    {
27 +
      "include": "#keywords"
28 +
    },
29 +
    {
30 +
      "include": "#numbers"
31 +
    },
32 +
    {
33 +
      "include": "#punctuation"
34 +
    }
35 +
  ],
36 +
  "repository": {
37 +
    "branches": {
38 +
      "patterns": [
39 +
        {
40 +
          "captures": {
41 +
            "1": {
42 +
              "name": "keyword.control.branch.ril"
43 +
            },
44 +
            "2": {
45 +
              "name": "keyword.operator.comparison.ril"
46 +
            }
47 +
          },
48 +
          "match": "\\b(br)\\.(eq|ne|slt|ult)\\b",
49 +
          "name": "keyword.control.branch.ril"
50 +
        }
51 +
      ]
52 +
    },
53 +
    "comments": {
54 +
      "patterns": [
55 +
        {
56 +
          "begin": "//",
57 +
          "beginCaptures": {
58 +
            "0": {
59 +
              "name": "punctuation.definition.comment.ril"
60 +
            }
61 +
          },
62 +
          "end": "$",
63 +
          "name": "comment.line.double-slash.ril",
64 +
          "patterns": [
65 +
            {
66 +
              "match": "\\b(?:TODO|FIXME)\\b",
67 +
              "name": "keyword.other.todo.ril"
68 +
            }
69 +
          ]
70 +
        }
71 +
      ]
72 +
    },
73 +
    "keywords": {
74 +
      "patterns": [
75 +
        {
76 +
          "match": "\\b(?:void|w8|w16|w32|w64)\\b",
77 +
          "name": "storage.type.ril"
78 +
        },
79 +
        {
80 +
          "match": "\\b(?:str|sym|undef|undefined)\\b",
81 +
          "name": "constant.language.ril"
82 +
        },
83 +
        {
84 +
          "match": "\\b(?:add|and|blit|call|copy|ebreak|ecall|eq|jmp|load|mul|ne|neg|not|or|reserve|ret|sdiv|sext|sge|shl|sload|slt|srem|sshr|store|sub|switch|udiv|uge|ult|unreachable|urem|ushr|xor|zext)\\b",
85 +
          "name": "keyword.other.instruction.ril"
86 +
        },
87 +
        {
88 +
          "match": "\\b(?:align|data|extern|fn|mut)\\b",
89 +
          "name": "keyword.control.ril"
90 +
        }
91 +
      ]
92 +
    },
93 +
    "labels": {
94 +
      "patterns": [
95 +
        {
96 +
          "match": "@[A-Za-z_][A-Za-z0-9_#.]*",
97 +
          "name": "entity.name.label.ril"
98 +
        }
99 +
      ]
100 +
    },
101 +
    "numbers": {
102 +
      "patterns": [
103 +
        {
104 +
          "match": "(?<![A-Za-z0-9_])-?0[xX][0-9A-Fa-f]+",
105 +
          "name": "constant.numeric.integer.hexadecimal.ril"
106 +
        },
107 +
        {
108 +
          "match": "(?<![A-Za-z0-9_])-?[0-9]+",
109 +
          "name": "constant.numeric.integer.decimal.ril"
110 +
        }
111 +
      ]
112 +
    },
113 +
    "punctuation": {
114 +
      "patterns": [
115 +
        {
116 +
          "match": "[{}]",
117 +
          "name": "punctuation.section.block.ril"
118 +
        },
119 +
        {
120 +
          "match": "[()]",
121 +
          "name": "punctuation.section.group.ril"
122 +
        },
123 +
        {
124 +
          "match": "[;:,]",
125 +
          "name": "punctuation.separator.ril"
126 +
        },
127 +
        {
128 +
          "match": "\\*",
129 +
          "name": "keyword.operator.ril"
130 +
        }
131 +
      ]
132 +
    },
133 +
    "registers": {
134 +
      "patterns": [
135 +
        {
136 +
          "match": "%[A-Za-z0-9_]+",
137 +
          "name": "variable.other.register.ril"
138 +
        }
139 +
      ]
140 +
    },
141 +
    "strings": {
142 +
      "patterns": [
143 +
        {
144 +
          "begin": "\"",
145 +
          "beginCaptures": {
146 +
            "0": {
147 +
              "name": "punctuation.definition.string.begin.ril"
148 +
            }
149 +
          },
150 +
          "end": "\"",
151 +
          "endCaptures": {
152 +
            "0": {
153 +
              "name": "punctuation.definition.string.end.ril"
154 +
            }
155 +
          },
156 +
          "name": "string.quoted.double.ril",
157 +
          "patterns": [
158 +
            {
159 +
              "match": "\\\\.",
160 +
              "name": "constant.character.escape.ril"
161 +
            }
162 +
          ]
163 +
        }
164 +
      ]
165 +
    },
166 +
    "symbols": {
167 +
      "patterns": [
168 +
        {
169 +
          "captures": {
170 +
            "1": {
171 +
              "name": "punctuation.definition.variable.ril"
172 +
            },
173 +
            "2": {
174 +
              "name": "punctuation.definition.string.begin.ril"
175 +
            },
176 +
            "3": {
177 +
              "name": "variable.other.symbol.quoted.ril"
178 +
            },
179 +
            "4": {
180 +
              "name": "punctuation.definition.string.end.ril"
181 +
            }
182 +
          },
183 +
          "match": "(\\$)(\")([^\"]*)(\")"
184 +
        },
185 +
        {
186 +
          "match": "\\$[A-Za-z_][$A-Za-z0-9_]*",
187 +
          "name": "variable.other.symbol.ril"
188 +
        }
189 +
      ]
190 +
    }
191 +
  },
192 +
  "scopeName": "source.ril"
193 +
}
crates/highlight/tests/syntaxes.rs +64 -0
16 16
        syntaxes::HTML,
17 17
        syntaxes::JAVASCRIPT,
18 18
        syntaxes::LUA,
19 19
        syntaxes::MAKE,
20 20
        syntaxes::MARKDOWN,
21 +
        syntaxes::RADIANCE,
22 +
        syntaxes::RIL,
21 23
        syntaxes::PYTHON,
22 24
        syntaxes::RUBY,
23 25
        syntaxes::RUST,
24 26
        syntaxes::SHELL,
25 27
        syntaxes::SQL,
317 319
        scopes.contains(&"constant.other.reference.link.markdown"),
318 320
        "{scopes:?}"
319 321
    );
320 322
}
321 323
324 +
#[test]
325 +
fn radiance_highlights_language_constructs() {
326 +
    let grammar = Grammar::from_str(syntaxes::RADIANCE).unwrap();
327 +
    let scopes = tokenize_scopes(
328 +
        &grammar,
329 +
        "@test export fn decode(ch: u8) -> bool { return ch >= '0'; }",
330 +
    );
331 +
    let module_scopes = tokenize_scopes(&grammar, "mod scanner;");
332 +
    let import_scopes = tokenize_scopes(&grammar, "use scanner;");
333 +
334 +
    assert!(
335 +
        scopes.contains(&"support.function.builtin.radiance"),
336 +
        "{scopes:?}"
337 +
    );
338 +
    assert!(
339 +
        scopes.contains(&"entity.name.function.radiance"),
340 +
        "{scopes:?}"
341 +
    );
342 +
    assert!(scopes.contains(&"storage.type.radiance"), "{scopes:?}");
343 +
    assert!(
344 +
        scopes.contains(&"string.quoted.single.radiance"),
345 +
        "{scopes:?}"
346 +
    );
347 +
    assert!(scopes.contains(&"keyword.operator.radiance"), "{scopes:?}");
348 +
    assert!(
349 +
        module_scopes.contains(&"entity.name.namespace.radiance"),
350 +
        "{module_scopes:?}"
351 +
    );
352 +
    assert!(
353 +
        import_scopes.contains(&"entity.name.namespace.radiance"),
354 +
        "{import_scopes:?}"
355 +
    );
356 +
}
357 +
358 +
#[test]
359 +
fn ril_highlights_language_constructs() {
360 +
    let grammar = Grammar::from_str(syntaxes::RIL).unwrap();
361 +
    let scopes = tokenize_scopes(&grammar, "br.ult w32 %7 3 @guard#pass $WORDS;");
362 +
    let quoted_scopes = tokenize_scopes(&grammar, "fn w32 $\"quoted.name\"() {");
363 +
364 +
    assert!(scopes.contains(&"keyword.control.branch.ril"), "{scopes:?}");
365 +
    assert!(
366 +
        scopes.contains(&"keyword.operator.comparison.ril"),
367 +
        "{scopes:?}"
368 +
    );
369 +
    assert!(scopes.contains(&"storage.type.ril"), "{scopes:?}");
370 +
    assert!(
371 +
        scopes.contains(&"variable.other.register.ril"),
372 +
        "{scopes:?}"
373 +
    );
374 +
    assert!(
375 +
        scopes.contains(&"constant.numeric.integer.decimal.ril"),
376 +
        "{scopes:?}"
377 +
    );
378 +
    assert!(scopes.contains(&"entity.name.label.ril"), "{scopes:?}");
379 +
    assert!(scopes.contains(&"variable.other.symbol.ril"), "{scopes:?}");
380 +
    assert!(
381 +
        quoted_scopes.contains(&"variable.other.symbol.quoted.ril"),
382 +
        "{quoted_scopes:?}"
383 +
    );
384 +
}
385 +
322 386
/// Tokenizes `line` and returns its scope names.
323 387
fn tokenize_scopes<'a>(grammar: &'a Grammar, line: &str) -> Vec<&'a str> {
324 388
    let mut state = LineState::default();
325 389
    let mut tokenizer = LineTokenizer::new(grammar);
326 390
    let spans = tokenizer.tokenize_line(&mut state, line);