/** * Create a new parser of the same kind * * @return a new parser of the same kind as this one */ public XQueryParser newParser() { XQueryParser qp = new XQueryParser(); qp.setLanguage(language, 31); qp.setParserExtension(parserExtension); return qp; }
ensureSchemaAware("import schema"); Import sImport = new Import(); String prefix = null; sImport.namespaceURI = null; sImport.locationURIs = new ArrayList<>(5); nextToken(); if (isKeyword("namespace")) { prefix = readNamespaceBinding(); } else if (isKeyword("default")) { nextToken(); if (!isKeyword("element")) { grumble("In 'import schema', expected 'element namespace'"); nextToken(); if (!isKeyword("namespace")) { grumble("In 'import schema', expected keyword 'namespace'"); nextToken(); prefix = ""; String uri = uriLiteral(t.currentTokenValue); checkProhibitedPrefixes(prefix, uri); sImport.namespaceURI = uri; nextToken(); if (isKeyword("at")) { nextToken(); expect(Token.STRING_LITERAL); sImport.locationURIs.add(uriLiteral(t.currentTokenValue)); nextToken();
do { LetClause clause = new LetClause(); setLocation(clause, t.currentTokenStartOffset); clause.setRepeated(containsLoopingClause(clauseList)); if (first) { nextToken(); if (first) { first = false; expect(Token.DOLLAR); nextToken(); expect(Token.NAME); String var = t.currentTokenValue; StructuredQName varQName = makeStructuredQName(var, ""); SequenceType type = SequenceType.ANY_SEQUENCE; nextToken(); if (t.currentToken == Token.AS) { nextToken(); type = parseSequenceType(); expect(Token.ASSIGN); nextToken(); clause.initSequence(flwor, parseExprSingle()); clause.setRangeVariable(v); declareRangeVariable(v); } while (t.currentToken == Token.COMMA);
expect(Token.MODULE_NAMESPACE); nextToken(); expect(Token.NAME); String prefix = t.currentTokenValue; nextToken(); expect(Token.EQUALS); nextToken(); expect(Token.STRING_LITERAL); String uri = uriLiteral(t.currentTokenValue); checkProhibitedPrefixes(prefix, uri); if (uri.isEmpty()) { grumble("Module namespace cannot be \"\"", "XQST0088"); uri = "http://saxon.fallback.namespace/"; // for error recovery nextToken(); expect(Token.SEMICOLON); nextToken(); try { ((QueryModule) env).setModuleNamespace(uri); executable.addQueryLibraryModule((QueryModule) env); } catch (XPathException err) { err.setLocator(makeLocation()); reportError(err);
/** * Parse a CountClause. * <p> * [44] CountClause ::= <"count" "$"> VarName * </p> * * @param clauseList - the components of the parsed CountClause are appended to the * supplied list * @throws XPathException in the event of a syntax error */ private void parseCountClause(List<Clause> clauseList) throws XPathException { do { CountClause clause = new CountClause(); setLocation(clause, t.currentTokenStartOffset); clause.setRepeated(containsLoopingClause(clauseList)); clauseList.add(clause); nextToken(); expect(Token.DOLLAR); nextToken(); expect(Token.NAME); String var = t.currentTokenValue; StructuredQName varQName = makeStructuredQName(var, ""); SequenceType type = SequenceType.ANY_SEQUENCE; nextToken(); LocalVariableBinding v = new LocalVariableBinding(varQName, type); clause.setRangeVariable(v); declareRangeVariable(v); } while (t.currentToken == Token.COMMA); }
String uri = ((QueryModule) env).getModuleNamespace(); if (uri == null) { grumble("Module declaration must not be used in a main module"); } else { grumble("Module declaration appears more than once"); grumble("Module declaration must precede other declarations in the query prolog"); case Token.DECLARE_NAMESPACE: if (!allowDeclarations) { grumble("Namespace declarations cannot follow variables, functions, or options"); parseNamespaceDeclaration(); break; case Token.DECLARE_ANNOTATED: processPreamble(); if (allowDeclarations) { sealNamespaces(namespacesToBeSealed, env.getConfiguration()); allowDeclarations = false; nextToken(); expect(Token.PERCENT); AnnotationList annotationList = parseAnnotationsList(); if (isKeyword("function")) { annotationList.check(env.getConfiguration(), "DF"); parseFunctionDeclaration(annotationList); } else if (isKeyword("variable")) { annotationList.check(env.getConfiguration(), "DV");
setLocation(clause, t.currentTokenStartOffset); clause.setRepeated(containsLoopingClause(clauseList)); clause.setIsSlidingWindow(t.currentToken == Token.FOR_SLIDING); nextToken(); if (!isKeyword("window")) { grumble("after 'sliding' or 'tumbling', expected 'window', but found " + currentTokenDisplay()); nextToken(); StructuredQName windowVarName = readVariableName(); SequenceType windowType = SequenceType.ANY_SEQUENCE; if (t.currentToken == Token.AS) { nextToken(); windowType = parseSequenceType(); expect(Token.IN); nextToken(); clause.initSequence(flwor, parseExprSingle()); if (!isKeyword("start")) { grumble("in window clause, expected 'start', but found " + currentTokenDisplay()); nextToken(); if (t.currentToken == Token.DOLLAR) { LocalVariableBinding startItemVar = new LocalVariableBinding(readVariableName(), windowItemTypeMandatory); clause.setVariableBinding(WindowClause.START_ITEM, startItemVar); declareRangeVariable(startItemVar); if (isKeyword("at")) { nextToken(); LocalVariableBinding startPositionVar = new LocalVariableBinding(readVariableName(), SequenceType.SINGLE_INTEGER);
int offset = t.currentTokenStartOffset; if (t.currentToken == Token.FOR) { parseForClause(flwor, clauseList); } else if (t.currentToken == Token.LET) { parseLetClause(flwor, clauseList); } else if (t.currentToken == Token.COUNT) { parseCountClause(clauseList); } else if (t.currentToken == Token.GROUP_BY) { parseGroupByClause(flwor, clauseList); } else if (t.currentToken == Token.FOR_TUMBLING || t.currentToken == Token.FOR_SLIDING) { parseWindowClause(flwor, clauseList); } else if (t.currentToken == Token.WHERE || isKeyword("where")) { nextToken(); Expression condition = parseExprSingle(); WhereClause clause = new WhereClause(flwor, condition); clause.setRepeated(containsLoopingClause(clauseList)); clauseList.add(clause); foundWhere = true; } else if (isKeyword("stable") || isKeyword("order")) { if (isKeyword("stable")) { nextToken(); if (!isKeyword("order")) { grumble("'stable' must be followed by 'order by'"); List sortSpecList; t.setState(Tokenizer.BARE_NAME_STATE); nextToken(); if (!isKeyword("by")) {
do { ForClause clause = new ForClause(); clause.setRepeated(!first || containsLoopingClause(clauseList)); setLocation(clause, t.currentTokenStartOffset); if (first) { nextToken(); if (first) { first = false; expect(Token.DOLLAR); nextToken(); expect(Token.NAME); StructuredQName varQName = makeStructuredQName(t.currentTokenValue, ""); SequenceType type = SequenceType.SINGLE_ITEM; nextToken(); nextToken(); type = parseSequenceType(); if (isKeyword("allowing")) { allowingEmpty = true; clause.setAllowingEmpty(true); nextToken(); if (!isKeyword("empty")) { grumble("After 'allowing', expected 'empty'"); nextToken();
t.tokenize(Objects.requireNonNull(queryString), 0, -1); } catch (XPathException err) { grumble(err.getMessage()); parseVersionDeclaration(); allowSaxonExtensions = t.allowSaxonExtensions = qp.setAcceptEQName(true); qp.setUnescaper(new Unescaper(env.getConfiguration().getValidCharacterChecker())); setQNameParser(qp); parseProlog(); processPreamble(); Expression exp = parseExpression(); grumble("Unexpected token " + currentTokenDisplay() + " beyond end of query"); setLocation(exp); ExpressionTool.setDeepRetainedStaticContext(exp, env.makeRetainedStaticContext()); if (errorCount == 0) {
boolean scanOnly) throws XPathException { Location loc = makeLocation(); List<Expression> components = new ArrayList<>(10); addStringComponent(components, avt, last, i2); throw e; addStringComponent(components, avt, last, i8 + 1); last = i8 + 2; } else if (i1 >= 0 && i1 == i0) { // found a doubled "{{" addStringComponent(components, avt, last, i1 + 1); last = i1 + 2; } else if (i0 >= 0) { // found a single "{" if (i0 > last) { addStringComponent(components, avt, last, i0); XPathParser parser = newParser(); ((XQueryParser) parser).executable = executable; parser.setAllowAbsentExpression(allowXPath31Syntax); components.add(makeStringJoin(exp, env));
int equals = property.indexOf("="); if (equals < 0) { badOutputProperty("no equals sign"); } else if (equals == 0) { badOutputProperty("starts with '="); Properties props = getExecutable().getPrimarySerializationProperties().getProperties(); try { StructuredQName name = makeStructuredQName(keyword, ""); String lname = name.getLocalPart(); String uri = name.getURI(); env.getConfiguration()); } catch (XPathException e) { badOutputProperty(e.getMessage());
grumble("Default collation name '" + collationName + "' is not a valid URI", "XQST0046"); collationName = NamespaceConstant.CODEPOINT_COLLATION_URI; grumble("Default collation name '" + collationName + "' is not a recognized collation", "XQST0038"); collationName = NamespaceConstant.CODEPOINT_COLLATION_URI; applySchemaImport(imp); } catch (XPathException err) { if (!err.hasBeenReported()) { applyModuleImport(imp); } catch (XPathException err) { if (!err.hasBeenReported()) {
throw new XPathException("XQuery Update is supported only in Saxon-EE"); } else if (languageVersion == 31 || languageVersion == 30 || languageVersion == 10) { XQueryParser parser = new XQueryParser(); parser.setLanguage(XPathParser.XQUERY, 31); return parser; } else {
String uri = ((QueryModule) env).getModuleNamespace(); if (uri == null) { grumble("Module declaration must not be used in a main module"); } else { grumble("Module declaration appears more than once"); grumble("Module declaration must precede other declarations in the query prolog"); case Token.DECLARE_NAMESPACE: if (!allowDeclarations) { grumble("Namespace declarations cannot follow variables, functions, or options"); parseNamespaceDeclaration(); break; case Token.DECLARE_ANNOTATED: processPreamble(); if (allowDeclarations) { sealNamespaces(namespacesToBeSealed, env.getConfiguration()); allowDeclarations = false; nextToken(); expect(Token.PERCENT); AnnotationList annotationList = parseAnnotationsList(); if (isKeyword("function")) { annotationList.check(env.getConfiguration(), "DF"); parseFunctionDeclaration(annotationList); } else if (isKeyword("variable")) { annotationList.check(env.getConfiguration(), "DV");
setLocation(clause, t.currentTokenStartOffset); clause.setRepeated(containsLoopingClause(clauseList)); clause.setIsSlidingWindow(t.currentToken == Token.FOR_SLIDING); nextToken(); if (!isKeyword("window")) { grumble("after 'sliding' or 'tumbling', expected 'window', but found " + currentTokenDisplay()); nextToken(); StructuredQName windowVarName = readVariableName(); SequenceType windowType = SequenceType.ANY_SEQUENCE; if (t.currentToken == Token.AS) { nextToken(); windowType = parseSequenceType(); expect(Token.IN); nextToken(); clause.initSequence(flwor, parseExprSingle()); if (!isKeyword("start")) { grumble("in window clause, expected 'start', but found " + currentTokenDisplay()); nextToken(); if (t.currentToken == Token.DOLLAR) { LocalVariableBinding startItemVar = new LocalVariableBinding(readVariableName(), windowItemTypeMandatory); clause.setVariableBinding(WindowClause.START_ITEM, startItemVar); declareRangeVariable(startItemVar); if (isKeyword("at")) { nextToken(); LocalVariableBinding startPositionVar = new LocalVariableBinding(readVariableName(), SequenceType.SINGLE_INTEGER);
int offset = t.currentTokenStartOffset; if (t.currentToken == Token.FOR) { parseForClause(flwor, clauseList); } else if (t.currentToken == Token.LET) { parseLetClause(flwor, clauseList); } else if (t.currentToken == Token.COUNT) { parseCountClause(clauseList); } else if (t.currentToken == Token.GROUP_BY) { parseGroupByClause(flwor, clauseList); } else if (t.currentToken == Token.FOR_TUMBLING || t.currentToken == Token.FOR_SLIDING) { parseWindowClause(flwor, clauseList); } else if (t.currentToken == Token.WHERE || isKeyword("where")) { nextToken(); Expression condition = parseExprSingle(); WhereClause clause = new WhereClause(flwor, condition); clause.setRepeated(containsLoopingClause(clauseList)); clauseList.add(clause); foundWhere = true; } else if (isKeyword("stable") || isKeyword("order")) { if (isKeyword("stable")) { nextToken(); if (!isKeyword("order")) { grumble("'stable' must be followed by 'order by'"); List sortSpecList; t.setState(Tokenizer.BARE_NAME_STATE); nextToken(); if (!isKeyword("by")) {
do { ForClause clause = new ForClause(); clause.setRepeated(!first || containsLoopingClause(clauseList)); setLocation(clause, t.currentTokenStartOffset); if (first) { nextToken(); if (first) { first = false; expect(Token.DOLLAR); nextToken(); expect(Token.NAME); StructuredQName varQName = makeStructuredQName(t.currentTokenValue, ""); SequenceType type = SequenceType.SINGLE_ITEM; nextToken(); nextToken(); type = parseSequenceType(); if (isKeyword("allowing")) { allowingEmpty = true; clause.setAllowingEmpty(true); nextToken(); if (!isKeyword("empty")) { grumble("After 'allowing', expected 'empty'"); nextToken();
expect(Token.MODULE_NAMESPACE); nextToken(); expect(Token.NAME); String prefix = t.currentTokenValue; nextToken(); expect(Token.EQUALS); nextToken(); expect(Token.STRING_LITERAL); String uri = uriLiteral(t.currentTokenValue); checkProhibitedPrefixes(prefix, uri); if (uri.isEmpty()) { grumble("Module namespace cannot be \"\"", "XQST0088"); uri = "http://saxon.fallback.namespace/"; // for error recovery nextToken(); expect(Token.SEMICOLON); nextToken(); try { ((QueryModule) env).setModuleNamespace(uri); executable.addQueryLibraryModule((QueryModule) env); } catch (XPathException err) { err.setLocator(makeLocation()); reportError(err);
t.tokenize(Objects.requireNonNull(queryString), 0, -1); } catch (XPathException err) { grumble(err.getMessage()); parseVersionDeclaration(); allowSaxonExtensions = t.allowSaxonExtensions = qp.setAcceptEQName(true); qp.setUnescaper(new Unescaper(env.getConfiguration().getValidCharacterChecker())); setQNameParser(qp); parseProlog(); processPreamble(); Expression exp = parseExpression(); grumble("Unexpected token " + currentTokenDisplay() + " beyond end of query"); setLocation(exp); ExpressionTool.setDeepRetainedStaticContext(exp, env.makeRetainedStaticContext()); if (errorCount == 0) {