Antlr4 导入组合语法失败
Antlr4 import of combined grammar failing
我现在正在...
error(56): AqlCommentTest.g4:12:4: reference to undefined rule: htmlCommentDeclaration
error(56): AqlCommentTest.g4:13:4: reference to undefined rule: mdCommentDeclaration
似乎正在加载词法分析器语法的导入。
以下文件存在问题。
AqlCommentTest.g4
grammar AqlCommentTest;
import AqlLexerRules;
import AqlComment;
program: commentDeclaration+;
commentDeclaration:
htmlCommentDeclaration #Comment_HTML
| mdCommentDeclaration #Comment_MD
;
AqlComment.g4
grammar AqlComment;
import AqlLexerRules;
htmlCommentDeclaration: 'html' '{' '(*' STRING '*)' '}';
mdCommentDeclaration: 'md' '{' '(*' STRING '*)' '}';
AqlLexerRules.g4
lexer grammar AqlLexerRules;
STRING : '"' [a-z]? '"' ;
可以通过从 'AqlCommentTest.g4' 文件中删除 'import AqlLexerRules;' 来停止错误。
为什么会出现这个"fix"问题?
我如何检查 antlr4 导入语句是否实际应用以及如何应用?
如果导入词法分析器规则排在最后:
import AqlComment;
import AqlLexerRules;
错误变为:
error(54): AqlCommentTest.g4:4:0: repeated grammar prequel spec (options, tokens, or import); please merge
因此问题:导入有限制吗?
在Definitive ANTLR 4 Reference 15.2 Grammar Structure or doc你可以找到:
There can be at most one each of options, imports, and token specifications.
如果我将导入更改为:
import AqlComment, AqlLexerRules;
它编译。
我现在正在...
error(56): AqlCommentTest.g4:12:4: reference to undefined rule: htmlCommentDeclaration
error(56): AqlCommentTest.g4:13:4: reference to undefined rule: mdCommentDeclaration
似乎正在加载词法分析器语法的导入。 以下文件存在问题。
AqlCommentTest.g4
grammar AqlCommentTest;
import AqlLexerRules;
import AqlComment;
program: commentDeclaration+;
commentDeclaration:
htmlCommentDeclaration #Comment_HTML
| mdCommentDeclaration #Comment_MD
;
AqlComment.g4
grammar AqlComment;
import AqlLexerRules;
htmlCommentDeclaration: 'html' '{' '(*' STRING '*)' '}';
mdCommentDeclaration: 'md' '{' '(*' STRING '*)' '}';
AqlLexerRules.g4
lexer grammar AqlLexerRules;
STRING : '"' [a-z]? '"' ;
可以通过从 'AqlCommentTest.g4' 文件中删除 'import AqlLexerRules;' 来停止错误。
为什么会出现这个"fix"问题?
我如何检查 antlr4 导入语句是否实际应用以及如何应用?
如果导入词法分析器规则排在最后:
import AqlComment;
import AqlLexerRules;
错误变为:
error(54): AqlCommentTest.g4:4:0: repeated grammar prequel spec (options, tokens, or import); please merge
因此问题:导入有限制吗?
在Definitive ANTLR 4 Reference 15.2 Grammar Structure or doc你可以找到:
There can be at most one each of options, imports, and token specifications.
如果我将导入更改为:
import AqlComment, AqlLexerRules;
它编译。