Package tool.model.grammar

Source Code of tool.model.grammar.ANTLRTest

package tool.model.grammar;

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;

public class ANTLRTest{
  public CommonTokenStream getStream(String source) {
    CharStream stream = new NoCaseStringStream(source);
    ForteLexer lexer = new ForteLexer(stream);
    CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    return tokenStream;
   
  }

  public CommonTokenStream getStream(File source) throws IOException {
    CharStream stream = new NoCaseFileStream(source.getAbsolutePath());
    ForteLexer lexer = new ForteLexer(stream);
    CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    return tokenStream;
   
  }
  public CommonTokenStream getSQLStream(String source) {
    CharStream stream = new NoCaseStringStream(source);
    ToolSQLLexer lexer = new ToolSQLLexer(stream);
    CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    return tokenStream;
   
  }

  public CommonTokenStream getSQLStream(File source) throws IOException {
    CharStream stream = new NoCaseFileStream(source.getAbsolutePath());
    ToolSQLLexer lexer = new ToolSQLLexer(stream);
    CommonTokenStream tokenStream = new CommonTokenStream(lexer);
    return tokenStream;
   
  }
  public int syntaxErrors(ForteParser parser){
    int errors = parser.getNumberOfSyntaxErrors();
    if (errors > 0) Assert.fail();
    return errors;
  }

 
  public ForteParser getParser(String source){
    TokenStream tokenStream = getStream(source);
    ForteParser parser = new ForteParser(tokenStream);
    return parser;
  }

  public ForteParser getParser(File source) throws IOException{
    TokenStream tokenStream = getStream(source);
    ForteParser parser = new ForteParser(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);
  }

}
TOP

Related Classes of tool.model.grammar.ANTLRTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.