use of org.eclipse.rdf4j.query.parser.serql.ast.ASTTupleQuery in project rdf4j by eclipse.
the class SeRQLParser method parseQuery.
public ParsedQuery parseQuery(String queryStr, String baseURI) throws MalformedQueryException {
try {
ASTQueryContainer qc = SyntaxTreeBuilder.parseQuery(queryStr);
// Replace deprecated NULL nodes with semantically equivalent
// alternatives
NullProcessor.process(qc);
StringEscapesProcessor.process(qc);
Map<String, String> namespaces = NamespaceDeclProcessor.process(qc);
ProjectionProcessor.process(qc);
qc.jjtAccept(new ProjectionAliasProcessor(), null);
qc.jjtAccept(new AnonymousVarGenerator(), null);
// TODO: check use of unbound variables?
TupleExpr tupleExpr = QueryModelBuilder.buildQueryModel(qc, SimpleValueFactory.getInstance());
ASTQuery queryNode = qc.getQuery();
ParsedQuery query;
if (queryNode instanceof ASTTupleQuery) {
query = new ParsedTupleQuery(tupleExpr);
} else if (queryNode instanceof ASTGraphQuery) {
query = new ParsedGraphQuery(tupleExpr, namespaces);
} else {
throw new RuntimeException("Unexpected query type: " + queryNode.getClass());
}
return query;
} catch (ParseException e) {
throw new MalformedQueryException(e.getMessage(), e);
} catch (TokenMgrError e) {
throw new MalformedQueryException(e.getMessage(), e);
} catch (VisitorException e) {
throw new MalformedQueryException(e.getMessage(), e);
}
}
Aggregations