[antlr-interest] outputting whole source line on error
Randall R Schulz
rschulz at sonic.net
Fri Nov 28 15:53:09 PST 2008
On Friday 28 November 2008 04:30, micha wrote:
> Hi,
>
> maybe I'm not seeing the obvious, but how can I output the whole
> source line, when an error occurs (while parsing) ?
Well, the lexer counts newlines (or CR+LF pairs) so as to provide a line
count associated with each token it emits, but lines per se are not
something that it otherwise deals in. Lines are, in effect, a
completely separate partitioning of the input sequence and rarely
correspond to a syntactically significant entity.
So the answer is basically "no."
However, the TokenStream interface can reconstruct the text of one or a
sub-sequence of the tokens it has produced (based on ordinal indexes or
particular Token instances produced by that TokenStream). You may be
able to find a way to use that to reconstruct an input line or, more
probably, a fragment of the input corresponding to some syntactically
significant entity.
> thanks for answering,
> Michael
Randall Schulz
More information about the antlr-interest
mailing list