Skip to content
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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

beta-ziliani
Copy link
Contributor

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.

Copy link

changeset-bot bot commented Dec 11, 2024

⚠️ No Changeset found

Latest commit: 05d405a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@beta-ziliani beta-ziliani marked this pull request as ready for review December 16, 2024 13:57
@beta-ziliani beta-ziliani requested review from a team as code owners December 16, 2024 13:57
pub(crate) errors: Vec<ParseError>,
}

impl ParseOutput {
pub fn tree(&self) -> Node {
self.parse_tree.clone()
pub fn tree(&self) -> Rc<NonterminalNode> {
Copy link
Contributor

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)),
Copy link
Contributor

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<>?

Copy link
Contributor Author

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

Copy link
Contributor Author

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:

// If the result won't match exactly, we return a dummy `ParserResult::no_match`, since

Copy link
Contributor

@OmarTawfik OmarTawfik Dec 23, 2024

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?

Copy link
Contributor

@OmarTawfik OmarTawfik left a 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.

Copy link
Contributor

@OmarTawfik OmarTawfik left a 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.

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