use of org.antlr.runtime.tree.TreeVisitor in project cuba by cuba-platform.
the class Parser method checkTreeForExceptions.
private static void checkTreeForExceptions(String input, CommonTree tree) {
TreeVisitor visitor = new TreeVisitor();
ErrorNodesFinder errorNodesFinder = new ErrorNodesFinder();
visitor.visit(tree, errorNodesFinder);
List<ErrorRec> errors = errorNodesFinder.getErrorNodes().stream().map(node -> new ErrorRec(node, "CommonErrorNode")).collect(Collectors.toList());
if (!errors.isEmpty()) {
throw new JpqlSyntaxException(String.format("Errors found for input jpql:[%s]", StringUtils.strip(input)), errors);
}
}
use of org.antlr.runtime.tree.TreeVisitor in project cuba by cuba-platform.
the class QueryTreeAnalyzer method prepare.
public void prepare(DomainModel model, String query, boolean failOnErrors) throws RecognitionException {
Preconditions.checkNotNull(query, "query is null");
this.model = model;
query = query.replace("\n", " ");
query = query.replace("\r", " ");
query = query.replace("\t", " ");
tree = Parser.parse(query, failOnErrors);
TreeVisitor visitor = new TreeVisitor();
idVarSelector = new IdVarSelector(model);
visitor.visit(tree, idVarSelector);
}
use of org.antlr.runtime.tree.TreeVisitor in project cuba by cuba-platform.
the class QueryTreeAnalyzer method findAllConditions.
public List<SimpleConditionNode> findAllConditions() {
NodesFinder<SimpleConditionNode> nodesFinder = new NodesFinder<>(SimpleConditionNode.class);
TreeVisitor treeVisitor = new TreeVisitor();
treeVisitor.visit(tree, nodesFinder);
return nodesFinder.getFoundNodes();
}
use of org.antlr.runtime.tree.TreeVisitor in project antlr4 by tunnelvisionlabs.
the class GrammarTransformPipeline method expandParameterizedLoops.
/**
* Find and replace
* ID*[','] with ID (',' ID)*
* ID+[','] with ID (',' ID)+
* (x {action} y)+[','] with x {action} y (',' x {action} y)+
*
* Parameter must be a token.
* todo: do we want?
*/
public void expandParameterizedLoops(GrammarAST root) {
TreeVisitor v = new TreeVisitor(new GrammarASTAdaptor());
v.visit(root, new TreeVisitorAction() {
@Override
public Object pre(Object t) {
if (((GrammarAST) t).getType() == 3) {
return expandParameterizedLoop((GrammarAST) t);
}
return t;
}
@Override
public Object post(Object t) {
return t;
}
});
}
use of org.antlr.runtime.tree.TreeVisitor in project flink by apache.
the class HiveParserUtils method rewriteGroupingFunctionAST.
public static HiveParserASTNode rewriteGroupingFunctionAST(final List<HiveParserASTNode> grpByAstExprs, HiveParserASTNode targetNode, final boolean noneSet) throws SemanticException {
final MutableBoolean visited = new MutableBoolean(false);
final MutableBoolean found = new MutableBoolean(false);
final boolean legacyGrouping = legacyGrouping();
TreeVisitorAction action = new TreeVisitorAction() {
@Override
public Object pre(Object t) {
return t;
}
@Override
public Object post(Object t) {
HiveParserASTNode current = (HiveParserASTNode) t;
// rewrite grouping function
if (current.getType() == HiveASTParser.TOK_FUNCTION && current.getChildCount() >= 2) {
HiveParserASTNode func = (HiveParserASTNode) current.getChild(0);
if (func.getText().equals("grouping")) {
visited.setValue(true);
convertGrouping(current, grpByAstExprs, noneSet, legacyGrouping, found);
}
} else if (legacyGrouping && current.getType() == HiveASTParser.TOK_TABLE_OR_COL && current.getChildCount() == 1) {
// rewrite grouping__id
HiveParserASTNode child = (HiveParserASTNode) current.getChild(0);
if (child.getText().equalsIgnoreCase(VirtualColumn.GROUPINGID.getName())) {
return convertToLegacyGroupingId(current, grpByAstExprs.size());
}
}
return t;
}
};
HiveParserASTNode newTargetNode = (HiveParserASTNode) new TreeVisitor(HiveASTParseDriver.ADAPTOR).visit(targetNode, action);
if (visited.booleanValue() && !found.booleanValue()) {
throw new SemanticException("Expression in GROUPING function not present in GROUP BY");
}
return newTargetNode;
}
Aggregations