How do I put unicode characters in my Antlr grammar?
-
09-06-2019 - |
Question
I'm trying to build a grammar with the following:
NUMERIC: INTEGER | FLOAT | INFINITY | PI ... INFINITY: '∞' PI: 'π'
But Antlr refuses to load the grammar.
Solution
Use the Java expression representing the Unicode character:
- 'π' = '\u03C0'
- '∞' = '\u221E'
That will work up to '\uFFFF'; Java doesn't support five-digit Unicode.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow