[antlr-interest] Taking control of the input stream

weitzman_d weitzman_d at yahoo.com
Tue Sep 17 14:23:41 PDT 2002

Howdy.  I just started using ANTLR and it looks like a great tool.  
I'm trying to write a grammer that parses IMAP commands (the spec 
doesn't seem consistant enough to allow generic parsing).  Here's the 
tricky part:

IMAP allows strings to be expressed as something it calls a 'literal' 
(not to be confused with what everyone else calls a literal).  
Servers must accept quoted strings and 
atoms (like the quoted-string message content here)

C: A003 APPEND saved-messages (\Seen) "Date: Mon, ..."

But servers must also be able to accept in the 'literal' form like 

C: A003 APPEND saved-messages (\Seen) {310}
S: + continue
C: Date: Mon, 7 Feb 1994 21:52:25 -0800 (PST)
C: ...
C: (310 bytes later...)
S: A003 OK APPEND completed

I want my ANTLR grammer to see the {NUM} and eat up the next NUM 
bytes into a single token.  A general outline of the rule would look 
something like this:

literal	:	"{" len:NUMBER "}" CRLF
	int length = Integer.parseInt(len.getText());
        out.println("+ continue");
	String value = [read the next 'length' bytes]

How can I do this (or is it not possible)?


David Weitzman


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

More information about the antlr-interest mailing list