更新时间:2023-02-09 13:26:27
组合语法(即仅以grammar
开头的语法,而不是parser grammar
或lexer grammar
开头的语法)不能使用词法分析器模式.代替使用import
功能¹,您应该使用这样的tokenVocab
功能:
Combined grammars (which are grammars that start with just grammar
, instead of parser grammar
or lexer grammar
) cannot use lexer modes. Instead of using the import
feature¹, you should use the tokenVocab
feature like this:
Lexer_To_Test_More_Command.g4 :
lexer grammar Lexer_To_Test_More_Command;
// lexer rules and modes here
Parser_To_Test_More_Command.g4 :
parser grammar Parser_To_Test_More_Command;
options {
tokenVocab = Lexer_To_Test_More_Command;
}
// parser rules here
¹我实际上建议在ANTLR中完全避免使用import
语句.我上面描述的方法几乎总是首选.
¹ I actually recommend avoiding the import
statement altogether in ANTLR. The method I described above is almost always preferable.