[antlr-interest] parsing InputStream from a socket

Johannes Luber jaluber at gmx.de
Thu Aug 23 02:56:54 PDT 2007


Sean Proctor wrote:
> Hello,
> 
> I'm tasked with parsing a protocol that resembles XML. I was using a SAX
> parser and fixing up the input to be valid XML. I switched from this to
> an ANTLR lexer/parser that handles the data as it comes in. I can't
> figure out how to get ANTLR to start parsing as soon as it has enough
> data to determine what to do. I tried writing a CharStream that would
> serve this purpose, but it seems that the tokenizer wants to keep going
> until the EOF. I haven't spent too much time on it to determine if this
> is necessarily true, but I think it's a good assumption. So my questions
> are: Does anyone have any pointers on how to implement a tokenizer that
> will exhibit the behavior that I desire? If I do that, will the parser
> do anything before it gets an EOF? Are there any SAX implementations
> written in ANTLR that I could adapt or use for reference?
> 
> Thanks,
> Sean

The ANTLR lexer does tokenize the entire input at once. The only
solution is to overwrite nextToken() to prevent the call of fillBuffer()
(both methods should be in the lexer) and to implement yourself the
desired behaviour.

Best regards,
Johannes Luber


More information about the antlr-interest mailing list