Retrieving the underlying source text

24 views
Skip to first unread message

Niels Basjes

unread,
Jul 6, 2016, 8:33:32 AM7/6/16
to antlr-discussion
Hi,

I wrote a parser ( https://github.com/nielsbasjes/yauaa ) and when I simply skip the spaces in my lexer the getText() method no longer includes these skipped tokens.
Effectively the input string "foo  bar" is output as "foobar" by getText.

So for my project (where in some cases I need the original including the spaces) I wrote a getSourceText function that retrieves the substring of the underlying source instead of concatenating the parsed tokens (like getText() does).

As a test I implemented this first in my project 

And to see if it would be a usable fit I implemented it as a new method in antlr4 itself.

Now before I put effort into writing tests and ensuring the code is clean: 

Is this an enhancement that is desirable in ANTLR?
Or is this a call that should not go into ANTLR a be a part of the specific application?

Niels Basjes


Reply all
Reply to author
Forward
0 new messages