Problem
I just started using ANTLR (4.3 for .NET) and after debugging for quite a while, I have to surrender. I get a NoViableAltException
in the last 4 lines - but I really have no idea how to fix it ...
So you have any hints for me?
Supposed Behavior
The generated parser is supposed to parse strings like Hello {User.Name}!
or Hello {{ {User.Name("}")} }}!
where User.Name
and User.Name("}")
are expected to derive from the expression
rule and everything else from plainString
. However, I was not yet able to test it ...
Grammar
grammar PatternString;
@namespace{PatternStringParser.AntlrGenerated}
patternString: (plainString | expressionString)+;
plainString: (PLAINSTRINGLITERAL | '""' | '{{' | '}}' )+;
expressionString: '{' expression* '}';
expression: BALANCEDSTRINGLITERAL+
| '(' expression ')'
| '[' expression ']'
| '{' expression '}'
| '"' string '"'
| '\'' character '\'';
string: (STRINGLITERAL | '\\"')+;
character: (CHARACTERLITERAL | '\'' )+;
PLAINSTRINGLITERAL: ~[\"\{\}]; // <= NoViableAltException
BALANCEDSTRINGLITERAL: ~[\"\{\(\[\']; // <= NoViableAltException
CHARACTERLITERAL: ~[\']; // <= NoViableAltException
STRINGLITERAL: ~[\"]; // <= NoViableAltException