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

Retrieve / check the direct ancestor of a binding #355

Open
morgante opened this issue May 26, 2024 · 0 comments
Open

Retrieve / check the direct ancestor of a binding #355

morgante opened this issue May 26, 2024 · 0 comments

Comments

@morgante
Copy link
Contributor

morgante commented May 26, 2024

Ideally, there would be an easy way to directly check the parent of a node against a pattern. Within is not quite sufficient, since it traverses upwards forever.

Use cases

  • Confirming the direct parent of a statement is the program itself here

Possible approach: built-in parent function

New parent($node) built in that retrieves the parent of a node.

Reusing within

We could allow within to take a modifier, determining how far it would traverse upwards.

Ex. this would make sure a const is directly within a specific parent:

`const $x;` as $match where $match <: within(1) statement_block()

This could be used to implement a parent function in user space:

function parent($pattern) {
   $pattern <: within(1) $parent,
   return $parent
}
@morgante morgante changed the title parent built-in Retrieve / check the direct ancestor of a binding May 26, 2024
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

No branches or pull requests

1 participant