parser.xpointer();
else
parser.xpath();
if (parser.foundErrors()) {
LOG.debug(parser.getErrorMessage());
throw new StaticXQueryException(
parser.getErrorMessage());
}
AST ast = parser.getAST();
if (ast == null)
throw new XPathException("Unknown XQuery parser error: the parser returned an empty syntax tree.");
PathExpr expr = new PathExpr(context);
if (xpointer)
treeParser.xpointer(ast, expr);
else
treeParser.xpath(ast, expr);
if (treeParser.foundErrors()) {
throw new StaticXQueryException(
treeParser.getErrorMessage(),
treeParser.getLastException());
}
expr.analyze(new AnalyzeContextInfo(context));
// if (context.optimizationsEnabled()) {
// Optimizer optimizer = new Optimizer(context);
// expr.accept(optimizer);
// if (optimizer.hasOptimized()) {
// context.reset(true);
// expr.resetState(true);
// expr.analyze(new AnalyzeContextInfo());
// }
// }
// Log the query if it is not too large, but avoid
// dumping huge queries to the log
if (context.getExpressionCount() < 150) {
LOG.debug("Query diagnostics:\n" + ExpressionDumper.dump(expr));
} else {
LOG.debug("Query diagnostics:\n" + "[skipped: more than 150 expressions]");
}
if (LOG.isDebugEnabled()) {
NumberFormat nf = NumberFormat.getNumberInstance();
LOG.debug("Compilation took " + nf.format(System.currentTimeMillis() - start) + " ms");
}
//return
content.add(expr);
} catch (RecognitionException e) {
LOG.debug("Error compiling query: " + e.getMessage(), e);
String msg = e.getMessage();
if (msg.endsWith(", found 'null'"))
msg = msg.substring(0, msg.length() - ", found 'null'".length());
throw new StaticXQueryException(e.getLine(), e.getColumn(), msg);
} catch (TokenStreamException e) {
LOG.debug("Error compiling query: " + e.getMessage(), e);
throw new StaticXQueryException(e.getMessage(), e);
}
}