package mlc.forselect;
import java.io.File;
import java.io.IOException;
import junit.framework.Assert;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.CommonTree;
import tool.model.grammar.ForSelectLexer;
import tool.model.grammar.ForSelectParser;
import tool.model.grammar.NoCaseFileStream;
import tool.model.grammar.NoCaseStringStream;
public class ForTest{
public CommonTokenStream getStream(String source) {
CharStream stream = new NoCaseStringStream(source);
ForSelectLexer lexer = new ForSelectLexer(stream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
return tokenStream;
}
public CommonTokenStream getStream(File source) throws IOException {
CharStream stream = new NoCaseFileStream(source.getAbsolutePath());
ForSelectLexer lexer = new ForSelectLexer(stream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
return tokenStream;
}
public int syntaxErrors(ForSelectParser parser){
int errors = parser.getNumberOfSyntaxErrors();
if (errors > 0) Assert.fail();
return errors;
}
public ForSelectParser getParser(String source){
TokenStream tokenStream = getStream(source);
ForSelectParser parser = new ForSelectParser(tokenStream);
return parser;
}
public ForSelectParser getParser(File source) throws IOException{
TokenStream tokenStream = getStream(source);
ForSelectParser parser = new ForSelectParser(tokenStream);
return parser;
}
public String printTree(String title, Object tree){
String treeString = ((CommonTree)tree).toStringTree();
System.out.println(title +" ==>" + treeString);
return treeString;
}
public String printTree(Object tree){
String title = "TREE";
return printTree(title, tree);
}
}