Search in sources :

Example 1 with ParseException

use of org.apache.jena.sparql.lang.arq.ParseException 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 epxression
	 * @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);
    }
}
Also used : Query(org.apache.jena.query.Query) ARQParser(org.apache.jena.sparql.lang.arq.ARQParser) StringReader(java.io.StringReader) TokenMgrError(org.apache.jena.sparql.lang.arq.TokenMgrError) TokenMgrError(org.apache.jena.sparql.lang.arq.TokenMgrError) ParseException(org.apache.jena.sparql.lang.arq.ParseException) QueryParseException(org.apache.jena.query.QueryParseException) VarExprList(org.apache.jena.sparql.core.VarExprList) QueryParseException(org.apache.jena.query.QueryParseException)

Aggregations

StringReader (java.io.StringReader)1 Query (org.apache.jena.query.Query)1 QueryParseException (org.apache.jena.query.QueryParseException)1 VarExprList (org.apache.jena.sparql.core.VarExprList)1 ARQParser (org.apache.jena.sparql.lang.arq.ARQParser)1 ParseException (org.apache.jena.sparql.lang.arq.ParseException)1 TokenMgrError (org.apache.jena.sparql.lang.arq.TokenMgrError)1