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

org.joo.libra.sql.AbstractAntlrSqlPredicateParser Maven / Gradle / Ivy

There is a newer version: 2.1.2
Show newest version
package org.joo.libra.sql;

import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.Lexer;
import org.antlr.v4.runtime.Parser;
import org.joo.libra.Predicate;

public abstract class AbstractAntlrSqlPredicateParser implements SqlPredicateParser {

	@Override
	public Predicate parse(String predicate) {
		CharStream stream = CharStreams.fromString(predicate);
		
		Lexer lexer = createLexer(stream);
		
		CommonTokenStream tokens = new CommonTokenStream(lexer);
		
		P parser = createParser(tokens);
		
		ExpressionNode node = doParse(parser);
		if (node == null) {
			return null;
		}
		return node.buildPredicate();
	}

	protected abstract L createLexer(CharStream stream);

	protected abstract P createParser(CommonTokenStream tokens);
	
	protected abstract ExpressionNode doParse(P parser);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy