[antlr-interest] Empty Quoted String Literal
G. Richard Bellamy
rbellamy at pteradigm.com
Wed Jul 27 14:01:16 PDT 2011
Sam, Bart & Jim, I really appreciate your help on this.
Here's a more complete example, without the greedy confusion. I'm
including the combined grammar and a test rig.
I get: CombinedLexer:line 1:2 mismatched character '<EOF>' expecting '"'
just before a NullReferenceException.
GRAMMAR:
----------------------------
grammar Combined;
options {
language=CSharp3;
TokenLabelType=CommonToken;
output=AST;
ASTLabelType=CommonTree;
}
@lexer::namespace{StringLiteralLexerTest}
@parser::namespace{StringLiteralLexerTest}
/*
* Parser Rules
*/
public
compileUnit
: STRING
;
/*
* Lexer Rules
*/
STRING : '"' ('""' | ~'"')* '"';
TEST RIG:
------------------------------
static void Main()
{
CombinedLexer lexer = new CombinedLexer(new ANTLRStringStream(@""""));
//lexer.TraceDestination = new ConsoleTextWriter(typeof(CombinedLexer));
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
CombinedParser parser = new CombinedParser(tokenStream);
//parser.TraceDestination = new ConsoleTextWriter(typeof(CombinedParser));
CommonTree parseTree = parser.compileUnit().Tree;
Console.WriteLine(parseTree.ToStringTree());
}
More information about the antlr-interest
mailing list