导入使用不同模式的 ANTLR4 词法分析器语法 [英] Import ANTLR4 lexer grammar which uses different modes

查看:37
本文介绍了导入使用不同模式的 ANTLR4 词法分析器语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一个词法分析器语法导入到另一个词法分析器语法中.导入的语法使用不同的模式(在 XMLLexer 示例模式 INSIDE 和 PROC_INSTR 中).

I am trying to import a lexer grammar into another lexer grammar. The imported grammar uses differen modes (in the XMLLexer example modes INSIDE and PROC_INSTR).

lexer grammar HTMLLexer;
import XMLLexer;

在编译时,我收到一个错误,提示未定义与模式名称相对应的变量.

When compiling, I get an error that an variable which correspond to the mode name is not defined.

作为一个具体的例子,我在 XMLLexer 之上定义了一个 HTMLLexer(来自 antlr4 书)并得到以下错误:

As an concrete example I am defining an HTMLLexer on top of the XMLLexer (from the antlr4 book) and get the following Error:

C:\Users\<user>\AppData\Local\Temp\TestRigTask-1360839400637\HTMLLexer.java:143: 
  error: cannot find symbol
  case 6: more(); pushMode(PROC_INSTR);  break;
                         ^
  symbol:   variable PROC_INSTR
  location: class HTMLLexer
1 error

我可以通过使用附加标记重新定义顶级词法分析器中的模式来克服此错误,但随后无法识别其他模式中导入的标记作为默认标记.

I can overcome this error by redifining the modes in the top level lexer with additional tokens, but then the imported tokens inside the other modes, as the default one, are not recognized.

如果我在主词法分析器定义中内联导入的部分,解析器就可以工作,但我想使用导入功能进行清晰的分离.(不适用于 xml/html 示例,而是在另一种情况下.)

The parser works if I inline the imported part in the main lexer definition, but I would like to use the import functionality to have a clean separation. (Not for the xml/html example, but in an another case.)

是否可以使用导入来使其工作,还是 antlr4 的限制?

Is it possible to get it working using imports or is it a limitation of antlr4?

推荐答案

ANTLR 4 尚不支持导入多模式词法分析器语法.以下问题将跟踪此功能的进展:

Importing multi-mode lexer grammars is not yet supported in ANTLR 4. The following issue will track the progress of this feature:

支持导入多模式词法分析器语法

这篇关于导入使用不同模式的 ANTLR4 词法分析器语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆