feat(diagnostics): token and rule labels for expected-X messages - #73
Open
theoephraim wants to merge 1 commit into
Open
feat(diagnostics): token and rule labels for expected-X messages#73theoephraim wants to merge 1 commit into
theoephraim wants to merge 1 commit into
Conversation
The emitted engine's $missing diagnostics name what was missing by its
grammar name: a token NUM reads as "expected 'NUM'", a rule Value as
"expected Value". For a language whose grammar names are internal
identifiers (DEC_VALUE_TEXT) that text leaks straight to editor users.
token(pattern, { label }) and rule(fn, { label }) substitute a display
string in exactly those messages and nowhere else: leaf tokenTypes,
ruleNameOf, the CST, and every derived artifact keep the grammar name,
so a grammar that adds labels parses byte-identically. A labelled token
renders bare (expected a number); an unlabelled one keeps the quoted
name, so existing output is unchanged.
Gate: test/diagnostic-labels.ts (tiny grammar plus TypeScript's Expr
rule relabelled, tree identity across labels).
theoephraim
force-pushed
the
feat/diagnostic-labels
branch
from
September 8, 2026 04:51
6a143a7 to
95dd7f3
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Token and rule labels for
expected …diagnosticsThe emitted engine's
$missingdiagnostics name what was missing by its grammar name: a tokenNUMreads asexpected 'NUM', a ruleValueasexpected Value. That is fine when grammar names are already words (Expr), and leaks internal identifiers to end users otherwise. We hit it porting env-spec (the dotenv dialect behind varlock): its tokens are things likeDEC_VALUE_TEXT, and those names would be the text an editor shows on every keystroke.token(pattern, { label: 'a number' })andrule(fn, { label: 'an expression' })substitute a display string in exactly those messages and nowhere else. LeaftokenTypes,ruleNameOf, the CST, and every derived artifact keep the grammar name, so a grammar that adds labels parses byte-identically. A labelled token renders bare (expected a number); an unlabelled one keeps the quoted grammar name, so existing output is unchanged (the emitted tables gainRULE_LABELSandK_LABELSnext toRULE_DISPLAYandK_NAMES;RULE_DISPLAYstill drives node names).Gate:
test/diagnostic-labels.ts(registered incore). It covers the tiny-grammar token case, TypeScript'sExprrule relabelled (const a = ;readsexpected an expression), tree identity across labels, the TextMate, tree-sitter, and language-configuration outputs byte-identical across labels, literal messages and related info unchanged, and the interpreter unaffected (it has no expected-X diagnostics). README gets one paragraph.npm run check: 50/50.