I have the following token definition in my lexer defining a CharacterString (e.g. ‘abcd’):
CharacterString:
Apostrophe
(Alphanumeric)*
Apostrophe
;
Is it possible to ignore the two apostrophes to then be able to get the token string without them in the lexer (via $CharacterString.text->chars)?
I tried …
CharacterString:
Apostrophe { $channel = HIDDEN; }
(Alphanumeric)*
Apostrophe { $channel = HIDDEN; }
;
… without success… This case does not even match my string anymore (e.g. ‘oiu’ will fail in the parser – Missmatched Set Exception).
Thank you 🙂
The inline code
{$channel=HIDDEN;}affects the entireCharacterString, so you can’t do it like the way you tried.You will need to add some custom code and remove the quotes yourself. Here’s a small C demo:
and a little test function:
and the test
input.txtfile contains:If you now 1) generate the lexer and parser, 2) compile all
.csource files, and 3) runmain:you’ll see that
abc(without the quotes) is being printed to the console.