问题
The rule I am trying to write is:
Character : '\u0000'..'\u10FFF';
But when trying to run antlr tool against the lexer file where it is defined I get the following error:
multi-character literals are not allowed in lexer sets: '\u10FFF'
How to resolve this problem?
回答1:
Try wrapping the multi-char literal with {
and }
, and use the v4 style character set [...]
:
Character : [\u0000-\u{10FFF}];
From https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md#lexer-rule-elements:
[...] Match one of the characters specified in the character set. Interpret
x-y
as the set of characters between rangex
andy
, inclusively. The following escaped characters are interpreted as single special characters:\n
,\r
,\b
,\t
,\f
,\uXXXX
, and\u{XXXXXX}
. To get]
,\
, or-
you must escape them with\
.
来源:https://stackoverflow.com/questions/56322449/how-to-fix-the-multi-character-literals-are-not-allowed-error-in-antlr4-lexer