highlight: Add YAML and TOML grammars

b541deb08433ad04ead55c499938d2f116bcdccd
Bundle the upstream YAML and TOML TextMate grammars and expose them
through the built-in syntax list.

Wire the pager asset list for .toml, .yaml, and .yml files and add
syntax tests for common keys, sections, strings, booleans, and
comments.

Assisted-by: Codex:gpt-5.5
Alexis Sellier committed ago 1 parent 8879398e
crates/diff/src/bin/rustik-diff/builtins.rs +13 -1
8 8
/// Theme name used for built-in diff highlighting.
9 9
const THEME_NAME: &str = "rustik-catppuccin-mocha";
10 10
/// Built-in syntax theme JSON.
11 11
const THEME: &str = include_str!("../../themes/rustik-catppuccin-mocha.json");
12 12
/// Common syntax grammars loaded by the interactive pager.
13 -
const SYNTAXES: [SyntaxAsset; 13] = [
13 +
const SYNTAXES: [SyntaxAsset; 15] = [
14 14
    SyntaxAsset {
15 15
        source: syntax::syntaxes::C,
16 16
        file_types: &["c", "h"],
17 17
        dependencies: &[],
18 18
    },
74 74
    SyntaxAsset {
75 75
        source: syntax::syntaxes::SHELL,
76 76
        file_types: &["sh", "bash", "zsh"],
77 77
        dependencies: &[],
78 78
    },
79 +
    SyntaxAsset {
80 +
        source: syntax::syntaxes::TOML,
81 +
        file_types: &["toml"],
82 +
        dependencies: &[],
83 +
    },
79 84
    SyntaxAsset {
80 85
        source: syntax::syntaxes::TYPESCRIPT,
81 86
        file_types: &["ts", "cts", "mts"],
82 87
        dependencies: &[],
83 88
    },
89 +
    SyntaxAsset {
90 +
        source: syntax::syntaxes::YAML,
91 +
        file_types: &["yaml", "yml"],
92 +
        dependencies: &[],
93 +
    },
84 94
];
85 95
86 96
/// Binary-local highlight assets loaded for one diff document.
87 97
pub(super) struct Builtins {
88 98
    /// Diff chrome palette derived from the built-in theme.
185 195
            "rules.mk",
186 196
            "index.html.erb",
187 197
            "script.py",
188 198
            "task.rb",
189 199
            "build.sh",
200 +
            "Cargo.toml",
201 +
            "config.yml",
190 202
        ] {
191 203
            assert!(
192 204
                SYNTAXES
193 205
                    .iter()
194 206
                    .any(|syntax| syntax.matches_path(path.as_ref())),
crates/highlight/src/syntaxes.rs +6 -0
38 38
pub const RUST: &str = include_str!("../syntaxes/rust.json");
39 39
40 40
/// Shell grammar source.
41 41
pub const SHELL: &str = include_str!("../syntaxes/shellscript.json");
42 42
43 +
/// TOML grammar source.
44 +
pub const TOML: &str = include_str!("../syntaxes/toml.json");
45 +
43 46
/// TypeScript grammar source.
44 47
pub const TYPESCRIPT: &str = include_str!("../syntaxes/typescript.json");
48 +
49 +
/// YAML grammar source.
50 +
pub const YAML: &str = include_str!("../syntaxes/yaml.json");
crates/highlight/syntaxes/toml.json added +430 -0
1 +
{
2 +
  "displayName": "TOML",
3 +
  "fileTypes": [
4 +
    "toml"
5 +
  ],
6 +
  "name": "toml",
7 +
  "patterns": [
8 +
    {
9 +
      "include": "#comments"
10 +
    },
11 +
    {
12 +
      "include": "#groups"
13 +
    },
14 +
    {
15 +
      "include": "#key_pair"
16 +
    },
17 +
    {
18 +
      "include": "#invalid"
19 +
    }
20 +
  ],
21 +
  "repository": {
22 +
    "comments": {
23 +
      "begin": "(^[\\t ]+)?(?=#)",
24 +
      "beginCaptures": {
25 +
        "1": {
26 +
          "name": "punctuation.whitespace.comment.leading.toml"
27 +
        }
28 +
      },
29 +
      "end": "(?!\\G)",
30 +
      "patterns": [
31 +
        {
32 +
          "begin": "#",
33 +
          "beginCaptures": {
34 +
            "0": {
35 +
              "name": "punctuation.definition.comment.toml"
36 +
            }
37 +
          },
38 +
          "end": "\\n",
39 +
          "name": "comment.line.number-sign.toml"
40 +
        }
41 +
      ]
42 +
    },
43 +
    "groups": {
44 +
      "patterns": [
45 +
        {
46 +
          "captures": {
47 +
            "1": {
48 +
              "name": "punctuation.definition.section.begin.toml"
49 +
            },
50 +
            "2": {
51 +
              "patterns": [
52 +
                {
53 +
                  "match": "[^.\\s]+",
54 +
                  "name": "entity.name.section.toml"
55 +
                }
56 +
              ]
57 +
            },
58 +
            "3": {
59 +
              "name": "punctuation.definition.section.begin.toml"
60 +
            }
61 +
          },
62 +
          "match": "^\\s*(\\[)([^]\\[]*)(])",
63 +
          "name": "meta.group.toml"
64 +
        },
65 +
        {
66 +
          "captures": {
67 +
            "1": {
68 +
              "name": "punctuation.definition.section.begin.toml"
69 +
            },
70 +
            "2": {
71 +
              "patterns": [
72 +
                {
73 +
                  "match": "[^.\\s]+",
74 +
                  "name": "entity.name.section.toml"
75 +
                }
76 +
              ]
77 +
            },
78 +
            "3": {
79 +
              "name": "punctuation.definition.section.begin.toml"
80 +
            }
81 +
          },
82 +
          "match": "^\\s*(\\[\\[)([^]\\[]*)(]])",
83 +
          "name": "meta.group.double.toml"
84 +
        }
85 +
      ]
86 +
    },
87 +
    "invalid": {
88 +
      "match": "\\S+(\\s*(?=\\S))?",
89 +
      "name": "invalid.illegal.not-allowed-here.toml"
90 +
    },
91 +
    "key_pair": {
92 +
      "patterns": [
93 +
        {
94 +
          "begin": "([-0-9A-Z_a-z]+)\\s*(=)\\s*",
95 +
          "captures": {
96 +
            "1": {
97 +
              "name": "variable.other.key.toml"
98 +
            },
99 +
            "2": {
100 +
              "name": "punctuation.separator.key-value.toml"
101 +
            }
102 +
          },
103 +
          "end": "(?<=\\S)(?<!=)|$",
104 +
          "patterns": [
105 +
            {
106 +
              "include": "#primatives"
107 +
            }
108 +
          ]
109 +
        },
110 +
        {
111 +
          "begin": "((\")(.*?)(\"))\\s*(=)\\s*",
112 +
          "captures": {
113 +
            "1": {
114 +
              "name": "variable.other.key.toml"
115 +
            },
116 +
            "2": {
117 +
              "name": "punctuation.definition.variable.begin.toml"
118 +
            },
119 +
            "3": {
120 +
              "patterns": [
121 +
                {
122 +
                  "match": "\\\\([\"\\\\bfnrt]|u\\h{4}|U\\h{8})",
123 +
                  "name": "constant.character.escape.toml"
124 +
                },
125 +
                {
126 +
                  "match": "\\\\[^\"\\\\bfnrt]",
127 +
                  "name": "invalid.illegal.escape.toml"
128 +
                },
129 +
                {
130 +
                  "match": "\"",
131 +
                  "name": "invalid.illegal.not-allowed-here.toml"
132 +
                }
133 +
              ]
134 +
            },
135 +
            "4": {
136 +
              "name": "punctuation.definition.variable.end.toml"
137 +
            },
138 +
            "5": {
139 +
              "name": "punctuation.separator.key-value.toml"
140 +
            }
141 +
          },
142 +
          "end": "(?<=\\S)(?<!=)|$",
143 +
          "patterns": [
144 +
            {
145 +
              "include": "#primatives"
146 +
            }
147 +
          ]
148 +
        },
149 +
        {
150 +
          "begin": "((')([^']*)('))\\s*(=)\\s*",
151 +
          "captures": {
152 +
            "1": {
153 +
              "name": "variable.other.key.toml"
154 +
            },
155 +
            "2": {
156 +
              "name": "punctuation.definition.variable.begin.toml"
157 +
            },
158 +
            "4": {
159 +
              "name": "punctuation.definition.variable.end.toml"
160 +
            },
161 +
            "5": {
162 +
              "name": "punctuation.separator.key-value.toml"
163 +
            }
164 +
          },
165 +
          "end": "(?<=\\S)(?<!=)|$",
166 +
          "patterns": [
167 +
            {
168 +
              "include": "#primatives"
169 +
            }
170 +
          ]
171 +
        },
172 +
        {
173 +
          "begin": "(((?:[-0-9A-Z_a-z]+|\"(?:[^\"\\\\]|\\\\.)*\"|'[^']*')(?:\\s*\\.\\s*|(?=\\s*=))){2,})\\s*(=)\\s*",
174 +
          "captures": {
175 +
            "1": {
176 +
              "name": "variable.other.key.toml",
177 +
              "patterns": [
178 +
                {
179 +
                  "match": "\\.",
180 +
                  "name": "punctuation.separator.variable.toml"
181 +
                },
182 +
                {
183 +
                  "captures": {
184 +
                    "1": {
185 +
                      "name": "punctuation.definition.variable.begin.toml"
186 +
                    },
187 +
                    "2": {
188 +
                      "patterns": [
189 +
                        {
190 +
                          "match": "\\\\([\"\\\\bfnrt]|u\\h{4}|U\\h{8})",
191 +
                          "name": "constant.character.escape.toml"
192 +
                        },
193 +
                        {
194 +
                          "match": "\\\\[^\"\\\\bfnrt]",
195 +
                          "name": "invalid.illegal.escape.toml"
196 +
                        }
197 +
                      ]
198 +
                    },
199 +
                    "3": {
200 +
                      "name": "punctuation.definition.variable.end.toml"
201 +
                    }
202 +
                  },
203 +
                  "match": "(\")((?:[^\"\\\\]|\\\\.)*)(\")"
204 +
                },
205 +
                {
206 +
                  "captures": {
207 +
                    "1": {
208 +
                      "name": "punctuation.definition.variable.begin.toml"
209 +
                    },
210 +
                    "2": {
211 +
                      "name": "punctuation.definition.variable.end.toml"
212 +
                    }
213 +
                  },
214 +
                  "match": "(')[^']*(')"
215 +
                }
216 +
              ]
217 +
            },
218 +
            "3": {
219 +
              "name": "punctuation.separator.key-value.toml"
220 +
            }
221 +
          },
222 +
          "end": "(?<=\\S)(?<!=)|$",
223 +
          "patterns": [
224 +
            {
225 +
              "include": "#primatives"
226 +
            }
227 +
          ]
228 +
        }
229 +
      ]
230 +
    },
231 +
    "primatives": {
232 +
      "patterns": [
233 +
        {
234 +
          "begin": "\\G\"\"\"",
235 +
          "beginCaptures": {
236 +
            "0": {
237 +
              "name": "punctuation.definition.string.begin.toml"
238 +
            }
239 +
          },
240 +
          "end": "\"{3,5}",
241 +
          "endCaptures": {
242 +
            "0": {
243 +
              "name": "punctuation.definition.string.end.toml"
244 +
            }
245 +
          },
246 +
          "name": "string.quoted.triple.double.toml",
247 +
          "patterns": [
248 +
            {
249 +
              "match": "\\\\([\"\\\\bfnrt]|u\\h{4}|U\\h{8})",
250 +
              "name": "constant.character.escape.toml"
251 +
            },
252 +
            {
253 +
              "match": "\\\\[^\\n\"\\\\bfnrt]",
254 +
              "name": "invalid.illegal.escape.toml"
255 +
            }
256 +
          ]
257 +
        },
258 +
        {
259 +
          "begin": "\\G\"",
260 +
          "beginCaptures": {
261 +
            "0": {
262 +
              "name": "punctuation.definition.string.begin.toml"
263 +
            }
264 +
          },
265 +
          "end": "\"",
266 +
          "endCaptures": {
267 +
            "0": {
268 +
              "name": "punctuation.definition.string.end.toml"
269 +
            }
270 +
          },
271 +
          "name": "string.quoted.double.toml",
272 +
          "patterns": [
273 +
            {
274 +
              "match": "\\\\([\"\\\\bfnrt]|u\\h{4}|U\\h{8})",
275 +
              "name": "constant.character.escape.toml"
276 +
            },
277 +
            {
278 +
              "match": "\\\\[^\"\\\\bfnrt]",
279 +
              "name": "invalid.illegal.escape.toml"
280 +
            }
281 +
          ]
282 +
        },
283 +
        {
284 +
          "begin": "\\G'''",
285 +
          "beginCaptures": {
286 +
            "0": {
287 +
              "name": "punctuation.definition.string.begin.toml"
288 +
            }
289 +
          },
290 +
          "end": "'{3,5}",
291 +
          "endCaptures": {
292 +
            "0": {
293 +
              "name": "punctuation.definition.string.end.toml"
294 +
            }
295 +
          },
296 +
          "name": "string.quoted.triple.single.toml"
297 +
        },
298 +
        {
299 +
          "begin": "\\G'",
300 +
          "beginCaptures": {
301 +
            "0": {
302 +
              "name": "punctuation.definition.string.begin.toml"
303 +
            }
304 +
          },
305 +
          "end": "'",
306 +
          "endCaptures": {
307 +
            "0": {
308 +
              "name": "punctuation.definition.string.end.toml"
309 +
            }
310 +
          },
311 +
          "name": "string.quoted.single.toml"
312 +
        },
313 +
        {
314 +
          "match": "\\G[0-9]{4}-(0[1-9]|1[012])-(?!00|3[2-9])[0-3][0-9]([ Tt](?!2[5-9])[012][0-9]:[0-5][0-9]:(?!6[1-9])[0-6][0-9](\\.[0-9]+)?(Z|[-+](?!2[5-9])[012][0-9]:[0-5][0-9])?)?",
315 +
          "name": "constant.other.date.toml"
316 +
        },
317 +
        {
318 +
          "match": "\\G(?!2[5-9])[012][0-9]:[0-5][0-9]:(?!6[1-9])[0-6][0-9](\\.[0-9]+)?",
319 +
          "name": "constant.other.time.toml"
320 +
        },
321 +
        {
322 +
          "match": "\\G(true|false)",
323 +
          "name": "constant.language.boolean.toml"
324 +
        },
325 +
        {
326 +
          "match": "\\G0x\\h(_??\\h)*",
327 +
          "name": "constant.numeric.hex.toml"
328 +
        },
329 +
        {
330 +
          "match": "\\G0o[0-7]([0-7]|_[0-7])*",
331 +
          "name": "constant.numeric.octal.toml"
332 +
        },
333 +
        {
334 +
          "match": "\\G0b[01]([01]|_[01])*",
335 +
          "name": "constant.numeric.binary.toml"
336 +
        },
337 +
        {
338 +
          "match": "\\G[-+]?(inf|nan)",
339 +
          "name": "constant.numeric.toml"
340 +
        },
341 +
        {
342 +
          "match": "\\G([-+]?(0|([1-9](([0-9]|_[0-9])+)?)))(?=[.Ee])(\\.([0-9](([0-9]|_[0-9])+)?))?([Ee]([-+]?[0-9](([0-9]|_[0-9])+)?))?",
343 +
          "name": "constant.numeric.float.toml"
344 +
        },
345 +
        {
346 +
          "match": "\\G([-+]?(0|([1-9](([0-9]|_[0-9])+)?)))",
347 +
          "name": "constant.numeric.integer.toml"
348 +
        },
349 +
        {
350 +
          "begin": "\\G\\[",
351 +
          "beginCaptures": {
352 +
            "0": {
353 +
              "name": "punctuation.definition.array.begin.toml"
354 +
            }
355 +
          },
356 +
          "end": "]",
357 +
          "endCaptures": {
358 +
            "0": {
359 +
              "name": "punctuation.definition.array.end.toml"
360 +
            }
361 +
          },
362 +
          "name": "meta.array.toml",
363 +
          "patterns": [
364 +
            {
365 +
              "begin": "(?=[\"']|[-+]?[0-9]|[-+]?(inf|nan)|true|false|[\\[{])",
366 +
              "end": ",|(?=])",
367 +
              "endCaptures": {
368 +
                "0": {
369 +
                  "name": "punctuation.separator.array.toml"
370 +
                }
371 +
              },
372 +
              "patterns": [
373 +
                {
374 +
                  "include": "#primatives"
375 +
                },
376 +
                {
377 +
                  "include": "#comments"
378 +
                },
379 +
                {
380 +
                  "include": "#invalid"
381 +
                }
382 +
              ]
383 +
            },
384 +
            {
385 +
              "include": "#comments"
386 +
            },
387 +
            {
388 +
              "include": "#invalid"
389 +
            }
390 +
          ]
391 +
        },
392 +
        {
393 +
          "begin": "\\G\\{",
394 +
          "beginCaptures": {
395 +
            "0": {
396 +
              "name": "punctuation.definition.inline-table.begin.toml"
397 +
            }
398 +
          },
399 +
          "end": "}",
400 +
          "endCaptures": {
401 +
            "0": {
402 +
              "name": "punctuation.definition.inline-table.end.toml"
403 +
            }
404 +
          },
405 +
          "name": "meta.inline-table.toml",
406 +
          "patterns": [
407 +
            {
408 +
              "begin": "(?=\\S)",
409 +
              "end": ",|(?=})",
410 +
              "endCaptures": {
411 +
                "0": {
412 +
                  "name": "punctuation.separator.inline-table.toml"
413 +
                }
414 +
              },
415 +
              "patterns": [
416 +
                {
417 +
                  "include": "#key_pair"
418 +
                }
419 +
              ]
420 +
            },
421 +
            {
422 +
              "include": "#comments"
423 +
            }
424 +
          ]
425 +
        }
426 +
      ]
427 +
    }
428 +
  },
429 +
  "scopeName": "source.toml"
430 +
}
crates/highlight/syntaxes/yaml.json added +627 -0
1 +
{
2 +
  "displayName": "YAML",
3 +
  "fileTypes": [
4 +
    "yaml",
5 +
    "yml",
6 +
    "rviz",
7 +
    "reek",
8 +
    "clang-format",
9 +
    "yaml-tmlanguage",
10 +
    "syntax",
11 +
    "sublime-syntax"
12 +
  ],
13 +
  "firstLineMatch": "^%YAML( ?1.\\d+)?",
14 +
  "name": "yaml",
15 +
  "patterns": [
16 +
    {
17 +
      "include": "#comment"
18 +
    },
19 +
    {
20 +
      "include": "#property"
21 +
    },
22 +
    {
23 +
      "include": "#directive"
24 +
    },
25 +
    {
26 +
      "match": "^---",
27 +
      "name": "entity.other.document.begin.yaml"
28 +
    },
29 +
    {
30 +
      "match": "^\\.{3}",
31 +
      "name": "entity.other.document.end.yaml"
32 +
    },
33 +
    {
34 +
      "include": "#node"
35 +
    }
36 +
  ],
37 +
  "repository": {
38 +
    "block-collection": {
39 +
      "patterns": [
40 +
        {
41 +
          "include": "#block-sequence"
42 +
        },
43 +
        {
44 +
          "include": "#block-mapping"
45 +
        }
46 +
      ]
47 +
    },
48 +
    "block-mapping": {
49 +
      "patterns": [
50 +
        {
51 +
          "include": "#block-pair"
52 +
        }
53 +
      ]
54 +
    },
55 +
    "block-node": {
56 +
      "patterns": [
57 +
        {
58 +
          "include": "#prototype"
59 +
        },
60 +
        {
61 +
          "include": "#block-scalar"
62 +
        },
63 +
        {
64 +
          "include": "#block-collection"
65 +
        },
66 +
        {
67 +
          "include": "#flow-scalar-plain-out"
68 +
        },
69 +
        {
70 +
          "include": "#flow-node"
71 +
        }
72 +
      ]
73 +
    },
74 +
    "block-pair": {
75 +
      "patterns": [
76 +
        {
77 +
          "begin": "\\?",
78 +
          "beginCaptures": {
79 +
            "1": {
80 +
              "name": "punctuation.definition.key-value.begin.yaml"
81 +
            }
82 +
          },
83 +
          "end": "(?=\\?)|^ *(:)|(:)",
84 +
          "endCaptures": {
85 +
            "1": {
86 +
              "name": "punctuation.separator.key-value.mapping.yaml"
87 +
            },
88 +
            "2": {
89 +
              "name": "invalid.illegal.expected-newline.yaml"
90 +
            }
91 +
          },
92 +
          "name": "meta.block-mapping.yaml",
93 +
          "patterns": [
94 +
            {
95 +
              "include": "#block-node"
96 +
            }
97 +
          ]
98 +
        },
99 +
        {
100 +
          "begin": "(?=(?:[^-\\]!\"#%\\&'*,:>?@\\[`{|}\\s]|[-:?]\\S)([^:\\s]|:\\S|\\s+(?![#\\s]))*\\s*:(\\s|$))",
101 +
          "end": "(?=\\s*$|\\s+#|\\s*:(\\s|$))",
102 +
          "patterns": [
103 +
            {
104 +
              "include": "#flow-scalar-plain-out-implicit-type"
105 +
            },
106 +
            {
107 +
              "begin": "[^-\\]!\"#%\\&'*,:>?@\\[`{|}\\s]|[-:?]\\S",
108 +
              "beginCaptures": {
109 +
                "0": {
110 +
                  "name": "entity.name.tag.yaml"
111 +
                }
112 +
              },
113 +
              "contentName": "entity.name.tag.yaml",
114 +
              "end": "(?=\\s*$|\\s+#|\\s*:(\\s|$))",
115 +
              "name": "string.unquoted.plain.out.yaml"
116 +
            }
117 +
          ]
118 +
        },
119 +
        {
120 +
          "match": ":(?=\\s|$)",
121 +
          "name": "punctuation.separator.key-value.mapping.yaml"
122 +
        }
123 +
      ]
124 +
    },
125 +
    "block-scalar": {
126 +
      "begin": "(?:(\\|)|(>))([1-9])?([-+])?(.*\\n?)",
127 +
      "beginCaptures": {
128 +
        "1": {
129 +
          "name": "keyword.control.flow.block-scalar.literal.yaml"
130 +
        },
131 +
        "2": {
132 +
          "name": "keyword.control.flow.block-scalar.folded.yaml"
133 +
        },
134 +
        "3": {
135 +
          "name": "constant.numeric.indentation-indicator.yaml"
136 +
        },
137 +
        "4": {
138 +
          "name": "storage.modifier.chomping-indicator.yaml"
139 +
        },
140 +
        "5": {
141 +
          "patterns": [
142 +
            {
143 +
              "include": "#comment"
144 +
            },
145 +
            {
146 +
              "match": ".+",
147 +
              "name": "invalid.illegal.expected-comment-or-newline.yaml"
148 +
            }
149 +
          ]
150 +
        }
151 +
      },
152 +
      "end": "^(?=\\S)|(?!\\G)",
153 +
      "patterns": [
154 +
        {
155 +
          "begin": "^( +)(?! )",
156 +
          "end": "^(?!\\1|\\s*$)",
157 +
          "name": "string.unquoted.block.yaml"
158 +
        }
159 +
      ]
160 +
    },
161 +
    "block-sequence": {
162 +
      "match": "(-)(?!\\S)",
163 +
      "name": "punctuation.definition.block.sequence.item.yaml"
164 +
    },
165 +
    "comment": {
166 +
      "begin": "(?:^([\\t ]*)|[\\t ]+)(?=#\\p{print}*$)",
167 +
      "beginCaptures": {
168 +
        "1": {
169 +
          "name": "punctuation.whitespace.comment.leading.yaml"
170 +
        }
171 +
      },
172 +
      "end": "(?!\\G)",
173 +
      "patterns": [
174 +
        {
175 +
          "begin": "#",
176 +
          "beginCaptures": {
177 +
            "0": {
178 +
              "name": "punctuation.definition.comment.yaml"
179 +
            }
180 +
          },
181 +
          "end": "\\n",
182 +
          "name": "comment.line.number-sign.yaml"
183 +
        }
184 +
      ]
185 +
    },
186 +
    "directive": {
187 +
      "begin": "^%",
188 +
      "beginCaptures": {
189 +
        "0": {
190 +
          "name": "punctuation.definition.directive.begin.yaml"
191 +
        }
192 +
      },
193 +
      "end": "(?=$|[\\t ]+($|#))",
194 +
      "name": "meta.directive.yaml",
195 +
      "patterns": [
196 +
        {
197 +
          "captures": {
198 +
            "1": {
199 +
              "name": "keyword.other.directive.yaml.yaml"
200 +
            },
201 +
            "2": {
202 +
              "name": "constant.numeric.yaml-version.yaml"
203 +
            }
204 +
          },
205 +
          "match": "\\G(YAML)[\\t ]+(\\d+\\.\\d+)"
206 +
        },
207 +
        {
208 +
          "captures": {
209 +
            "1": {
210 +
              "name": "keyword.other.directive.tag.yaml"
211 +
            },
212 +
            "2": {
213 +
              "name": "storage.type.tag-handle.yaml"
214 +
            },
215 +
            "3": {
216 +
              "name": "support.type.tag-prefix.yaml"
217 +
            }
218 +
          },
219 +
          "match": "\\G(TAG)(?:[\\t ]+(!(?:[-0-9A-Za-z]*!)?)(?:[\\t ]+(!(?:%\\h{2}|[]!#$\\&-;=?-\\[_a-z~])*|(?![]!,\\[{}])(?:%\\h{2}|[]!#$\\&-;=?-\\[_a-z~])+))?)?"
220 +
        },
221 +
        {
222 +
          "captures": {
223 +
            "1": {
224 +
              "name": "support.other.directive.reserved.yaml"
225 +
            },
226 +
            "2": {
227 +
              "name": "string.unquoted.directive-name.yaml"
228 +
            },
229 +
            "3": {
230 +
              "name": "string.unquoted.directive-parameter.yaml"
231 +
            }
232 +
          },
233 +
          "match": "\\G(\\w+)(?:[\\t ]+(\\w+)(?:[\\t ]+(\\w+))?)?"
234 +
        },
235 +
        {
236 +
          "match": "\\S+",
237 +
          "name": "invalid.illegal.unrecognized.yaml"
238 +
        }
239 +
      ]
240 +
    },
241 +
    "flow-alias": {
242 +
      "captures": {
243 +
        "1": {
244 +
          "name": "keyword.control.flow.alias.yaml"
245 +
        },
246 +
        "2": {
247 +
          "name": "punctuation.definition.alias.yaml"
248 +
        },
249 +
        "3": {
250 +
          "name": "variable.other.alias.yaml"
251 +
        },
252 +
        "4": {
253 +
          "name": "invalid.illegal.character.anchor.yaml"
254 +
        }
255 +
      },
256 +
      "match": "((\\*))([^],/\\[{}\\s]+)([^],}\\s]\\S*)?"
257 +
    },
258 +
    "flow-collection": {
259 +
      "patterns": [
260 +
        {
261 +
          "include": "#flow-sequence"
262 +
        },
263 +
        {
264 +
          "include": "#flow-mapping"
265 +
        }
266 +
      ]
267 +
    },
268 +
    "flow-mapping": {
269 +
      "begin": "\\{",
270 +
      "beginCaptures": {
271 +
        "0": {
272 +
          "name": "punctuation.definition.mapping.begin.yaml"
273 +
        }
274 +
      },
275 +
      "end": "}",
276 +
      "endCaptures": {
277 +
        "0": {
278 +
          "name": "punctuation.definition.mapping.end.yaml"
279 +
        }
280 +
      },
281 +
      "name": "meta.flow-mapping.yaml",
282 +
      "patterns": [
283 +
        {
284 +
          "include": "#prototype"
285 +
        },
286 +
        {
287 +
          "match": ",",
288 +
          "name": "punctuation.separator.mapping.yaml"
289 +
        },
290 +
        {
291 +
          "include": "#flow-pair"
292 +
        }
293 +
      ]
294 +
    },
295 +
    "flow-node": {
296 +
      "patterns": [
297 +
        {
298 +
          "include": "#prototype"
299 +
        },
300 +
        {
301 +
          "include": "#flow-alias"
302 +
        },
303 +
        {
304 +
          "include": "#flow-collection"
305 +
        },
306 +
        {
307 +
          "include": "#flow-scalar"
308 +
        }
309 +
      ]
310 +
    },
311 +
    "flow-pair": {
312 +
      "patterns": [
313 +
        {
314 +
          "begin": "\\?",
315 +
          "beginCaptures": {
316 +
            "0": {
317 +
              "name": "punctuation.definition.key-value.begin.yaml"
318 +
            }
319 +
          },
320 +
          "end": "(?=[],}])",
321 +
          "name": "meta.flow-pair.explicit.yaml",
322 +
          "patterns": [
323 +
            {
324 +
              "include": "#prototype"
325 +
            },
326 +
            {
327 +
              "include": "#flow-pair"
328 +
            },
329 +
            {
330 +
              "include": "#flow-node"
331 +
            },
332 +
            {
333 +
              "begin": ":(?=\\s|$|[],\\[{}])",
334 +
              "beginCaptures": {
335 +
                "0": {
336 +
                  "name": "punctuation.separator.key-value.mapping.yaml"
337 +
                }
338 +
              },
339 +
              "end": "(?=[],}])",
340 +
              "patterns": [
341 +
                {
342 +
                  "include": "#flow-value"
343 +
                }
344 +
              ]
345 +
            }
346 +
          ]
347 +
        },
348 +
        {
349 +
          "begin": "(?=(?:[^-\\]!\"#%\\&'*,:>?@\\[`{|}\\s]|[-:?][^],\\[{}\\s])([^],:\\[{}\\s]|:[^],\\[{}\\s]|\\s+(?![#\\s]))*\\s*:(\\s|$))",
350 +
          "end": "(?=\\s*$|\\s+#|\\s*:(\\s|$)|\\s*:[],\\[{}]|\\s*[],\\[{}])",
351 +
          "name": "meta.flow-pair.key.yaml",
352 +
          "patterns": [
353 +
            {
354 +
              "include": "#flow-scalar-plain-in-implicit-type"
355 +
            },
356 +
            {
357 +
              "begin": "[^-\\]!\"#%\\&'*,:>?@\\[`{|}\\s]|[-:?][^],\\[{}\\s]",
358 +
              "beginCaptures": {
359 +
                "0": {
360 +
                  "name": "entity.name.tag.yaml"
361 +
                }
362 +
              },
363 +
              "contentName": "entity.name.tag.yaml",
364 +
              "end": "(?=\\s*$|\\s+#|\\s*:(\\s|$)|\\s*:[],\\[{}]|\\s*[],\\[{}])",
365 +
              "name": "string.unquoted.plain.in.yaml"
366 +
            }
367 +
          ]
368 +
        },
369 +
        {
370 +
          "include": "#flow-node"
371 +
        },
372 +
        {
373 +
          "begin": ":(?=\\s|$|[],\\[{}])",
374 +
          "captures": {
375 +
            "0": {
376 +
              "name": "punctuation.separator.key-value.mapping.yaml"
377 +
            }
378 +
          },
379 +
          "end": "(?=[],}])",
380 +
          "name": "meta.flow-pair.yaml",
381 +
          "patterns": [
382 +
            {
383 +
              "include": "#flow-value"
384 +
            }
385 +
          ]
386 +
        }
387 +
      ]
388 +
    },
389 +
    "flow-scalar": {
390 +
      "patterns": [
391 +
        {
392 +
          "include": "#flow-scalar-double-quoted"
393 +
        },
394 +
        {
395 +
          "include": "#flow-scalar-single-quoted"
396 +
        },
397 +
        {
398 +
          "include": "#flow-scalar-plain-in"
399 +
        }
400 +
      ]
401 +
    },
402 +
    "flow-scalar-double-quoted": {
403 +
      "begin": "\"",
404 +
      "beginCaptures": {
405 +
        "0": {
406 +
          "name": "punctuation.definition.string.begin.yaml"
407 +
        }
408 +
      },
409 +
      "end": "\"",
410 +
      "endCaptures": {
411 +
        "0": {
412 +
          "name": "punctuation.definition.string.end.yaml"
413 +
        }
414 +
      },
415 +
      "name": "string.quoted.double.yaml",
416 +
      "patterns": [
417 +
        {
418 +
          "match": "\\\\([ \"/0LN\\\\_abefnprtv]|x\\d\\d|u\\d{4}|U\\d{8})",
419 +
          "name": "constant.character.escape.yaml"
420 +
        },
421 +
        {
422 +
          "match": "\\\\\\n",
423 +
          "name": "constant.character.escape.double-quoted.newline.yaml"
424 +
        }
425 +
      ]
426 +
    },
427 +
    "flow-scalar-plain-in": {
428 +
      "patterns": [
429 +
        {
430 +
          "include": "#flow-scalar-plain-in-implicit-type"
431 +
        },
432 +
        {
433 +
          "begin": "[^-\\]!\"#%\\&'*,:>?@\\[`{|}\\s]|[-:?][^],\\[{}\\s]",
434 +
          "end": "(?=\\s*$|\\s+#|\\s*:(\\s|$)|\\s*:[],\\[{}]|\\s*[],\\[{}])",
435 +
          "name": "string.unquoted.plain.in.yaml"
436 +
        }
437 +
      ]
438 +
    },
439 +
    "flow-scalar-plain-in-implicit-type": {
440 +
      "patterns": [
441 +
        {
442 +
          "captures": {
443 +
            "1": {
444 +
              "name": "constant.language.null.yaml"
445 +
            },
446 +
            "2": {
447 +
              "name": "constant.language.boolean.yaml"
448 +
            },
449 +
            "3": {
450 +
              "name": "constant.numeric.integer.yaml"
451 +
            },
452 +
            "4": {
453 +
              "name": "constant.numeric.float.yaml"
454 +
            },
455 +
            "5": {
456 +
              "name": "constant.other.timestamp.yaml"
457 +
            },
458 +
            "6": {
459 +
              "name": "constant.language.value.yaml"
460 +
            },
461 +
            "7": {
462 +
              "name": "constant.language.merge.yaml"
463 +
            }
464 +
          },
465 +
          "match": "(?:(null|Null|NULL|~)|([Yy]|yes|Yes|YES|[Nn]|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)|([-+]?0b[01_]+|[-+]?0[0-7_]+|[-+]?(?:0|[1-9][0-9_]*)|[-+]?0x[_\\h]+|[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)|([-+]?(?:[0-9][0-9_]*)?\\.[.0-9]*(?:[Ee][-+][0-9]+)?|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))|(\\d{4}-\\d{2}-\\d{2}|\\d{4}-\\d{1,2}-\\d{1,2}(?:[Tt]|[\\t ]+)\\d{1,2}:\\d{2}:\\d{2}(?:\\.\\d*)?(?:[\\t ]*Z|[-+]\\d{1,2}(?::\\d{1,2})?)?)|(=)|(<<))(?=\\s*$|\\s+#|\\s*:(\\s|$)|\\s*:[],\\[{}]|\\s*[],\\[{}])"
466 +
        }
467 +
      ]
468 +
    },
469 +
    "flow-scalar-plain-out": {
470 +
      "patterns": [
471 +
        {
472 +
          "include": "#flow-scalar-plain-out-implicit-type"
473 +
        },
474 +
        {
475 +
          "begin": "[^-\\]!\"#%\\&'*,:>?@\\[`{|}\\s]|[-:?]\\S",
476 +
          "end": "(?=\\s*$|\\s+#|\\s*:(\\s|$))",
477 +
          "name": "string.unquoted.plain.out.yaml"
478 +
        }
479 +
      ]
480 +
    },
481 +
    "flow-scalar-plain-out-implicit-type": {
482 +
      "patterns": [
483 +
        {
484 +
          "captures": {
485 +
            "1": {
486 +
              "name": "constant.language.null.yaml"
487 +
            },
488 +
            "2": {
489 +
              "name": "constant.language.boolean.yaml"
490 +
            },
491 +
            "3": {
492 +
              "name": "constant.numeric.integer.yaml"
493 +
            },
494 +
            "4": {
495 +
              "name": "constant.numeric.float.yaml"
496 +
            },
497 +
            "5": {
498 +
              "name": "constant.other.timestamp.yaml"
499 +
            },
500 +
            "6": {
501 +
              "name": "constant.language.value.yaml"
502 +
            },
503 +
            "7": {
504 +
              "name": "constant.language.merge.yaml"
505 +
            }
506 +
          },
507 +
          "match": "(?:(null|Null|NULL|~)|([Yy]|yes|Yes|YES|[Nn]|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)|([-+]?0b[01_]+|[-+]?0[0-7_]+|[-+]?(?:0|[1-9][0-9_]*)|[-+]?0x[_\\h]+|[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)|([-+]?(?:[0-9][0-9_]*)?\\.[.0-9]*(?:[Ee][-+][0-9]+)?|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))|(\\d{4}-\\d{2}-\\d{2}|\\d{4}-\\d{1,2}-\\d{1,2}(?:[Tt]|[\\t ]+)\\d{1,2}:\\d{2}:\\d{2}(?:\\.\\d*)?(?:[\\t ]*Z|[-+]\\d{1,2}(?::\\d{1,2})?)?)|(=)|(<<))(?=\\s*$|\\s+#|\\s*:(\\s|$))"
508 +
        }
509 +
      ]
510 +
    },
511 +
    "flow-scalar-single-quoted": {
512 +
      "begin": "'",
513 +
      "beginCaptures": {
514 +
        "0": {
515 +
          "name": "punctuation.definition.string.begin.yaml"
516 +
        }
517 +
      },
518 +
      "end": "'(?!')",
519 +
      "endCaptures": {
520 +
        "0": {
521 +
          "name": "punctuation.definition.string.end.yaml"
522 +
        }
523 +
      },
524 +
      "name": "string.quoted.single.yaml",
525 +
      "patterns": [
526 +
        {
527 +
          "match": "''",
528 +
          "name": "constant.character.escape.single-quoted.yaml"
529 +
        }
530 +
      ]
531 +
    },
532 +
    "flow-sequence": {
533 +
      "begin": "\\[",
534 +
      "beginCaptures": {
535 +
        "0": {
536 +
          "name": "punctuation.definition.sequence.begin.yaml"
537 +
        }
538 +
      },
539 +
      "end": "]",
540 +
      "endCaptures": {
541 +
        "0": {
542 +
          "name": "punctuation.definition.sequence.end.yaml"
543 +
        }
544 +
      },
545 +
      "name": "meta.flow-sequence.yaml",
546 +
      "patterns": [
547 +
        {
548 +
          "include": "#prototype"
549 +
        },
550 +
        {
551 +
          "match": ",",
552 +
          "name": "punctuation.separator.sequence.yaml"
553 +
        },
554 +
        {
555 +
          "include": "#flow-pair"
556 +
        },
557 +
        {
558 +
          "include": "#flow-node"
559 +
        }
560 +
      ]
561 +
    },
562 +
    "flow-value": {
563 +
      "patterns": [
564 +
        {
565 +
          "begin": "\\G(?![],}])",
566 +
          "end": "(?=[],}])",
567 +
          "name": "meta.flow-pair.value.yaml",
568 +
          "patterns": [
569 +
            {
570 +
              "include": "#flow-node"
571 +
            }
572 +
          ]
573 +
        }
574 +
      ]
575 +
    },
576 +
    "node": {
577 +
      "patterns": [
578 +
        {
579 +
          "include": "#block-node"
580 +
        }
581 +
      ]
582 +
    },
583 +
    "property": {
584 +
      "begin": "(?=[!\\&])",
585 +
      "end": "(?!\\G)",
586 +
      "name": "meta.property.yaml",
587 +
      "patterns": [
588 +
        {
589 +
          "captures": {
590 +
            "1": {
591 +
              "name": "keyword.control.property.anchor.yaml"
592 +
            },
593 +
            "2": {
594 +
              "name": "punctuation.definition.anchor.yaml"
595 +
            },
596 +
            "3": {
597 +
              "name": "entity.name.type.anchor.yaml"
598 +
            },
599 +
            "4": {
600 +
              "name": "invalid.illegal.character.anchor.yaml"
601 +
            }
602 +
          },
603 +
          "match": "\\G((&))([^],/\\[{}\\s]+)(\\S+)?"
604 +
        },
605 +
        {
606 +
          "match": "\\G!(?:<(?:%\\h{2}|[]!#$\\&-;=?-\\[_a-z~])+>|(?:[-0-9A-Za-z]*!)?(?:%\\h{2}|[#$\\&-+\\--;=?-Z_a-z~])+|)(?=[\\t ]|$)",
607 +
          "name": "storage.type.tag-handle.yaml"
608 +
        },
609 +
        {
610 +
          "match": "\\S+",
611 +
          "name": "invalid.illegal.tag-handle.yaml"
612 +
        }
613 +
      ]
614 +
    },
615 +
    "prototype": {
616 +
      "patterns": [
617 +
        {
618 +
          "include": "#comment"
619 +
        },
620 +
        {
621 +
          "include": "#property"
622 +
        }
623 +
      ]
624 +
    }
625 +
  },
626 +
  "scopeName": "source.yaml"
627 +
}
crates/highlight/tests/syntaxes.rs +29 -0
18 18
        syntaxes::MARKDOWN,
19 19
        syntaxes::PYTHON,
20 20
        syntaxes::RUBY,
21 21
        syntaxes::RUST,
22 22
        syntaxes::SHELL,
23 +
        syntaxes::TOML,
23 24
        syntaxes::TYPESCRIPT,
25 +
        syntaxes::YAML,
24 26
    ] {
25 27
        Grammar::from_str(source).unwrap();
26 28
    }
27 29
}
28 30
130 132
    assert!(scopes.contains(&"meta.function.url.css"));
131 133
    assert!(scopes.contains(&"meta.function.color.css"));
132 134
    assert!(scopes.contains(&"constant.other.color.rgb-value.hex.css"));
133 135
}
134 136
137 +
#[test]
138 +
fn toml_highlights_keys_sections_strings_and_booleans() {
139 +
    let grammar = Grammar::from_str(syntaxes::TOML).unwrap();
140 +
    let section_scopes = tokenize_scopes(&grammar, "[package]");
141 +
    let value_scopes = tokenize_scopes(&grammar, "name = \"rustik\"");
142 +
    let boolean_scopes = tokenize_scopes(&grammar, "publish = false");
143 +
144 +
    assert!(section_scopes.contains(&"entity.name.section.toml"));
145 +
    assert!(value_scopes.contains(&"variable.other.key.toml"));
146 +
    assert!(value_scopes.contains(&"punctuation.separator.key-value.toml"));
147 +
    assert!(value_scopes.contains(&"string.quoted.double.toml"));
148 +
    assert!(boolean_scopes.contains(&"constant.language.boolean.toml"));
149 +
}
150 +
151 +
#[test]
152 +
fn yaml_highlights_keys_scalars_and_comments() {
153 +
    let grammar = Grammar::from_str(syntaxes::YAML).unwrap();
154 +
    let key_scopes = tokenize_scopes(&grammar, "name: rustik");
155 +
    let scalar_scopes = tokenize_scopes(&grammar, "name: \"rustik\"");
156 +
    let comment_scopes = tokenize_scopes(&grammar, "# generated");
157 +
158 +
    assert!(key_scopes.contains(&"entity.name.tag.yaml"));
159 +
    assert!(key_scopes.contains(&"punctuation.separator.key-value.mapping.yaml"));
160 +
    assert!(scalar_scopes.contains(&"string.quoted.double.yaml"));
161 +
    assert!(comment_scopes.contains(&"comment.line.number-sign.yaml"));
162 +
}
163 +
135 164
/// Tokenizes `line` and returns its scope names.
136 165
fn tokenize_scopes<'a>(grammar: &'a Grammar, line: &str) -> Vec<&'a str> {
137 166
    let mut state = LineState::default();
138 167
    let mut tokenizer = LineTokenizer::new(grammar);
139 168
    let spans = tokenizer.tokenize_line(&mut state, line);