chevrotain icon indicating copy to clipboard operation
chevrotain copied to clipboard

Expose API to get the current CSTNode

Open bd82 opened this issue 4 years ago • 2 comments

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

bd82 avatar Sep 04 '19 16:09 bd82

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).

bd82 avatar Sep 04 '19 16:09 bd82

Thanks for helping @drayavannie, lets track everything in this single issue?

bd82 avatar Feb 06 '20 08:02 bd82