Package org.yaac.server.egql

Source Code of org.yaac.server.egql.TestUtil

package org.yaac.server.egql;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.TokenStream;
import org.yaac.server.egql.antlr.EGQLLexer;
import org.yaac.server.egql.antlr.EGQLParser;
import org.yaac.server.egql.evaluator.EvaluationResult;
import org.yaac.server.egql.processor.ProcessData.ProcessDataRecord;

/**
* Testing util only for ANTLR related test
*
* make it abstract so that maven test runner will ignore this class
*
* @author Max Zhu (thebbsky@gmail.com)
*
*/
public abstract class TestUtil {

  /**
   * @param inputStr
   * @return
   * @throws Exception
   */
  public static EGQLParser parser(String inputStr) {
    CharStream input = new ANTLRStringStream(inputStr);
   
    EGQLLexer lexer = new EGQLLexer(input);
    TokenStream tokens = new CommonTokenStream(lexer);
    EGQLParser parser = new EGQLParser(tokens);
   
    return parser;
  }
 
  /**
   * @param inputStr
   * @return
   * @throws RecognitionException
   */
  public static EvaluationResult evaluate(String inputStr) throws RecognitionException {
    return evaluate(inputStr, null);
  }
 
  /**
   * @param inputStr
   * @param context
   * @return
   * @throws RecognitionException
   */
  public static EvaluationResult evaluate(String inputStr, ProcessDataRecord context) throws RecognitionException {
    return parser(inputStr).expression().e.evaluate(context);
  }
}
TOP

Related Classes of org.yaac.server.egql.TestUtil

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.