Exceptions handling, Line and Char stream Position
Hi all,
I've written a tree parsing rule, and have few doubts concerning nice
exceptions handling.
I have such thing working:
def_tags
: (a=ID {db.tags.register($ID.text);})*
;
catch[DatabaseAbstractException e] {
reportDatabaseError(e,$a);
tryToRecover(e);
}
And I would like it to look like this:
def_tags
: (ID {db.tags.register($ID.text);})*
;
catch[DatabaseAbstractException e] {
reportDatabaseError(e);
tryToRecover(e);
}
Method 'reportDatabaseError' is member of tree parser.
Method register throws TagAlreadyDefinedException, which inherits from
DatabaseAbstractException.
In first rule, I nicely print line and char position of the error
using token reference '$a' passed to method 'reportDatabaseError'.
In second rule I would like to get last matched token from 'input'
'InStream' available from my tree parser and then get from it all
necessary data for nice error info.
Is it possible to do it like that?
I have been studying RecognitionException source code for some
answers, but it occurs to me that RecognitionExceptions are thrown
before 'consume' method is invoked on the stream, thus mismatched
token is still available through LT(1) method. In my case token ID is
successfully matched and consumed, and after that 'register' throws an
exception.
http://www.antlr.org/api/Java/_recognition_exception_8java-source.html
Thanks for help in advance,
Michal
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---