*/
final long start = System.currentTimeMillis();
final XQueryLexer lexer = new XQueryLexer(context, reader);
final XQueryParser parser = new XQueryParser(lexer);
final XQueryTreeParser treeParser = new XQueryTreeParser(context);
try {
if(xpointer) {
parser.xpointer();
} else {
parser.xpath();
}
if(parser.foundErrors()) {
LOG.debug(parser.getErrorMessage());
throw new StaticXQueryException(parser.getErrorMessage());
}
final AST ast = parser.getAST();
if(ast == null) {
throw new XPathException("Unknown XQuery parser error: the parser returned an empty syntax tree.");
}
// LOG.debug("Generated AST: " + ast.toStringTree());
final PathExpr expr = new PathExpr(context);
if(xpointer) {
treeParser.xpointer(ast, expr);
} else {
treeParser.xpath(ast, expr);
}
if(treeParser.foundErrors()) {
//AST treeAst = treeParser.getAST();
throw new StaticXQueryException(ast.getLine(), ast.getColumn(), treeParser.getErrorMessage(), treeParser.getLastException());
}
context.getRootContext().resolveForwardReferences();
context.analyzeAndOptimizeIfModulesChanged(expr);