[antlr-interest] Parse only <n> bytes from InputStream

matthew ford Matthew.Ford at forward.com.au
Wed Jul 7 14:51:21 PDT 2004


I have recently come across a problem of Anltr not closing input streams (in
Java), at least as far at JEdit is concerned.
Need to quit the Antlr parser in order to get JEdit to save any changes to
the input file.
My quick fix was to read the input into a StringBuffer close the input
stream and then parse from a StringReader.
Haven't got round to producing a small example of the problem.
Any one else have this problem?
matthew
----- Original Message ----- 
From: "Ric Klaren" <klaren at cs.utwente.nl>
To: <antlr-interest at yahoogroups.com>
Sent: Wednesday, July 07, 2004 12:47 AM
Subject: Re: [antlr-interest] Parse only <n> bytes from InputStream


> On Tue, Jul 06, 2004 at 02:33:05PM -0000, andreasharth wrote:
> > I have written a small HTTP server in Java and like to parse input
> > from a HTTP PUT operation.  The length of the input in bytes is
> > specified using the content-length header.  I am able to parse the
> > stream that's coming in.  So far, so good.
> >
> > Problem is that the parser should close the Reader after a number of
> > bytes (the content-length) have been read.  I could first store
> > everything the HTTP server recieves, and then parse that, but since I
> > want to process megabytes (and maybe gigabytes) caching things is not
> > really an option.  I cannot specify and end of file symbol either
> > because that's not in the HTTP protocol.
> >
> > Is there a way to make the parser stop after having read a given
> > number of bytes?
>
> I'd implement a custom InputBuffer that would cut off after N bytes. Then
> initialize the lexer with that one. Look at InputBuffer.java to see what
> you have to do. You might also get some inspiration from
> lib/cpp/antlr/CharInputBuffer.hpp.
>
> Cheers,
>
> Ric
> -- 
> -----+++++*****************************************************+++++++++--
-----
>     ---- Ric Klaren ----- j.klaren at utwente.nl ----- +31 53 4893755  ----
> -----+++++*****************************************************+++++++++--
-----
>   Xander: "Buffy, we need to do something *now*"
>   Angel: "We need a distraction."
>   Buffy: "Right."
>   Angel: "What are you going to do?"
>   Buffy: "I'm going to kill them all. That oughtta distract 'em..."
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>



 
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