[antlr-interest] ANTLR 3.0.1: invalid character column in a mismatch character error message.

Loring Craymer lgcraymer at yahoo.com
Wed Aug 13 11:45:13 PDT 2008


As far as tabs go, if it matters, it makes more sense to track tab count and position in line; the user can do that by having a
TAB : '\t'  { tabs++; } ;
rule (or something similar; I don't use ANTLR 3 action syntax) and supporting a column() method that looks like
int column() {
     return charPositionInLine - tabs + tabs * tabsize;
}
to the AST node type.
--Loring



----- Original Message ----
> From: Gavin Lambert <antlr at mirality.co.nz>
> To: Terence Parr <parrt at cs.usfca.edu>; Jim Idle <jimi at temporal-wave.com>
> Cc: antlr-interest at antlr.org
> Sent: Wednesday, August 13, 2008 1:26:54 AM
> Subject: Re: [antlr-interest] ANTLR 3.0.1: invalid character column in a mismatch character error message.
> 
> [Merging thread branches a bit...]
> 
> At 09:50 13/08/2008, Terence Parr wrote:
> >> Still, couldn't the lexer have a setTabSize() method or
> >> something?  Default it to 8, since that's the official
> >> standard tab size (even though most people usually reduce
> >> it), and let the driver code (or ANTLRworks) modify as
> >> needed.
> >
> >that was how v2 worked I think...still was trouble ;)
> 
> Yeah, but v2 *only* did that.  I think v3 should still keep the 
> line position (that's still useful) -- but it should have the 
> column as well.  It's not that much more work and it'd be handy 
> whether for the default or for custom error handlers.  (Might even 
> be useful for some kinds of syntax highlighting too.)
> 
> 
> At 10:51 13/08/2008, Jim Idle wrote:
> >Once you start adding all these traces then you find the lexers 
> >generate 3 tokens a minute. The base information is all there and 
> >I think FAQ #1 just needs to be: "Why you need your own error 
> >message printing function."
> 
> Hardly.  One or two extra ints containing information that's 
> basically already known at token generation time?  I doubt that'd 
> leave a noticeable dent.  (Well, ok, I guess the stream position 
> might have to be a longlong, or fpos_t, or whatever..  Still.)
> 
> And even if you do implement your own error handling function -- 
> why force it to do all the work of scanning the characters on the 
> line looking for and expanding tabs just to get a column number, 
> when the lexer already had to pass those same tabs in order to 
> generate the error in the first place?
> 
> At minimum there should be a function in the runtime you can call 
> to do this for you.  I don't see why each driver program needs to 
> re-invent the wheel.



      



More information about the antlr-interest mailing list