You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
}
The text was updated successfully, but these errors were encountered:
morgante
changed the title
parent built-in
Retrieve / check the direct ancestor of a binding
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
Possible approach: built-in
parent
functionNew
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:
This could be used to implement a
parent
function in user space:The text was updated successfully, but these errors were encountered: