如何修复“不允许使用多字符文字".antlr4词法分析器规则出错? [英] How to fix the "multi-character literals are not allowed" error in antlr4 lexer rule?
问题描述
我要写的规则是:
Character : '\u0000'..'\u10FFF';
但是当尝试对定义了该词法的lexer文件运行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屋!