Gokulakannan Somasundaram wrote: > Actually there is a comment like this before the source code of the > function. > > /** A more general version of getRuleInvocationStack where you can > * pass in, for example, a RecognitionException to get it's rule > * stack trace. This routine is shared with all recognizers, hence, > * static. > * > * TODO: move to a utility class or something; weird having lexer call > * this */ > public static List getRuleInvocationStack(Throwable e, > String recognizerClassName) > > > It more or less sounds to me that lexer should not call this.
The recipe in section 10.2 of 'The Definitive ANTLR Reference' does so, therefore it's a supported API, not internal. Moving it would break all lexers using that recipe. Calling the static version of this method rather than the instance version (with no arguments) is correct: if you don't obtain the stack from the RecognitionException that is passed to getErrorMessage, then the relevent lexer rule will no longer be on the current stack in some cases. > When i observe > the source code, i see that your approach may not be possible, because the > token to be tried out never gets saved anywhere. But let me check this. It is possible because the implementation uses a stack trace to determine which lexer methods were on the call stack when the RecognitionException was thrown, and so no explicit state is needed. In any case, I tested this code before posting; it works. -- David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com 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 -~----------~----~----~----~------~----~------~--~---
