[antlr-interest] Matching fragments

David-Sarah Hopwood david-sarah at jacaranda.org
Mon Sep 7 15:43:06 PDT 2009


Sam Barnett-Cormack wrote:
> Hi all,
> 
> Now, I know that there's no difference between the rule one wants to be 
> start rule and any other - you can call any of them as a function to 
> parse a token stream.
> 
> However, it's usual to put EOF at the end of the start rule, so it makes 
> sure it matches the whole file. However, I'm doing some delayed parsing 
> of certain constructs (as detectable context cannot determine manner of 
> parsing, but using ANTLR should be easier than hand-coding a parser for 
> these token sequences), and I store a list of tokens and have written a 
> wrapper to make them a token stream. However, the rules I'll pass them 
> to won't match EOF.

You can match EOF in the code that calls the rule, not the rule itself,
for example:

  parser.myRule();
  parser.eof();

where "eof : EOF;" is a parser rule.

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com



More information about the antlr-interest mailing list