将令牌分配给频道时,为什么会出现错误?
我的.g4文件中包含以下代码.
I have the following code in my .g4 file.
@lexer::members{
public static final int WHITESPACE = 1;
public static final int COMMENTS = 2;
}
WS : (' '|'\t'|'\f')+ -> channel(WHITESPACE)
;
COMMENT
: '//' ~('\n'|'\r')* -> channel(COMMENTS)
;
LINE_COMMENT
: '/*' .*? '*/' NEWLINE? -> channel(WHITESPACE)
;
我遇到以下错误:
warning(155):Shiro.g4:239:34:规则"WS"包含一个词法器命令,其常量值无法识别;词法解释器可能会产生错误的输出
warning(155): Shiro.g4:239:34: rule 'WS' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output
warning(155):Shiro.g4:243:38:规则'COMMENT'包含一个词法器命令,其常量值无法识别;词法解释器可能会产生错误的输出
warning(155): Shiro.g4:243:38: rule 'COMMENT' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output
warning(155):Shiro.g4:247:42:规则"LINE_COMMENT"包含一个词法分析器命令,其常量值无法识别;词法解释器可能会产生错误的输出
warning(155): Shiro.g4:247:42: rule 'LINE_COMMENT' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output
这是Terrence在ANTLR4书中描述的将令牌放置在单独通道上的技术.为什么会收到这些警告?我应该担心吗?
This is the technique described by Terrence in the ANTLR4 book to put tokens on separate channels. Why am I getting these warnings? Should I be concerned?
您没有收到错误;这是一个警告.特别是 UNKNOWN_LEXER_CONSTANT
警告,这是ANTLR 4.2的新功能.
You are not receiving an error; it is a warning. In particular, it is the UNKNOWN_LEXER_CONSTANT
warning, which is new to ANTLR 4.2.
编译器警告155.
Compiler Warning 155.
规则' rule '包含带有无法识别的常数值的lexer命令;词法解释器可能会产生错误的输出
rule 'rule' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output
词法分析器规则包含一个标准的词法分析器命令,但是该命令的常量值参数是无法识别的字符串.结果,lexer命令将转换为自定义lexer操作,从而阻止了该命令在某些解释模式下执行.词法分析器解释器的输出可能与生成的词法分析器的输出不匹配.
A lexer rule contains a standard lexer command, but the constant value argument for the command is an unrecognized string. As a result, the lexer command will be translated as a custom lexer action, preventing the command from executing in some interpreted modes. The output of the lexer interpreter may not match the output of the generated lexer.
以下规则会产生此警告.
The following rule produces this warning.
@members {
public static final int CUSTOM = HIDDEN + 1;
}
X : 'foo' -> channel(HIDDEN); // ok
Y : 'bar' -> channel(CUSTOM); // warning 155