[antlr-interest] Creating tree items in an exception
Jan van der Ven
jhvdven at xs4all.nl
Thu Mar 15 12:12:38 PDT 2007
Dear all,
I am trying to parse a SQL script and to continue to the next statement
in case of errors in the current statement. I handle exceptions in the
grammar like this (inspired by Preshant):
sql_data_stmt : {nStatements++;}
select_stmt
| insert_stmt
| update_stmt
| delete_stmt
;
exception
catch [NoViableAltException nvae]
{
System.out.println("sql_data_stmt nvae " + nvae.getMessage());
QError e = new QError("NoViableAltException");
[...] // fill this error instance with useful stuff
// here is the problematic statement
##=#([ERROR_STATEMENT,"error nvae"]);
if(LA(1)==SEMICOLON)
{
consume();
sql_stmt();
return;
}
consume();
/*
A semicolon is a quite wonderful thing to have, but is not
required by all databases. So we might also try valid statement
starting keywords here.
*/
while (LA(1) != Token.EOF_TYPE && (LA(1)!=SEMICOLON)) {
consume();
}
if(LA(1)==SEMICOLON){
consume();
}
if(LA(1) != Token.EOF_TYPE){
sql_stmt();
}
return;
}
The funny bit is that I do get the console output, but do not get the
addition to the final AST.
Can anyone point me towards a solution?
Thanks in advance.
Jan
More information about the antlr-interest
mailing list