use of org.exist.xquery.parser.XQueryLexer in project exist by eXist-db.
the class AbstractSource method getModuleDecl.
/**
* Check if the source is an XQuery module. If yes, return a QName containing
* the module prefix as local name and the module namespace as namespace URI.
*
* @param is the input stream
* @return QName describing the module namespace or null if the source is not
* a module.
*/
protected static QName getModuleDecl(final InputStream is) {
final XQueryLexer lexer = new XQueryLexer(null, new InputStreamReader(is));
final DeclScanner scanner = new DeclScanner(lexer);
try {
scanner.versionDecl();
} catch (final RecognitionException | XPathException | TokenStreamException e) {
// Nothing to do
}
if (scanner.getNamespace() != null) {
return new QName(scanner.getPrefix(), scanner.getNamespace());
}
return null;
}
use of org.exist.xquery.parser.XQueryLexer in project exist by eXist-db.
the class SortedNodeSet method addAll.
@Override
public void addAll(final NodeSet other) {
final long start = System.currentTimeMillis();
final MutableDocumentSet docs = new DefaultDocumentSet();
for (final NodeProxy p : other) {
docs.add(p.getOwnerDocument());
}
// TODO(pkaminsk2): why replicate XQuery.compile here?
try (final DBBroker broker = pool.get(Optional.ofNullable(user))) {
final XQueryContext context = new XQueryContext(pool);
final XQueryLexer lexer = new XQueryLexer(context, new StringReader(sortExpr));
final XQueryParser parser = new XQueryParser(lexer);
final XQueryTreeParser treeParser = new XQueryTreeParser(context);
parser.xpath();
if (parser.foundErrors()) {
// TODO : error ?
LOG.debug(parser.getErrorMessage());
}
final AST ast = parser.getAST();
LOG.debug("generated AST: {}", ast.toStringTree());
final PathExpr expr = new PathExpr(context);
treeParser.xpath(ast, expr);
if (treeParser.foundErrors()) {
LOG.debug(treeParser.getErrorMessage());
}
expr.analyze(new AnalyzeContextInfo());
for (final SequenceIterator i = other.iterate(); i.hasNext(); ) {
final NodeProxy p = (NodeProxy) i.nextItem();
final IteratorItem item = new IteratorItem(p, expr);
list.add(item);
}
} catch (final RecognitionException | TokenStreamException re) {
// TODO : throw exception ! -pb
LOG.debug(re);
} catch (final EXistException | XPathException e) {
// TODO : throw exception ! -pb
LOG.debug("Exception during sort", e);
}
LOG.debug("sort-expression found {} in {}ms.", list.size(), System.currentTimeMillis() - start);
}
Aggregations