use of org.apache.jena.sparql.lang.arq.ARQParser in project jena by apache.
the class ParserARQ method perform.
// All throwable handling.
private static void perform(Query query, String string, Action action) {
Reader in = new StringReader(string);
ARQParser parser = new ARQParser(in);
try {
query.setStrict(true);
parser.setQuery(query);
action.exec(parser);
} 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.warn(ParserSPARQL11.class, "Unexpected throwable: ", th);
throw new QueryException(th.getMessage(), th);
}
}
use of org.apache.jena.sparql.lang.arq.ARQParser in project jena by apache.
the class SelectHandler method parseExpr.
/**
* Parse an expression string into an expression.
*
* This must be able to be parsed as though it were written "SELECT "+s
*
* @param s the select string to parse.
* @return the expression
* @throws QueryParseException on error
*/
private Expr parseExpr(String s) throws QueryParseException {
try {
ARQParser parser = new ARQParser(new StringReader("SELECT " + s));
parser.setQuery(new Query());
parser.getQuery().setPrefixMapping(query.getPrefixMapping());
parser.SelectClause();
Query q = parser.getQuery();
VarExprList vel = q.getProject();
return vel.getExprs().values().iterator().next();
} catch (ParseException ex) {
throw new QueryParseException(ex.getMessage(), ex.currentToken.beginLine, ex.currentToken.beginLine);
} catch (TokenMgrError tErr) {
throw new QueryParseException(tErr.getMessage(), -1, -1);
} catch (Error err) {
// The token stream can throw java.lang.Error's
String tmp = err.getMessage();
if (tmp == null)
throw new QueryParseException(err, -1, -1);
throw new QueryParseException(tmp, -1, -1);
}
}
Aggregations