I am a bit perplexed about how to capture a quoted string in ANTLR4.
Currently, this lexer rule is not tokenizing the way I expect.
The sample string is "=\""
. I've tried lots of different ways to capture this, but I am at a loss about what I am doing incorrectly. I'd really appreciate some insights on best practices for this. Thank you so much!
ESCAPED_QUOTE : '\"';
QUOTED_STRING : '"' ( ESCAPED_QUOTE | ~('\n'|'\r') )*? '"';
There are two problems with the above rules.
'\\"'
.ESCAPED_QUOTE
rule doesn't form a token all by itself, so it should be a fragment
rule.The result of these two changes would be the following:
fragment ESCAPED_QUOTE : '\\"';
QUOTED_STRING : '"' ( ESCAPED_QUOTE | ~('\n'|'\r') )*? '"';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With