use of org.antlr.runtime.RecognitionException in project cuba by cuba-platform.
the class QueryTransformerAstBased method addJoinAndWhere.
@Override
public void addJoinAndWhere(String join, String where) {
EntityReferenceInferer inferer = new EntityReferenceInferer(getMainEntityName());
EntityReference ref = inferer.infer(getQueryTransformer());
if (where.contains("{E}")) {
where = ref.replaceEntries(where, "\\{E\\}");
}
if (join.contains("{E}")) {
join = ref.replaceEntries(join, "\\{E\\}");
}
String[] strings = join.split(",");
join = strings[0];
try {
if (StringUtils.isNotBlank(join)) {
List<JoinVariableNode> joinVariableNodes = Parser.parseJoinClause(join);
boolean firstJoin = true;
for (JoinVariableNode joinVariableNode : joinVariableNodes) {
getQueryTransformer().mixinJoinIntoTree(joinVariableNode, ref, firstJoin);
firstJoin = false;
}
}
for (int i = 1; i < strings.length; i++) {
CommonTree selectionSource = Parser.parseSelectionSource(strings[i]);
getQueryTransformer().addSelectionSource(selectionSource);
}
CommonTree whereTree = Parser.parseWhereClause("where " + where);
addWhere(whereTree, ref, false);
} catch (RecognitionException e) {
throw new RuntimeException(e);
}
}
use of org.antlr.runtime.RecognitionException in project drill by apache.
the class TestBuilder method parsePath.
// modified code from SchemaPath.De class. This should be used sparingly and only in tests if absolutely needed.
public static SchemaPath parsePath(String path) {
try {
ExprLexer lexer = new ExprLexer(new ANTLRStringStream(path));
CommonTokenStream tokens = new CommonTokenStream(lexer);
ExprParser parser = new ExprParser(tokens);
ExprParser.parse_return ret = parser.parse();
if (ret.e instanceof SchemaPath) {
return (SchemaPath) ret.e;
} else {
throw new IllegalStateException("Schema path is not a valid format.");
}
} catch (RecognitionException e) {
throw new RuntimeException(e);
}
}
use of org.antlr.runtime.RecognitionException in project Palladio-Editors-Sirius by PalladioSimulator.
the class PCMServices method validExpression.
/**
* Parses an stochastic expression to determine whether it is valid.
*
* @param the
* expressionString
* @return the validity
*/
private boolean validExpression(final String expressionString) {
final MyPCMStoExLexer lexer = new MyPCMStoExLexer(new ANTLRStringStream(expressionString));
final MyPCMStoExParser parser = new MyPCMStoExParser(new CommonTokenStream(lexer));
try {
parser.expression();
} catch (final RecognitionException e1) {
return false;
}
if (lexer.hasErrors() || parser.hasErrors()) {
return false;
}
return true;
}
use of org.antlr.runtime.RecognitionException in project hive by apache.
the class ParseDriver method parse.
/**
* Parses a command, optionally assigning the parser's token stream to the
* given context.
*
* @param command
* command to parse
*
* @param ctx
* context with which to associate this parser's token stream, or
* null if either no context is available or the context already has
* an existing stream
*
* @return parsed AST
*/
public ASTNode parse(String command, Context ctx, String viewFullyQualifiedName) throws ParseException {
if (LOG.isDebugEnabled()) {
LOG.debug("Parsing command: " + command);
}
HiveLexerX lexer = new HiveLexerX(new ANTLRNoCaseStringStream(command));
TokenRewriteStream tokens = new TokenRewriteStream(lexer);
if (ctx != null) {
if (viewFullyQualifiedName == null) {
// Top level query
ctx.setTokenRewriteStream(tokens);
} else {
// It is a view
ctx.addViewTokenRewriteStream(viewFullyQualifiedName, tokens);
}
lexer.setHiveConf(ctx.getConf());
}
HiveParser parser = new HiveParser(tokens);
if (ctx != null) {
parser.setHiveConf(ctx.getConf());
}
parser.setTreeAdaptor(adaptor);
HiveParser.statement_return r = null;
try {
r = parser.statement();
} catch (RecognitionException e) {
e.printStackTrace();
throw new ParseException(parser.errors);
}
if (lexer.getErrors().size() == 0 && parser.errors.size() == 0) {
LOG.debug("Parse Completed");
} else if (lexer.getErrors().size() != 0) {
throw new ParseException(lexer.getErrors());
} else {
throw new ParseException(parser.errors);
}
ASTNode tree = (ASTNode) r.getTree();
tree.setUnknownTokenBoundaries();
return tree;
}
use of org.antlr.runtime.RecognitionException in project drools by kiegroup.
the class DrlExprParser method parse.
/**
* Parse an expression from text
*/
public ConstraintConnectiveDescr parse(final String text) {
ConstraintConnectiveDescr constraint = null;
try {
DRLLexer lexer = DRLFactory.getDRLLexer(new ANTLRStringStream(text), languageLevel);
CommonTokenStream input = new CommonTokenStream(lexer);
RecognizerSharedState state = new RecognizerSharedState();
helper = new ParserHelper(input, state, languageLevel);
DRLExpressions parser = DRLFactory.getDRLExpressions(input, state, helper, languageLevel);
parser.setBuildDescr(true);
// setting initial value just in case
parser.setLeftMostExpr(null);
BaseDescr expr = parser.conditionalOrExpression();
if (expr != null && !parser.hasErrors()) {
constraint = ConstraintConnectiveDescr.newAnd();
constraint.addOrMerge(expr);
}
} catch (RecognitionException e) {
helper.reportError(e);
}
return constraint;
}
Aggregations