如何修复“不允许使用多字符文字"antlr4 词法分析器规则中的错误? [英] How to fix the "multi-character literals are not allowed" error in antlr4 lexer rule?
问题描述
我想写的规则是:
Character : '\u0000'..'\u10FFF';
但是当尝试针对定义它的词法分析器文件运行 antlr 工具时,我收到以下错误:
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'
如何解决这个问题?
推荐答案
尝试用 {
和 }
包装多字符文字,并使用 v4 样式字符集[...]
:
Try wrapping the multi-char literal with {
and }
, and use the v4 style character set [...]
:
Character : [\u0000-\u{10FFF}];
来自 https://github.com/antlr/antlr4/blob/master/doc/lexer-rules.md#lexer-rule-elements:
[...] 匹配字符集中指定的字符之一.将 x-y
解释为范围 x
和 y
之间的字符集,包括.以下转义字符被解释为单个特殊字符:\n
、\r
、\b
、\t
、\f
、\uXXXX
和 \u{XXXXXX}
.要获得 ]
、\
或 -
,您必须使用 \
对它们进行转义.
[...] 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\
.
这篇关于如何修复“不允许使用多字符文字"antlr4 词法分析器规则中的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!