I've broken up my combined grammar in two Lexer and Parser grammars:
The combined grammar is so easy like:
parser grammar Fluent;
fluent
: MANDATORY
| PARAMETRIZED '(' PARAMETER ')'
| OPTIONS OPTION?
| CHOOCING ( CHOOSE1 | CHOOSE2 )
| PLUS+
;
MANDATORY : 'mandatory';
PARAMETRIZED : 'parameterized';
PARAMETER : 'parameter';
OPTIONS : 'options';
OPTION : 'option';
CHOOCING : 'choosing';
CHOOSE1: 'choise1';
CHOOSE2: 'choise2';
PLUS: 'plus';
Then I've created a FluentLexer.g4
with lexer rules and a FluentParser.g4
with parser rules.
Then I've imported FluentLexer
grammar on FluentParser
grammar.
I've tried two options:
- With an import FluentLexer in Fluent Grammar:
import FluentLexer
With an options structure:
options{ language = Java; tokenVocab = FluentLexer; }
Using the first one option ANTLR dumps me:
cannot create implicit token for string literal in non-combined grammar: '('
error(126): FluentParser.g4:7:30: cannot create implicit token for string literal in non-combined grammar: ')'
error(126): FluentParser.g4:3:12: cannot create implicit token for string literal in non-combined grammar: 'mandatory'
error(126): FluentParser.g4:4:15: cannot create implicit token for string literal in non-combined grammar: 'parameterized'
error(126): FluentParser.g4:5:12: cannot create implicit token for string literal in non-combined grammar: 'parameter'
...
It seems Lexer rules are imported.
with the second one option, ANTLR tells me only:
error(126): FluentParser.g4:10:16: cannot create implicit token for string literal in non-combined grammar: '('
error(126): FluentParser.g4:10:30: cannot create implicit token for string literal in non-combined grammar: ')'
Why do I need to define ')' and '(' in separated grammars, and why don't I need to define them on a combined grammar?
How could I solve that? I want to use '(' or ')'
insted of a LEXER rule...