[antlr-interest] How to redirect all of antlr parser's error messages without changing recovery.
Neville Clark
antlr at zavalon.com
Mon Feb 4 23:34:16 PST 2008
Hi all,
I am new to both this list and to antlr.
I have to questions
1. How to override all of antlr's parser errors but without changing
antlr's recovery. I am running as an Eclipse plug-in, and I want to use
"problem marker" instead of "System.err".
Overriding "reportError" catches most of the output. But had to also
override "recoverFromMismatchedToken" and "mismatch" as per below
@Override
public void recoverFromMismatchedToken(IntStream input,
RecognitionException mte,
int
ttype,
BitSet follow) throws RecognitionException
{
//System.err.println("BR.recoverFromMismatchedToken"); <<<=== I
removed this line
// if next token is what we are looking for then "delete" this token
if ( input.LA(2)==ttype )
{
reportError(mte);
/*
System.err.println("recoverFromMismatchedToken deleting
"+input.LT(1)+
" since "+input.LT(2)+" is what we
want");
*/
beginResync();
input.consume(); // simply delete extra token
endResync();
input.consume(); // move past ttype token as if all were ok
return;
}
if ( !recoverFromMismatchedElement(input,mte,follow) )
{
throw mte;
}
}
As indicated in above had to override and reproduce the same
functionality except for the print statement.
Also required to override "mismatch" and reproduce it's code without change
Is there a better way.
2nd Question
In a combined grammar is it possible to "superClass" the Lexer as well
as the Parser. I have added
options
{
superClass=MyParserSuperClass;
}
which works for the parser. But can not find same for the Lexer (within
a combined grammar).
I have not tried but am assuming I can superClass the Lexer if I
separate the Parser and Lexer.
Thanks in advance,
Nev
More information about the antlr-interest
mailing list