All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cass.rollup.rule.RollupRuleInterface Maven / Gradle / Ivy

There is a newer version: 3.1.8
Show newest version
package cass.rollup.rule;

import cass.rollup.js.bridges.*;
import org.stjs.javascript.functions.Callback1;

public class RollupRuleInterface {
	public Callback1 logFunction;
	public Callback1 success;
	public Callback1 failure;
	RollupListener listener;
	private RollupParser parser;
	private RollupRuleProcessor processor;

	public RollupRuleInterface(String input, RollupRuleProcessor processor) {
		InputStream chars = new InputStream(input);
		RollupLexer lexer = new RollupLexer(chars);
		CommonTokenStream tokens = new CommonTokenStream(lexer);
		parser = new RollupParser(tokens);
		parser.buildParseTrees = true;

		listener = new RollupListener();
		this.processor = processor;

		final RollupRuleInterface me = this;
		listener.enterS = new Callback1() {
			@Override
			public void $invoke(context ctx) {
				me.processor.enterS(ctx);
			}
		};
		listener.exitS = new Callback1() {
			@Override
			public void $invoke(context ctx) {
				me.processor.exitS(ctx);
				me.success.$invoke(true);
			}
		};
		listener.exitToken = new Callback1() {

			@Override
			public void $invoke(context ctx) {
				me.processor.exitToken(ctx);
			}
		};
		listener.enterQuery = new Callback1() {

			@Override
			public void $invoke(context ctx) {
				me.processor.enterQuery(ctx);
			}
		};
		listener.exitQuery = new Callback1() {

			@Override
			public void $invoke(context ctx) {
				me.processor.exitQuery(ctx);
			}
		};
		listener.exitInnerquery = new Callback1() {

			@Override
			public void $invoke(context ctx) {
				me.processor.exitInnerquery(ctx);
			}
		};
		listener.exitLogical_or_math_operator = new Callback1() {

			@Override
			public void $invoke(context ctx) {
				me.processor.exitLogical_or_math_operator(ctx);
			}
		};
		parser.addParseListener(listener);

	}

	public void go() {
		processor.logFunction = logFunction;
		processor.success = success;
		processor.failure = failure;
		parser.s();
	}

}