Skip to content

parser: separate forms with ; instead of , - #130

Merged
vito merged 9 commits into
mainfrom
block-semicolon-separator
Jun 15, 2026
Merged

vito merged 9 commits into
mainfrom
block-semicolon-separator

Conversation

@vito

@vito vito commented Jun 14, 2026 •

Copy link
Copy Markdown
Owner

Blocks and files now separate forms with ; or a newline, while keeping commas for collections and arugment lists.

The motivation here is familiarity and ergonomics. Using ; is more common in this way, and prevents the following footgun:

let b = 99
let result = { let a = 1, b = 2, a + b }

A new user may have expected this to do let a = 1, b = 2 -- declaring both within the block. But that actually reassigns the outer b, which is a very subtle footgun.

Following this change, if a user makes the same assumption, they'll write this instead:

let b = 99
let result = { let a = 1, b = 2; a + b }

Which will be a parse error, leading to this fix:

let b = 99
let result = { let a = 1; let b = 2; a + b }

(Alternatively, maybe someday we permit declaring multiple vars in one go, but I'm not sure it's a clean fit, so not doing it now.)

Now, sure, it's still possible to write the same broken code as before, but it seems more obvious what it's doing, and this code is a perfectly reasonable thing to do when it's intentional:

let b = 99
let result = { let a = 1; b = 2; a + b }

Bot-written below:


Zed compatibility test

editors/zed/extension.toml pins the Zed grammar to a dang commit that predates semi_token, so the in-repo highlight query is briefly ahead of the published grammar. Rather than fail on that release-ordering gap, TestZedHighlightQueryCompatibility now cross-checks the query against the current grammar first: a node missing there is a genuine bug (typo / stale name) and still fails, and the test only skips when a node is valid in the current grammar but absent from the pinned one. Bumping the pin to a grammar that defines semi_token reactivates the full test automatically — the only post-merge follow-up.

Testing

Full suite green across both modules and the tree-sitter corpus (with the one intentional self-skip above).

vito added 7 commits June 14, 2026 14:19
Statements in blocks, block-argument bodies, and the file top level are
now separated by ; (or a newline) through a new StmtSep rule, while
commas remain the separator for collection and argument lists. The split
mirrors the existing code/data brace distinction (single-brace { } for
code, {{ }} for data) and matches the usual convention of ; between
statements.

The previous single Sep rule allowed a comma between statements, which
let a stray comma in a block silently parse a following bare assignment
as a reassignment of an outer binding instead of a local declaration.
That mistake is now a syntax error.

Regenerates the pigeon parser and the tree-sitter grammar derived from
the same .peg, refreshes the affected corpus snapshots, and updates the
test fixtures that separated block statements with commas.

Signed-off-by: Alex Suraci <[email protected]>
When a block renders on a single line, separate its forms with "; "
rather than ", " so the formatter's output parses under the new
statement separator. Multi-line blocks are unaffected; they already
separate forms with newlines.

Signed-off-by: Alex Suraci <[email protected]>
Offer no completions when the cursor sits within string-literal content.
Error recovery on an unterminated string such as `f(x: "ab` leaves the
content as a loose token whose position otherwise reads as an argument or
identifier slot, so the engine would surface symbol completions inside
what is plainly a string. Template interpolation (`${...}`) is
unaffected, since its expression is not string content.

This latent bug was masked by the old block grammar's error recovery and
only surfaced once statements switched to ;.

Signed-off-by: Alex Suraci <[email protected]>
Highlight the new ; separator: add it to the VSCode delimiter class and
bump the zed and nvim submodules, whose tree-sitter queries now capture
semi_token as a punctuation delimiter.

The Zed compatibility test checks the in-repo highlights.scm against the
grammar pinned in extension.toml, which still predates semi_token. Rather
than failing on that release-ordering gap, the test now first verifies
the query against the current grammar -- a node missing there is a real
bug (typo or stale name) and still fails -- and only skips when a node is
valid in the current grammar but absent from the pinned one. Bumping the
pin to a grammar that defines the node reactivates the full test.

Signed-off-by: Alex Suraci <[email protected]>
Update the language docs to describe ; (or a newline) as the statement
separator for blocks and the top level, with commas reserved for
collection and argument lists, and fix the live snippets that separated
statements or object-body fields with commas so the docs build still
evaluates them.

Signed-off-by: Alex Suraci <[email protected]>
Reflect the new statement separator in the language skill reference: ;
(or a newline) separates statements, commas separate collection and
argument lists, and a comma between statements is now a syntax error.

Signed-off-by: Alex Suraci <[email protected]>
Recompile docs/js/tree-sitter-dang.wasm from the updated tree-sitter
grammar so the playground highlights the new ; statement separator. The
asset is committed and only changes when the grammar does.

Signed-off-by: Alex Suraci <[email protected]>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 14, 2026 •

Copy link
Copy Markdown

LuuOW

This comment was marked as spam.

Dang is expression-oriented: a block is a sequence of forms that each
evaluate, with the block's value being the last. Calling the separator
"statement" implied a statement/expression split the language doesn't
have. "Form" is the term the codebase already uses (Block.Forms, "a file
is a sequence of forms"), so the rule and the AST field now share it: ;
(or a newline) separates forms in a sequence, while Sep (comma) separates
collection and argument elements.

Regenerates the pigeon parser, the tree-sitter grammar (the node kind
becomes form_sep) and its corpus, and the playground grammar wasm, and
drops "statement" from the grammar and skill prose.

Signed-off-by: Alex Suraci <[email protected]>
@vito vito changed the title parser: separate statements with ; instead of , parser: separate forms with ; instead of , Jun 15, 2026
The separator sections (and the matching skill reference) carried prose a
reader of the current language doesn't need: "code separator"/"data
separator" labels, a bullet restating the code-vs-data split already
stated above it, a "not a terminator" caveat, and comma-contrast asides.
State the rules plainly. The skill keeps the precise error case, since an
agent reference benefits from knowing it.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito merged commit 1dea0cd into main Jun 15, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants