gpt4 book ai didi

antlr4 - 为什么在将 token 分配给 channel 时出现错误?

转载 作者:行者123 更新时间:2023-12-01 23:59:56 25 4
gpt4 key购买 nike

我的 .g4 文件中有以下代码。

@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: rule 'WS' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output

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: rule 'LINE_COMMENT' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output

这是 Terrence 在 ANTLR4 书中描述的将 token 放在单独 channel 上的技术。为什么我会收到这些警告?我应该担心吗?

最佳答案

您没有收到错误;这是一个警告。特别是,它是 UNKNOWN_LEXER_CONSTANT警告,这是 ANTLR 4.2 的新功能。

Compiler Warning 155.

rule 'rule' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output

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

关于antlr4 - 为什么在将 token 分配给 channel 时出现错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22027175/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com