ANTLR function to retrieve text from a single node in a parse tree

I want to retrieve text from a parse tree's node but when i use getText(), it retrieves all the text from that node's children. I have searched but i don't find any ANTLR function that can retrieve only the node's text or a function to delete a node's children (so that i can use getText() on that node once i have deleted his children). Any help is welcomed.

1 answer

  • answered 2022-05-06 14:51 Mike Cargal

    That would be because a “node” (and particularly, it’s text) includes it’s children. If you define it as the text that’s not part of a child, you’re left with just to tokens (leaf nodes) in that parser rule, and that’s probably a bit less than useful (some text with holes where other rules kick in).

    Maybe you have a situation where something like this would be useful. If so, you might want to elaborate. We might, then propose something more specific.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum