Syntax Definition
Use this skill when asked to create or update a syntax definition for a named language or file format.
Goal
Create or update exactly one grammar file in the repository top-level syntaxes/ directory:
syntaxes/<Language>.sublime-syntax
Also create or update one fixture/expectations pair under tests/fixtures/syntaxes/<language>/:
<sample>.<ext><sample>.<ext>.tokens.yml
Examples:
JSON->syntaxes/JSON.sublime-syntaxTypeScript->syntaxes/TypeScript.sublime-syntaxElm->syntaxes/Elm.sublime-syntaxDockerfile->syntaxes/Dockerfile.sublime-syntax
If a matching file already exists, update it instead of creating a duplicate.
Required Constraints
- Only produce Sublime Text 3 compatible grammars.
- Do not use Sublime Text 4+ only syntax features.
- Keep the file as YAML with the usual
.sublime-syntaxstructure. - Do not write the grammar anywhere except the top-level
syntaxes/directory unless the user explicitly asks for something else. - Keep syntax regression fixtures under
tests/fixtures/syntaxes/.
When compatibility is uncertain, prefer conservative syntax features:
%YAML 1.2namefile_extensionsscopevariablescontextsmatchcapturesscopepushsetpopincludemeta_scopemeta_content_scope
Workflow
- Identify the requested language or format name.
- Inspect nearby files in
syntaxes/to match the repository's existing style and naming conventions. - Create a practical first-pass grammar with the core building blocks for that language:
- comments
- strings
- numbers
- keywords
- operators or punctuation
- identifiers
- Add one representative sample file under
tests/fixtures/syntaxes/<language>/. - Add a YAML expectations file named
<sample>.<ext>.tokens.ymlwith:buffer_path: the virtual filename used to select the syntaxexpectations: an ordered list of critical(text, scope)checks
- Run
cargo test syntaxesto test and fix issues with the generated/updated syntax.
Output guidelines
For generated/updated syntaxes
- Use a stable top-level scope such as
source.<language>ortext.<format>as appropriate. - Keep contexts readable and modular rather than over-optimizing the grammar.
- If the language details are incomplete, make the smallest reasonable set of assumptions and state them briefly.
- The resulting syntax file should be directly usable by the repository's syntax-loading code.
- Prefer correctness and compatibility over advanced grammar tricks.
For syntax fixtures
- Use critical-scope expectations only; do not snapshot every token unless the user explicitly asks for exhaustive coverage.
- The fixture should be directly usable by the repository's
scribe::Workspace.current_buffer_tokens()test harness.