[antlr-interest] v3 stream input

Sohail Somani sohail at taggedtype.net
Wed May 24 20:54:58 PDT 2006


On Wed, 2006-05-24 at 11:21 -0700, Terence Parr wrote:
> On May 23, 2006, at 7:17 PM, Sohail Somani wrote:
> >>> I suppose what I'll do is just have a FiniteInputStream as a  
> >>> child of
> >>> ANTLRStringStream and just do what ANTLRFileStream does.
> >>
> >> How about just ANTLRReaderStream and/or ANTLRInputStream?
> >
> > Oh sure, if you want to use it.. Or are you referring to existing
> > classes?
> 
> I'm just saying that if you create this, might as well use those  
> names and share :) though I assume it's a simple subclass...

Madam:

// My java.io isn't that great :)
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.CharArrayWriter;
import java.io.BufferedWriter;
import org.antlr.runtime.ANTLRStringStream;

public class ANTLRInputStream extends ANTLRStringStream {

	public ANTLRInputStream(InputStream stream) throws IOException 
	{
		load(stream);
	}

	public void load(InputStream istream) throws IOException 
	{
		BufferedReader br = new BufferedReader(new 
			InputStreamReader(istream));
		CharArrayWriter wr = new CharArrayWriter();
		BufferedWriter bw = new BufferedWriter(wr); 
		String line=null;
		while((line=br.readLine())!=null)
		{
			bw.write(line);
			// TODO: This may not be what you want
			bw.newLine(); 
		}
		bw.close();
		data = wr.toCharArray();
	}
}




More information about the antlr-interest mailing list