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

查看:785
本文介绍了导入使用不同模式的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(来自antlr4书)
之上定义了一个HTMLLexer并得到以下错误:

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天全站免登陆