-
-
Notifications
You must be signed in to change notification settings - Fork 535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ungrammar, codegen, css_parser): support "dynamic" unordered node fields #1438
Conversation
✅ Deploy Preview for biomejs canceled.
|
Parser conformance results onjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
Some(CombinatorKind::DoublePipe) => Rule::UnorderedSome(rules), | ||
Some(CombinatorKind::Pipe) => Rule::Alt(rules), | ||
None | Some(CombinatorKind::NonCombinator) => { | ||
unreachable!("Matched more than one rule but didn't determine a combinator") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should we do in case we mistakenly reach this code path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be genuinely unreachable, since we break out of the loop before parsing a second rule if we encounter a non-combinator, and we also bail the parse entirely if we encounter mixed combinators, so I think this is safe as-is. Reaching this state would mean there's both a bug in the parsing logic above it and an unexpected input.
5642944
to
e890ec5
Compare
Summary
This PR implements the idea behind #1407, which is the ability to define, parse, represent, and interact with unordered fields on a node.
Without repeating too much of that discussion, the idea is that the grammar can define a set of fields that are unordered: each field can appear at most once in the node, but they can appear in any order in the set. In an AST, this is simple, but in a CST we need to be able to map the access for a specific field into the ordered, linear stream of tokens and nodes of the untyped syntax tree.
To do this,
AstNode
s with one or more unordered fields also include aslot_map
member that maps a defined slot index (the index of the field in the grammar) to a concrete index (the index of the field in the source code token stream). When converting from an untyped node to a typed node, the constructor builds the slot map by comparing the children against the specified grammar and assigning the slots. This also happens when up-casting the raw token stream to theSyntaxNode
, but only for validation and filling empty slots to ensure missing and required empties are filled.Test Plan
There's nothing that uses this yet, but I made a sample grammar with unordered nodes, ran codegen, and tested a parse result that you can see in this commit.