use of org.apache.jena.query.QueryParseException in project jena by apache.
the class uparse method execOne.
private void execOne(String updateString, Syntax syntax) {
UpdateRequest req;
try {
req = UpdateFactory.create(updateString, syntax);
} catch (QueryParseException ex) {
System.err.print("Parse error: ");
System.err.println(ex.getMessage());
return;
}
//req.output(IndentedWriter.stderr) ;
if (printUpdate)
System.out.print(req);
if (printNone)
return;
// And some checking.
IndentedLineBuffer w = new IndentedLineBuffer();
UpdateWriter.output(req, w);
String updateString2 = w.asString();
UpdateRequest req2 = null;
try {
req2 = UpdateFactory.create(updateString2, syntax);
} catch (QueryParseException ex) {
System.err.println("Can not reparse update after serialization");
System.err.println(updateString2);
}
if (!req.equalTo(req2))
System.err.println("Reparsed update does not .equalTo original parsed request");
}
use of org.apache.jena.query.QueryParseException in project jena by apache.
the class ParserARQUpdate method _parse.
private void _parse(UpdateSink sink, Reader r) {
ARQParser parser = null;
try {
parser = new ARQParser(r);
parser.setUpdateSink(sink);
parser.UpdateUnit();
} catch (org.apache.jena.sparql.lang.arq.ParseException ex) {
throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
} catch (org.apache.jena.sparql.lang.arq.TokenMgrError tErr) {
// Last valid token : not the same as token error message - but this should not happen
int col = parser.token.endColumn;
int line = parser.token.endLine;
throw new QueryParseException(tErr.getMessage(), line, col);
} catch (QueryException ex) {
throw ex;
} catch (JenaException ex) {
throw new QueryException(ex.getMessage(), ex);
} catch (Error err) {
// The token stream can throw errors.
throw new QueryParseException(err.getMessage(), err, -1, -1);
} catch (Throwable th) {
Log.error(this, "Unexpected throwable: ", th);
throw new QueryException(th.getMessage(), th);
}
}
use of org.apache.jena.query.QueryParseException in project jena by apache.
the class ParserSPARQL11 method perform.
// All throwable handling.
private static void perform(Query query, String string, Action action) {
Reader in = new StringReader(string);
SPARQLParser11 parser = new SPARQLParser11(in);
try {
query.setStrict(true);
parser.setQuery(query);
action.exec(parser);
} catch (org.apache.jena.sparql.lang.sparql_11.ParseException ex) {
throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginColumn);
} catch (org.apache.jena.sparql.lang.sparql_11.TokenMgrError tErr) {
// Last valid token : not the same as token error message - but this should not happen
int col = parser.token.endColumn;
int line = parser.token.endLine;
throw new QueryParseException(tErr.getMessage(), line, col);
} catch (QueryException ex) {
throw ex;
} catch (JenaException ex) {
throw new QueryException(ex.getMessage(), ex);
} catch (Error err) {
System.err.println(err.getMessage());
// The token stream can throw errors.
throw new QueryParseException(err.getMessage(), err, -1, -1);
} catch (Throwable th) {
Log.warn(ParserSPARQL11.class, "Unexpected throwable: ", th);
throw new QueryException(th.getMessage(), th);
}
}
use of org.apache.jena.query.QueryParseException in project jena by apache.
the class SyntaxVarScope method check.
// Other check (not scoping at this level) of a query
private static void check(Query query, Collection<Var> vars) {
// Check any expressions are assigned to fresh variables.
checkExprListAssignment(vars, query.getProject());
// Legal in ARQ, not in SPARQL 1.1
if (!Syntax.syntaxARQ.equals(query.getSyntax())) {
if (query.isQueryResultStar() && query.hasGroupBy())
throw new QueryParseException("SELECT * not legal with GROUP BY", -1, -1);
}
// Check any variable in an expression is in scope (if GROUP BY)
checkExprVarUse(query);
// ENABLE
if (false && query.hasGroupBy()) {
VarExprList exprList2 = query.getGroupBy();
checkExprListAssignment(vars, exprList2);
// CHECK
}
}
use of org.apache.jena.query.QueryParseException in project jena by apache.
the class SyntaxVarScope method checkExprVarUse.
private static void checkExprVarUse(Query query) {
if (query.hasGroupBy()) {
VarExprList groupKey = query.getGroupBy();
// Copy - we need to add variables
// SELECT (count(*) AS ?C) (?C+1 as ?D)
List<Var> inScopeVars = new ArrayList<>(groupKey.getVars());
VarExprList exprList = query.getProject();
for (Var v : exprList.getVars()) {
// In scope?
Expr e = exprList.getExpr(v);
if (e == null) {
if (!inScopeVars.contains(v)) {
throw new QueryParseException("Non-group key variable in SELECT: " + v, -1, -1);
}
} else {
Set<Var> eVars = e.getVarsMentioned();
for (Var v2 : eVars) {
if (!inScopeVars.contains(v2)) {
throw new QueryParseException("Non-group key variable in SELECT: " + v2 + " in expression " + e, -1, -1);
}
}
}
inScopeVars.add(v);
}
}
}
Aggregations