Just append a newline to the input string whether it has one or not -
there is no need to play with the input stream logic. A realloc of the
input string for one extra character will usually be accommodated by the
existing string allocation (which is almost always aligned/padded).

Jim

> -----Original Message-----
> From: Kirby Bohling [mailto:[email protected]]
> Sent: Monday, January 31, 2011 4:54 PM
> To: Jim Idle
> Cc: [email protected]
> Subject: Re: [antlr-interest] How do I accept input ending with a
> newline *or* EOF?
>
> On Mon, Jan 31, 2011 at 6:34 PM, Jim Idle <[email protected]>
> wrote:
> > It is much better to add a NL to the end of the input if it is not
> > present as the ambiguities are complicated and pointless without
> that,
> > but with this simple example you can do:
> <snip..>
>
> Jim,
>
>    I've seen you make this suggestion several times.  Is there a
> canonical or simple way to do that inside the Lexer?  Or is the easiest
> way to do that to monkey with the stream to ensure it kicks out a
> potentially missing character if it isn't the last character before the
> EOF?
>
> I've had this problem, and I just had my NL be ('\n'|EOF) and moved
> along, for the grammars I had it was 'good enough'.  It would seem much
> easier, and cleaner to fix up it up as you suggest, just not sure the
> cleanest way to go about it.
>
> Kirby

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to