質問

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.

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.

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.)

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

役に立ちましたか?

解決

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

Support importing multi-mode lexer grammars

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top