我刚开始使用ANTLR(4.3 for .NET),经过一段时间的调试后,我不得不投降。我在最后4行得到NoViableAltException
- 但我真的不知道如何解决它......
所以你对我有任何暗示吗?
生成的解析器应该解析Hello {User.Name}!
或Hello {{ {User.Name("}")} }}!
之类的字符串,其中User.Name
和User.Name("}")
应该来自expression
规则和其他所有内容来自plainString
。但是,我还没能测试它......
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