Open drewdaemon opened 2 months ago
Pinging @elastic/kibana-esql (Team:ESQL)
It would be great to use these walker APIs in our own validation engine as well.
I agree that this looks very useful, but I think its something that might live inside a more opinionated service that takes the whole ESQL string and provides getters and mutators.
@mattkime I think I get what you're saying, but I think a couple examples of how you would use the opinionated service to accomplish a given task would be helpful here. One recent task we had was adding a new where
clause if it doesn't exist, or edit it if it does. How would you accomplish this with the service you're envisioning? What would the getters
and mutators
look like?
There is an initial implementation of the Walker
now available, it is missing:
option
nodes@vadimkibana also a Readme (documentation) when this is more mature would be very nice too.
We may also want to consider giving the user more control over the traversal. Recast does this with this.traverse()
, this.abort()
, and return false;
Acorn AST walker for inspiration: https://github.com/acornjs/acorn/tree/master/acorn-walk
Finding things in an AST (and possibly changing them) requires a tree-traversal algorithm. Developers working with ES|QL queries shouldn't have to worry about implementing this themselves. Instead, we should provide a nice API.
Ideas
Or maybe
Or for manipulation, something like
Could also provide typed shortcut methods like
Each of those could return typed AST nodes, removing the need for consumers to run their own type checks.
Or we could implement a visitor like recast's
Some comparables
Some potential adoption points