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

Support for node traversal and matching #65

Open
jonathanhogg opened this issue Dec 18, 2024 · 2 comments
Open

Support for node traversal and matching #65

jonathanhogg opened this issue Dec 18, 2024 · 2 comments
Labels
🚀 enhancement New feature or request 💡 idea A hair-brained concept 💬 language Anything to do with the parser/evaluator/VM 🧱 model Anything to do with the underlying graph/value model

Comments

@jonathanhogg
Copy link
Owner

Since I ditched queries, I haven't revisited the idea of manipulating a node tree. However, since I have recursive functions now, rewriting a tree ought to be a simpler operation. What's missing is:

  • iterating over the children of a node
  • matching on a node kind, tags or attributes
  • retrieving the value of a node attribute

An additional nice to have would be:

  • syntax for binding a name to a tree

Adding these operations would allow for manipulating trees, but also allow nodes to be used as arbitrary data structures.

@jonathanhogg jonathanhogg added 🚀 enhancement New feature or request 💡 idea A hair-brained concept 💬 language Anything to do with the parser/evaluator/VM 🧱 model Anything to do with the underlying graph/value model labels Dec 18, 2024
@jonathanhogg
Copy link
Owner Author

jonathanhogg commented Dec 18, 2024

Could start off with a bunch of functions for deconstructing nodes:

  • kind( node ) - return the kind of the node as a symbol
  • children( node ) – return concatenated children of all nodes in the node vector
  • tags( node ) - return the tags of a node as a vector of symbols
  • attributes( node ) - return the attributes of a node (in order) as a vector of symbols
  • getattr( node , attr ) - return the value of a node attribute, specified as a symbol or string

And new functions for constructing nodes:

  • new( kind ) - create a new node with kind kind, specified as a symbol or string
  • tag( node , tag ) - return copy of node with the addition of tag tag (symbol or string)
  • setattr( node , attr , value ) - return copy of node with attr (symbol or string) set to value (null to remove attribute)
  • append( node , child ) - return copy of node with child appended

With these, and a new method for checking whether an item is in a vector, that would be enough to do basic matching and reconstruction.

Could see if this is useful for a while and then figure out whether there are particular patterns that merit new grammar.

@jonathanhogg
Copy link
Owner Author

One thing that probably would be worth adding new grammar for is a vector search operation, a la:

item in vector – return true or false as to whether item is contained within vector

For consistency this should accept an n-vector for item and should look for whether all of those items appear consecutively in vector.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🚀 enhancement New feature or request 💡 idea A hair-brained concept 💬 language Anything to do with the parser/evaluator/VM 🧱 model Anything to do with the underlying graph/value model
Projects
None yet
Development

No branches or pull requests

1 participant