chevrotain
chevrotain copied to clipboard
Expose API to get the current CSTNode
Lets say we want to modify the CSTNode being created.
For Example:
$.RULE("array", () => {
const from = this.currIdx
$.CONSUME(LSquare)
// ...
$.CONSUME(RSquare)
const to = this.currIdx
// Ugly way to access the current CSTNode using internal APIs
this.CST_STACK[this.CST_STACK.length - 1].tokVectorRange = {
from: from,
to: to
}
})
It seems there should be a better way to access the current CSTNode.
Both in terms of being documented on the public API and in terms of conciseness.
Perhaps something like this.currCSTNode
or maybe just this.currNode
Tasks
- [ ] Expose relevant method on the tree builder parser trait.
- [ ] Document the new API in api.d.ts CstParser class.
- [ ] Should there be special handling if this API is called from an EmbeddedActionsParser? - e.g throw an error?
- [ ] Tests and 100% Coverage.
- [ ] Create small example in examples/parser for this scenario.
- [ ] Update CST Guide Docs on the website (also link above example).
Thanks for helping @drayavannie, lets track everything in this single issue?