2

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
Community
  • 1
  • 1
Markus
  • 3,225
  • 6
  • 35
  • 47

1 Answers1

1

To analyze this kind of problem, dump the token stream to see what the lexer is actually doing. To dump the tokens, see this answer - it is in Java, but the C# implementation should be quite similar.

Community
  • 1
  • 1
GRosenberg
  • 5,843
  • 2
  • 19
  • 23
  • Already fixed it randomly, but thank you for your answer that will make it easier the next time! – Markus Jul 14 '15 at 20:25