Skip to main content

Module syntax

Module syntax 

Source
Expand description

The TypR syntax manifest — the single source of truth for every lexeme the language colors.

§Why this module exists

Before it, the same syntax was written down six times by hand (the parser here, VSCode’s typr.tmLanguage.json, the Playground’s Monarch rules, the Docusaurus Prism rules, editors/vim/syntax/typr.vim, and the LSP’s semantic tokens) and the copies had already drifted apart: the editor grammars colored impl/trait/struct/enum/where/mut/Option/ Result — Rust keywords copy-pasted in that TypR has never had — while opaque, module, record, object, interface, typeconstructor, recursive, embed, @export and the kind sigils were colored nowhere.

TextMate (VSCode/Positron/Shiki/Monaco) and tree-sitter (Neovim/Helix/Zed) do not convert into one another, so the source of truth has to sit one level above any grammar format: a plain data description of the lexemes, from which each target grammar is generated. That is this manifest. typr syntax (typr-cli) serializes it and renders the targets.

§Consumers

editors/vscode/syntaxes/typr.tmLanguage.json is the only artifact rendered today, and it feeds four targets: the VSCode/Positron extension, the playground (Shiki → Monaco, src/lib/monaco-typr.ts), the Docusaurus documentation (@shikijs/rehype, src/syntax/shiki.ts) and — the day TypR clears Linguist’s 2000-file bar — GitHub. Both sites keep a copy under syntaxes/, pushed there by the release’s grammar job; it is not hand-edited, and their CI warns when it drifts. Both read the grammar with Shiki’s JavaScript regex engine rather than Oniguruma, which is why RuleBody::Match sticks to a dialect both engines accept.

§Invariant

Every word-like literal the parser matches with tag("…") must appear in this manifest. tests::every_parser_tag_is_in_the_manifest reads the parser sources with include_str! and fails the build when one is missing, so adding a keyword to the grammar without teaching the editors about it is a test failure rather than a silent divergence.

Structs§

Language
Identity of the language, for the target grammars’ preamble.
Rule
One highlighting rule: a named bucket of lexemes plus the scope the targets should paint them with.
Sigil
A kind sigil (RFC ai_context/sigils.md §3.2.1), prefixed to a single-uppercase-letter generic to fix its kind: #N, %R, @T, ^S, ?B, $L.
SyntaxManifest

Enums§

RuleBody
What a rule matches. Ordering of SyntaxManifest::rules is significant: earlier rules win, in every target format.

Constants§

SCHEMA_VERSION
Bumped whenever the shape of the serialized manifest changes in a way a consumer (a generator, a downstream editor plugin) has to notice.