io.ebeaninternal.server.grammer.EqlParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ebean Show documentation
Show all versions of ebean Show documentation
composite of common runtime dependencies for all platforms
package io.ebeaninternal.server.grammer;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.server.grammer.antlr.EQLLexer;
import io.ebeaninternal.server.grammer.antlr.EQLParser;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.CharStreams;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
/**
* Parse EQL query language applying it to an ORM query object.
*/
public class EqlParser {
private static final ErrorListener errorListener = new ErrorListener();
/**
* Parse the raw EQL query and apply it to the supplied query.
*/
public static void parse(String raw, SpiQuery query) {
EQLLexer lexer = new EQLLexer(CharStreams.fromString(raw));
CommonTokenStream tokens = new CommonTokenStream(lexer);
EQLParser parser = new EQLParser(tokens);
parser.addErrorListener(errorListener);
EQLParser.Select_statementContext context = parser.select_statement();
EqlAdapter adapter = new EqlAdapter<>(query);
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(adapter, context);
query.simplifyExpressions();
}
static class ErrorListener extends BaseErrorListener {
@Override
public void syntaxError(Recognizer, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
String reportMsg = "line " + line + ":" + charPositionInLine + " " + msg;
throw new IllegalArgumentException(reportMsg);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy