Is there a way in ANTLR to mark certain tokens as having canonical output?
For example, given the grammar (excerpt)
words : FOO BAR BAZ
FOO : [Ff] [Oo] [Oo]
BAR : [Bb] [Aa] [Rr]
BAZ : [Bb] [Aa] [Zz]
SP : [ ] -> channel(HIDDEN);
words will match "FOO BAR BAZ", "foo bar baz", "Foo bAr baZ", etc.
When I call TokenStream#getText(Context), it'll return the tokens' actual text concatenated together.
Is there a way to "canonicalize" this output such that no matter what the input, all FOO tokens render as "Foo", BAR tokens render as "Bar", and BAZ tokens render as "Baz" (for example)?
Given any of the inputs above, I'd like to have the output "Foo Bar Baz".