[antlr-interest] error handling v3 style round 2
Brannon King
brannonking at yahoo.com
Wed Jan 4 10:57:33 PST 2006
I wasn't around for the previous discussion on this, but I'd like to comment
on it now.
Previously proposed by Terence:
method
: type ID ...
;
exception
catch[RecognitionException e]
( {level>0}? ('}' {level--;} | .) )*
That, to me, looks beautiful. It is very close to what I need to do. More
specifically it would be something like this:
method
: '(' funcName^ i:ID ')'
{ isValid(i.getText()) }?
;
exception
catch[SemanticException e]
( {level>0}? (')' {level--;} | .) )*
{ error("expecting blah, found " + i.getText(),
i.file, i.linenum, i.column,
i.getText().length(),
e.linenum, e.column);
recover();
}
To explain: I need to know the range of characters involved in the found ID
for the editor to mark the error, and I need to recover after I hit that
closing parenthisis. Whatever the case, the recover function needs to be
easy to call; I shouldn't have to spend half a day figuring out what params
it takes.
PS, I like the error alternates as well. The slash looks like a fine
operator to me, though |~ might be more obvious.
More information about the antlr-interest
mailing list