-
Notifications
You must be signed in to change notification settings - Fork 20
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
Change ParseOutput
to return a NonTerminal
instead of a Node
#1187
base: main
Are you sure you want to change the base?
Conversation
|
06692b6
to
95137a0
Compare
pub(crate) errors: Vec<ParseError>, | ||
} | ||
|
||
impl ParseOutput { | ||
pub fn tree(&self) -> Node { | ||
self.parse_tree.clone() | ||
pub fn tree(&self) -> Rc<NonterminalNode> { |
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.
TOL: I wonder why cloning by default? WDYT of returning &Rc<>
and leave cloning up to the user? This is similar to other APIs like Node::as_nonterminal()
.
I realize that Rc::clone()
is verbose, but we decided to enable a lint rule that enforces that for clarity (we can revisit this decision separately).
ParseOutput { | ||
parse_tree: tree, | ||
parse_tree: Rc::new(NonterminalNode::new(no_match.kind.unwrap(), trivia_nodes)), |
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.
if we are always unwrapping no_match.kind
, should it still be an Option<>
?
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.
NoMatch
is being used in the default()
function with None
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.
Here is an example of how it's used today:
slang/crates/codegen/runtime/generator/src/parser/codegen/precedence_parser_definition.rs
Line 45 in f257eae
// If the result won't match exactly, we return a dummy `ParserResult::no_match`, since |
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.
IIUC, in the case you mentioned, the kind is already known (nonterminal_name
). Right? Is it possible to initialize it with that expected kind, to prevent another code path from accidentally leaving a None
here?
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.
Left a couple of questions. Otherwise, LGTM!
Thanks.
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.
Left some comments above.
Solves #1184
To go on top of #1172
This has a big impact in the failing examples, which now return the expected
NonTerminal
.This was acknowledgedly coded by playing the whack-a-mole with the type system. I'm not so happy with the bunch of
Rc::clone()
that leaked out; I will consider an alternative once we settle this is what we need and there are no more pressing issues.Currently doing a full CI run locally to find what more to fix. In the meantime, I'll mark this as draft.