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 Edge::label from optional to required #1205

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

Conversation

mjoerussell
Copy link
Contributor

@mjoerussell mjoerussell commented Dec 30, 2024

This involves a couple of changes outside of just changing the field type:

  1. CursorIterator must be able to produce a label for every node now. This wasn't possible before because the root nodes of a cursor had no parent, and so could not derive a label. I've changed Cursor in the following ways to fix this:
    • Cursor::parent is a new type, Parent<T>, instead of Option<Rc<PathAncestor<T>>>. Parent<T> is an enum with three variants - None, Open(Rc<PathAncestor<T>>), and Closed(Rc<PathAncestor<T>>). A Closed parent is used when a cursor is spawned from an arbitrary non-root node, and means that the parent can be read but not traversed to. None is only used for the true root node.
  2. KindTypes::EdgeLabel is given a Default implementation, which for now just returns the first PredefinedLabel variant. This is needed in order to be able to set a "concrete" EdgeLabel value from the metaslang_cst crate.
  3. Added a Root variant to PredefinedLabel. This will be used when a node is the true root node. For now this will be the default value for KindTypes::EdgeLabel.

Closes #815

This involves a couple of changes outside of just changing the field type:
1. `CursorIterator` must be able to produce a label for every node now. This wasn't possible before because the root nodes of a cursor had no parent, and so could not derive a label. I've changed `Cursor` in the following ways to fix this:
    * `Cursor::parent` is a new type, `Parent<T>`, instead of `Option<Rc<PathAncestor<T>>>`. `Parent<T>` is an enum with three variants - `None`, `Open(Rc<PathAncestor<T>>)`, and `Closed(Rc<PathAncestor<T>>)`. A `Closed` parent is used when a cursor is spawned from an arbitrary non-root node, and means that the parent can be read but not traversed to. `None` is only used for the true root node.
2. `KindTypes::EdgeLabel` is given a `Default` implementation, which for now just returns the first `PredefinedLabel` variant. This is needed in order to be able to set a "concrete" `EdgeLabel` value from the `metaslang_cst` crate.
3. Added a `Root` variant to `PredefinedLabel`. This will be used when a node is the true root node. For now this will be the default value for `KindTypes::EdgeLabel`.
@mjoerussell mjoerussell self-assigned this Dec 30, 2024
@mjoerussell mjoerussell requested review from a team as code owners December 30, 2024 21:26
Copy link

changeset-bot bot commented Dec 30, 2024

🦋 Changeset detected

Latest commit: 8515650

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@nomicfoundation/slang Patch

Not sure what this means? Click here to learn what changesets are.

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

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.

Thanks for working on this!

@@ -27,7 +27,7 @@ Tree:
- (for_keyword꞉ ForKeyword): "for" # (0..3)
- (open_paren꞉ OpenParen): "(" # (3..4)
- (initialization꞉ ForStatementInitialization) ► (variant꞉ VariableDeclarationStatement) ► (variable_type꞉ VariableDeclarationType) ► (variant꞉ TypeName) ► (variant꞉ ElementaryType) ► (variant꞉ IntKeyword): "int" # (4..7)
- (MISSING): "" # (7..7)
- (root꞉ MISSING): "" # (7..7)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we are missing labels for MISSING nodes. I wonder if we are able to use the original label the parser was trying to parse, to indicate what is missing?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an Unrecognized label for UNRECOGNIZED nodes. However, getting the correct label for MISSING nodes was not that straightforward, at least for how well I currently understand the parser. For now, I've left those as having the label Root. @OmarTawfik if you have any thoughts about how to get those labels, I'd be happy to go back and make those updates.

I see. Thanks for the update. This looks like it needs a bigger refactoring the parser codegen, and I don't think it should block this PR/fix.
So, for the time being, WDYT of adding a similar EdgeLabel::MISSING for now, so that we don't mislabel them as root in the meantime?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created #1215 to track this, and added it to the backlog for now.

@mjoerussell
Copy link
Contributor Author

looks like we are missing labels for UNRECOGNIZED nodes. Should we add a matching EdgeLabel::UNRECOGNIZED for these? thoughts?

looks like we are missing labels for MISSING nodes. I wonder if we are able to use the original label the parser was trying to parse, to indicate what is missing?

I've added an Unrecognized label for UNRECOGNIZED nodes. However, getting the correct label for MISSING nodes was not that straightforward, at least for how well I currently understand the parser. For now, I've left those as having the label Root. @OmarTawfik if you have any thoughts about how to get those labels, I'd be happy to go back and make those updates.

All the other comments should be addressed now so this PR is ready for another review.

@mjoerussell mjoerussell requested a review from OmarTawfik January 3, 2025 21:59
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.

Made another pass on all unresoved comments.
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.

I think there is one unresolved comment still: #1205 (comment)

So, for the time being, WDYT of adding a similar EdgeLabel::MISSING for now, so that we don't mislabel them as root in the meantime?

Additionally, I suggest adding a changeset to describe the changes here.

Thanks!

@mjoerussell
Copy link
Contributor Author

I think there is one unresolved comment still: #1205 (comment)

Wasn't that added to the backlog as #1215? I thought that that was going to be resolved in the future.

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.

make EdgeLabel required in the CST
2 participants