Repository navigation
parser: separate forms with ; instead of , - #130
Merged
Merged
Conversation
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]>
Deploying dang with
|
| Latest commit: |
ba9497d
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://d704cd5c.dang-3kk.pages.dev |
| Branch Preview URL: | https://block-semicolon-separator.dang-3kk.pages.dev |
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]>
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]>
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.
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:A new user may have expected this to do
let a = 1, b = 2-- declaring both within the block. But that actually reassigns the outerb, which is a very subtle footgun.Following this change, if a user makes the same assumption, they'll write this instead:
Which will be a parse error, leading to this fix:
(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:
Bot-written below:
Zed compatibility test
editors/zed/extension.tomlpins the Zed grammar to a dang commit that predatessemi_token, so the in-repo highlight query is briefly ahead of the published grammar. Rather than fail on that release-ordering gap,TestZedHighlightQueryCompatibilitynow 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 definessemi_tokenreactivates 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).