[antlr-interest] outputting whole source line on error

Jim Idle jimi at temporal-wave.com
Sat Nov 29 09:37:35 PST 2008


On Fri, 2008-11-28 at 15:53 -0800, Randall R Schulz wrote:

> 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."


Or, more accurately, ANTLR does not do this because it cannot
generically 'know' what a line of your input is. However, the error
message objects give you the token at which an error occurred and it is
easy to use this positional information to locate the start of your
'line' in the input stream and print it out, with a caret underneath the
error and so on.

Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081129/c26a0842/attachment.html 


More information about the antlr-interest mailing list