[antlr-interest] Simply dump file contents between regular lines?

Ric Klaren klaren at cs.utwente.nl
Thu Jul 15 08:17:29 PDT 2004


Hi,

On Thu, Jul 15, 2004 at 03:57:25PM +0200, Lars von Wedel wrote:
> I'd like to create a parser which can parse a file with lines that have
> a regular syntax followed by several lines of arbitrary text. This text
> is like a comment, but may not be dumped as it is needed in the
> follow-up processing step.
> 
> I am able to parse the regular lines successfully. Further, I have
> achieved to parse the comment lines if they consist of simple labels or
> numbers. However, when I try to allow special characters within the
> comment I get lots of non-determinism warnings.

There's a number of ways to go about this and it kindoff depends on what
you'd exactly want.

1. You can use different lexers for the normal lines and the comment lines.
Check out the multiLexer examples from the distribution.

2. In some cases you might be able to us the filter option from the lexer.
(probably not in your case) (this does not work for parsers)

3. In another case you might look at the hidden token approach to 'hide'
the comment parts. Check out the preserveWhitespace example.

4. The tokenStreamRewrite stuff could also apply in some cases. Check out
the tokenStreamRewrite examples. (C++ version is available only in
development version (unreleased yet))

Could well be that you need a combination of 1 and 3.

> Is there any way to tell ANTLR to call a special method in my code for
> anything which does not match any of the given parse rules?

Not really. Or you have to meddle a lot with the error handling mechanisms
(probably a lot of headache while the options above might be better suited).

Cheers,

Ric
-- 
-----+++++*****************************************************+++++++++-------
    ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755  ----
-----+++++*****************************************************+++++++++-------
     "Evil will always triumph, because Good is dumb." ---  Spaceballs



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list