如何修复 antlr4 词法分析器规则中的 "multi-character literals are not allowed" 错误?

How to fix the "multi-character literals are not allowed" error in antlr4 lexer rule?

我要写的规则是:

Character : '\u0000'..'\u10FFF';

但是当尝试 运行 antlr 工具针对定义它的词法分析器文件时,我收到以下错误:

multi-character literals are not allowed in lexer sets: '\u10FFF'

如何解决这个问题?

尝试用 {} 包装 multi-char 文字,并使用 v4 样式字符集 [...]:

Character : [\u0000-\u{10FFF}];

来自 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 range x and y, 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 \.