-
Notifications
You must be signed in to change notification settings - Fork 19
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
make FieldName
required in the CST
#815
Comments
The ability to have un-named nodes is critical to the query system! |
I'm also in the camp of having the names optional. If it's all about |
I really think we should make it required everywhere. From an API perspective, if i'm iterating on children, or even filtering/inspecting a specific child, I should be able to read/know its name, and it should be strongly typed, and finite/matchable. All such is provided by the Re: the query system: I think the fact that something has a name or not shouldn't interfere with the querying system, as they are independent, and can actually be confusing in some cases, like the But we also discussed the cost of adding a side channel to record such information, and it is not clear whether it is worth doing now. |
Another idea: we might not need a side channel after all, if we can derive this info from existing node kinds (example below). We would need to use #808 to see if this affects query engine performance: fn is_node_contentful(parent_kind: &RuleKind, child_kind: &TokenKind) -> bool {
match (parent_kind, child_kind) {
// for `StructItem`, add children that appear in `terminated_by`/`delimited_by`:
(RuleKind::Statement, TokenKind::Semicolon) => false,
(RuleKind::Block, TokenKind::LeftCurly | TokenKind::RightCurly) => false,
// .....
// For `Separated`, add the `separator`:
(RuleKind::Arguments, TokenKind::Comma) => false,
(RuleKind::Parameters, TokenKind::Comma) => false,
// .....
// Also trivia:
(_, TokenKind::Whitespace | TokenKind::Newline | TokenKind::Comment) => false,
// otherwise, contentful:
_ => true,
}
} |
Let's defer this until we have more experience/feedback on the API. |
Making this a required property for all nodes (replacing the
Option<T>
) makes it much easier to handle/match in client code.FieldName::Item
andFieldName::Separator
forSeparatedItem
children.FieldName::Item
forRepeatedItem
children.FieldName::LeadingTrivia
andFieldName::TrailingTrivia
for children ofLeadingTrivia
andTrailingTrivia
.The text was updated successfully, but these errors were encountered: