[antlr-interest] Reg Multi-line comments
David-Sarah Hopwood
david-sarah at jacaranda.org
Thu Jul 16 22:33:32 PDT 2009
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
More information about the antlr-interest
mailing list