package wspice;

import java.io.File;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;

import org.apache.commons.io.FileUtils;

public class TestTranslator {
	
	protected File testSource;
	protected Lexer lexer = new Lexer();

	TestTranslator( String path ) {
		testSource = new File(path);
	}
	
	public boolean translate() {
		try {
			List<String> lines = FileUtils.readLines(testSource, "UTF-8");
			ListIterator<String> it = lines.listIterator();
			List<String> reduced = new Vector<String>();
			while (it.hasNext()) {
				String line = lexer.nextLine(it);
				if (line == null)
					break;
				if (line.isEmpty())
					continue;
				if (line.startsWith("%"))
					continue;
				StringBuffer fullLine = new StringBuffer();
				while( line.endsWith("...")) {
					fullLine.append( line.substring(0, line.length()-3) );
					line = lexer.nextLine(it);
				}
				fullLine.append( line );
			}
		} catch (Exception x) {
			x.printStackTrace();
			return false;
		}
		return true;
	}
}

@@ -212,16 +212,76 @@
 Source;%0A
+%09protected List%3CString%3E reduced;%0A%09ListIterator%3CString%3E rit;%0A
 %09protect
@@ -386,30 +386,707 @@
 %09%0A%09p
-ublic boolean translat
+rotected enum ParseState %7B%0A%09%09HEADER,%0A%09%09TRAILER,%0A%09%09ERROR%0A%09%7D;%0A%09protected ParseState parseState = ParseState.HEADER;%0A%09protected String testName;%0A%09%0A%09protected ParseState parseHeader(String line) %7B%0A%09%09String%5B%5D tokens = lexer.splitNoEmpties(line, %22 %22);%0A%09%09if (tokens.length != 2 %7C%7C !tokens%5B0%5D.equals(%22function%22))%0A%09%09%09return ParseState.ERROR;%0A%09%09testName = tokens%5B1%5D;%0A%09%09return ParseState.TRAILER;%0A%09%7D%0A%09%0A%09public boolean translate() %7B%0A%09%09reduce();%0A%09%09rit = reduced.listIterator();%0A%09%09while (rit.hasNext()) %7B%0A%09%09%09String line = lexer.nextLine(rit);%0A%09%09%09switch (parseState) %7B%0A%09%09%09case HEADER:%0A%09%09%09%09parseState = parseHeader( line );%0A%09%09%09%09break;%0A%09%09%09default:%0A%09%09%09%09return false;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return true;%0A%09%7D%0A%09%0A%09public boolean reduc
 e() 
@@ -1214,29 +1214,19 @@
 or();%0A%09%09
-%09List%3CString%3E
+   
  reduced

split for translate