[antlr-interest] how to report errors in include files

Rob Finneran robfinneran at gmail.com
Mon Oct 8 16:19:50 PDT 2007


Hi Pete,

I agree, ANTLR really needs to be improved to handle multiple file
parsing better.

The custom lexer rule manually calls "reset()" which resets the line
counter, so remove this line and add tracking for filenames and the
virtual line numbers they start on. Line counting would continue to be
automatic. Error message reporting would have to convert the virtual
line count to a file name and actual line number.

Of course this is all just theory for me, since I still can't get
include files to work. The lexer does its job, but the parser only
receives tokens from the first include file.  Maybe the build-AST-tree
mechanism, or the parser itself, thinks its job is done when the lexer
hits the first EOF of the first include file. The lexer moves on to
process the next file without any problems but the parser thinks its
job is finished. Eventually I will have to open up the hood and debug
the damned thing.

Cheers!

Rob

On 10/8/07, Pete Siemsen <siemsen at ucar.edu> wrote:
>
> I understand.  How do I "not reset the line counter"?  By editing the code
> generated
> by ANTLR?  It seems like counting lines and such is about as much effort as
> running
> the translator on each individual file.
>
> Seems like there ought to be a better solution :-)
>
>
> -- Pete
>
>
>
>
>
> On Oct 7, 2007, at 1:04 PM, Rob Finneran wrote:
>
> Hi Pete,
>
> One idea would be to not reset() the line counter. You would then need
> to map the virtual line number (like line 127585) to the actual file
> and actual line number (like line 123).
>
> Just an idea!
>
> On 10/7/07, Pete Siemsen <siemsen at ucar.edu> wrote:
>
> Can I make ANTLR show source file names in error messages?
>
> I'm developing a grammar to translate a set of about 1300 source files.  The
> files have to be processed in a certain order, so there's a single file that
> has about 1300 "include" statements.  By pointing my ANTLR 3.0.1 translator
> at the single source file, the entire set is processed as if it were one
> giant file.  My translator now handles the include files fine, thanks to
> help from this list.  As I expected, I'm seeing various parser error
> messages because my grammar isn't quite correct yet. The trouble is that the
> error messages don't tell me which include file the error occurred in.
>
> I tried putting debugging lines in the code that handles the include
> statements.  Now I see about 1300 messages that say "opening include file
> xyz".  The handling of include files happens in the lexer phase, so I see
> all 1300 of those messages first, followed by all the messages about parser
> errors.  The latter messages have line numbers, but not file names, so
> there's no way to relate the messages to the files.
>
> I could approach this problem outside ANTLR by running the translator on
> each individual file, but I'm hoping for a better method.
>
>
> -- Pete
>
>
>
>
>
>


More information about the antlr-interest mailing list