Class XQueryParser
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classNested classes/interfaces inherited from class net.sf.saxon.expr.parser.XPathParser
XPathParser.Accelerator, XPathParser.InlineFunctionDetails, XPathParser.NestedLocation, XPathParser.ParsedLanguage -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Executablefinal Set<NamespaceUri> static final StructuredQNameFields inherited from class net.sf.saxon.expr.parser.XPathParser
allowSaxonExtensions, allowXPath30XSLTExtensions, catchDepth, charChecker, codeInjector, env, inlineFunctionStack, language, languageVersion, parserExtension, qNameParser, rangeVariables, scanOnly, t -
Constructor Summary
ConstructorsConstructorDescriptionConstructor for internal use: this class should be instantiated via the QueryModule -
Method Summary
Modifier and TypeMethodDescriptionvoidapplySchemaImports(List<XQueryParser.Import> schemaImports) protected booleanTest whether the current token is one that can start a RelativePathExpression, satisfying the special rule for disambiguation after a lone leading slash.protected static booleancontainsLoopingClause(List<Clause> clauseList) static voidcreateRunTimeFunctionLibrary(QueryModule mainModule, Configuration config, Executable exec) protected voidCallback to tailor the tokenizerprotected voidensureSchemaAware(String featureName) Get the executable containing this expression.protected StringGet the current language (XPath or XQuery)protected booleanbooleanAsk whether the streaming option has been set, that is, whether subsequent calls on parseQuery() will compile queries to be capable of executing in streaming mode.protected LetExpressionMake a LetExpression.protected voidmakeSimpleContent(Expression content, SimpleNodeConstructor inst, int offset) Make the instructions for the children of a node with simple content (attribute, text, PI, etc)static ExpressionmakeStringJoin(Expression exp, StaticContext env) Make a string-join expression that concatenates the string-values of items in a sequence with intervening spaces.protected LiteralmakeStringLiteral(String token, boolean doUnescaping) Method to make a string literal from a token identified as a string literal.makeXQueryExpression(String query, QueryModule mainModule, Configuration config) Create an XQueryExpressionprotected AnnotationListParse the annotations that can appear in a variable or function declarationprotected ExpressionParse a node constructor.protected ExpressionParse an update map|array Expression.protected Expressionprotected ExpressionparseDirectElementConstructor(boolean isNested) Parse a direct element constructorprotected Expressionprotected ExpressionParse an Extension Expression.protected ExpressionParse a FLWOR expression.voidparseFunctionDeclaration(AnnotationList annotations) Parse a function declaration.protected voidparseItemTypeDeclaration(AnnotationList annotations) Parse a type alias declaration.final voidparseLibraryModule(String queryString, QueryModule env) Parse a library module.protected voidparseOutputDeclaration(StructuredQName varName, String value) protected voidParse the "declare revalidation" declaration.protected ExpressionParse a string constructor: introduced in XQuery 3.1.protected ExpressionParse a Switch Expression.protected ExpressionParse a Try/Catch Expression.protected ExpressionParse a Typeswitch Expression.protected ExpressionParse a Validate Expression.protected Stringprotected voidrequireXQuery(String construct) voidsetExecutable(Executable exec) Set the executable used for this query expressionvoidsetStreaming(boolean option) Say whether the query should be compiled and evaluated to use streaming.static Expressionstringify(Expression exp, boolean noNodeIfEmpty, StaticContext env) Convert an expression so it generates a space-separated sequence of stringsprotected voidtestPermittedAxis(int axis, String errorCode) protected StringUnescape character references and built-in entity references in a stringuriLiteral(String in) Handle a URI literal.Methods inherited from class net.sf.saxon.expr.parser.XPathParser
checkAllowedFunctionArgument, checkLanguageVersion30, checkLanguageVersion31, checkLanguageVersion40, checkLanguageVersion40, checkMapExtensions, checkSyntaxExtensions, currentTokenDisplay, declareRangeVariable, expect, expectKeyword, expectName, expectStringLiteral, findOuterRangeVariable, findOuterRangeVariable, findRangeVariable, gatherComponents, getCodeInjector, getMissingFunctionExplanation, getOffsetAfterParsing, getPlainType, getQNameParser, getRangeVariables, getStaticContext, getTokenizer, grumble, grumble, grumble, grumble, grumble, handleExternalFunctionDeclaration, isAllowAbsentExpression, isAllowArgumentKeywords, isAllowXPath31Syntax, isAllowXPath40Syntax, isKeyword, isKeyword, isKeywordPair, isNamespaceTestAllowed, isReservedFunctionName, isReservedInQuery, makeFingerprint, makeInlineFunctionValue, makeLocalQNameTest, makeLocation, makeLocation, makeLookupExpression, makeNamedFunctionReference, makeNamespaceQNameTest, makeNameTest, makeNestedLocation, makeNodeName, makeQNameTest, makeStructuredQName, makeStructuredQNameSilently, makeTracer, nextToken, notAllowedInPattern, parse, parseArrayCurlyConstructor, parseArrayItemType, parseArraySquareConstructor, parseArrowPostfix, parseBasicStep, parseBinaryExpression, parseConstant, parseDynamicFunctionCall, parseEnumType, parseEQName, parseExpression, parseExprSingle, parseExtendedSequenceType, parseFilterExprAM, parseFocusFunction, parseFunctionArgument, parseFunctionCall, parseFunctionItemType, parseInlineFunction, parseInlineFunctionBody, parseItemType, parseItemType, parseLookup, parseMapConstructor, parseMapItemType, parseMappingArrowPostfix, parseMethodCall, parseNamedFunctionReference, parseNameTestUnion, parseNodeTest, parseNumericLiteral, parseOccurrenceIndicator, parseParenthesizedExpression, parsePathExpression, parsePredicate, parsePredicate, parseRelativePath, parseRemainingPath, parseSequenceType, parseSequenceType, parseSimpleMappingExpression, parseStepExpression, parseStringLiteral, parseStringTemplate, parseUnionNodeTest, readKeyword, readName, readOptionalAsClause, readToken, readVariableName, reportMissingFunction, resolveFunctionName, resolveVariableReference, setAccelerator, setAllowAbsentExpression, setCatchDepth, setCodeInjector, setLanguage, setLocation, setLocation, setLocation, setParserExtension, setQNameParser, setRangeVariables, setRangeVariableStack, setScanOnly, tryKeyword, tryKeywordPair, undeclareRangeVariable, warning, whyDisallowedType
-
Field Details
-
executable
-
importedModules
-
SAXON_MEMO_FUNCTION
-
-
Constructor Details
-
XQueryParser
Constructor for internal use: this class should be instantiated via the QueryModule
-
-
Method Details
-
makeXQueryExpression
public XQueryExpression makeXQueryExpression(String query, QueryModule mainModule, Configuration config) throws XPathException Create an XQueryExpression- Parameters:
query- the source text of the querymainModule- the static context of the queryconfig- the Saxon configuration- Returns:
- the compiled XQuery expression
- Throws:
XPathException- if the expression contains static errors
-
createRunTimeFunctionLibrary
public static void createRunTimeFunctionLibrary(QueryModule mainModule, Configuration config, Executable exec) -
getExecutable
Get the executable containing this expression.- Returns:
- the executable
-
setExecutable
Set the executable used for this query expression- Parameters:
exec- the executable
-
customizeTokenizer
Callback to tailor the tokenizer- Overrides:
customizeTokenizerin classXPathParser- Parameters:
t- the Tokenizer to be customized
-
setStreaming
public void setStreaming(boolean option) Say whether the query should be compiled and evaluated to use streaming. This affects subsequent calls on the parseQuery() method. This option requires Saxon-EE.- Parameters:
option- if true, the compiler will attempt to compile a query to be capable of executing in streaming mode. If the query cannot be streamed, a compile-time exception is reported. In streaming mode, the source document is supplied as a stream, and no tree is built in memory. The default is false.- Since:
- 9.6
-
isStreaming
public boolean isStreaming()Ask whether the streaming option has been set, that is, whether subsequent calls on parseQuery() will compile queries to be capable of executing in streaming mode.- Returns:
- true if the streaming option has been set.
- Since:
- 9.6
-
parseLibraryModule
Parse a library module. Prolog? Expression- Parameters:
queryString- The text of the library module.env- The static context. The result of parsing a library module is that the static context is populated with a set of function declarations and variable declarations. Each library module must have its own static context objext.- Throws:
XPathException- if the expression contains a syntax error
-
parseAnnotationsList
Parse the annotations that can appear in a variable or function declaration- Overrides:
parseAnnotationsListin classXPathParser- Returns:
- the annotations as a list
- Throws:
XPathException- in the event of a syntax error
-
parseRevalidationDeclaration
Parse the "declare revalidation" declaration. Syntax: not allowed unless XQuery update is in use- Throws:
XPathException- if the syntax is incorrect, or is not allowed in this XQuery processor
-
ensureSchemaAware
- Throws:
XPathException
-
applySchemaImports
- Throws:
XPathException
-
parseFunctionDeclaration
Parse a function declaration.Syntax:
<"declare" "function"> QName "(" ParamList? ")" ("as" SequenceType)? (EnclosedExpr | "external")On entry, the "declare function" has already been recognized
- Parameters:
annotations- the list of annotations that have been encountered for this function declaration- Throws:
XPathException- if a syntax error is found
-
parseItemTypeDeclaration
Parse a type alias declaration. Allowed only in Saxon-PE and higher- Throws:
XPathException- if parsing fails
-
parseOutputDeclaration
- Throws:
XPathException
-
parseFLWORExpression
Parse a FLWOR expression. This replaces the XPath "for" expression. Full syntax:[41] FLWORExpr ::= (ForClause | LetClause)+ WhereClause? OrderByClause? "return" ExprSingle
[42] ForClause ::= <"for" "$"> VarName TypeDeclaration? PositionalVar? "in" ExprSingle ("," "$" VarName TypeDeclaration? PositionalVar? "in" ExprSingle)*
[43] PositionalVar ::= "at" "$" VarName
[44] LetClause ::= <"let" "$"> VarName TypeDeclaration? ":=" ExprSingle ("," "$" VarName TypeDeclaration? ":=" ExprSingle)*
[45] WhereClause ::= "where" Expr
[46] OrderByClause ::= (<"order" "by"> | <"stable" "order" "by">) OrderSpecList
[47] OrderSpecList ::= OrderSpec ("," OrderSpec)*
[48] OrderSpec ::= ExprSingle OrderModifier
[49] OrderModifier ::= ("ascending" | "descending")? (<"empty" "greatest"> | <"empty" "least">)? ("collation" StringLiteral)?- Overrides:
parseFLWORExpressionin classXPathParser- Returns:
- the resulting subexpression
- Throws:
XPathException- if any error is encountered
-
makeLetExpression
Make a LetExpression. This returns an ordinary LetExpression if tracing is off, and an EagerLetExpression if tracing is on. This is so that trace events occur in an order that the user can follow.- Returns:
- the constructed "let" expression
-
containsLoopingClause
-
makeStringJoin
Make a string-join expression that concatenates the string-values of items in a sequence with intervening spaces. This may be simplified later as a result of type-checking.- Parameters:
exp- the base expression, evaluating to a sequenceenv- the static context- Returns:
- a call on string-join to create a string containing the representations of the items in the sequence separated by spaces.
-
readCollationName
- Throws:
XPathException
-
parseTypeswitchExpression
Parse a Typeswitch Expression. This construct is XQuery-only. TypeswitchExpr ::= "typeswitch" "(" Expr ")" CaseClause+ "default" ("$" VarName)? "return" ExprSingle CaseClause ::= "case" ("$" VarName "as")? SequenceType "return" ExprSingle- Overrides:
parseTypeswitchExpressionin classXPathParser- Returns:
- the expression that results from the parsing
- Throws:
XPathException- if parsing fails
-
parseSwitchExpression
Parse a Switch Expression. This construct is XQuery-3.0-only. SwitchExpr ::= "switch" ("(" Expr ")")? SwitchCaseClause+ "default" "return" ExprSingle SwitchCaseClause ::= ("case" ExprSingle)+ "return" ExprSingle4.0 allows the parenthesized expression to be omitted, and also allows braces around the cases. This means there are three ways of recognizing the start of the expression: (a) "switch (", (b) "switch {" (c) "switch case"}
- Overrides:
parseSwitchExpressionin classXPathParser- Returns:
- the parsed expression
- Throws:
XPathException- in the event of a syntax error
-
parseValidateExpression
Parse a Validate Expression. This construct is XQuery-only. The syntax allows: validate mode? { Expr } mode ::= "strict" | "lax"- Overrides:
parseValidateExpressionin classXPathParser- Returns:
- the parsed expression; except that this version of the method always throws an exception
- Throws:
XPathException- if parsing fails
-
parseDeepUpdateExpression
Parse an update map|array Expression.- Overrides:
parseDeepUpdateExpressionin classXPathParser- Returns:
- the parsed expression; except that this version of the method always throws an exception
- Throws:
XPathException- if a static error is found
-
parseExtensionExpression
Parse an Extension Expression. Syntax: "(#" QName arbitrary-text "#)")+ "{" expr? "}" The pragma "(#...#)" is represented as a single token, which is the current token on entry to this method.- Overrides:
parseExtensionExpressionin classXPathParser- Returns:
- the parsed expression; except that this version of the method always throws an exception
- Throws:
XPathException- if parsing fails
-
isMaybeNamedConstructor
protected boolean isMaybeNamedConstructor()- Overrides:
isMaybeNamedConstructorin classXPathParser
-
parseComputedNodeConstructor
Parse a node constructor. This is allowed only in XQuery. This method handles the XQuery-based "computed" constructors, not the XML-style "direct" constructors. On entry the current token is the node-kind keyword such as "element" or "attribute".- Overrides:
parseComputedNodeConstructorin classXPathParser- Returns:
- an Expression for evaluating the parsed constructor
- Throws:
XPathException- in the event of a syntax error.
-
parseDirectPIConstructor
- Overrides:
parseDirectPIConstructorin classXPathParser- Throws:
XPathException
-
parseDirectCommentConstructor
- Throws:
XPathException
-
parseTryCatchExpression
Parse a Try/Catch Expression. This construct is XQuery-3.0 only. The syntax allows: try { Expr } catch NameTest ('|' NameTest)* { Expr } We don't currently implement the CatchVars- Overrides:
parseTryCatchExpressionin classXPathParser- Returns:
- the parsed expression; except that this version of the method always throws an exception
- Throws:
XPathException- if a static error is found
-
makeSimpleContent
Make the instructions for the children of a node with simple content (attribute, text, PI, etc)- Parameters:
content- the expression making up the simple contentinst- the skeletal instruction for creating the nodeoffset- the character position of this construct within the source query
-
parseDirectElementConstructor
Parse a direct element constructor- Overrides:
parseDirectElementConstructorin classXPathParser- Parameters:
isNested- true if this constructor is nested directly as part of the content of another element constructor. This has the effect that the child element is not copied, which means that namespace inheritance (which only happens during copying) has no effect- Returns:
- the expression representing the constructor
- Throws:
XPathException- if a syntax error is found
-
stringify
Convert an expression so it generates a space-separated sequence of strings- Parameters:
exp- the expression that calculates the contentnoNodeIfEmpty- if true, no node is produced when the value of the content expression is an empty sequence. If false, the effect of supplying an empty sequence is that a node is created whose string-value is a zero-length string. Set to true for text node constructors, false for other kinds of node.env- the static context- Returns:
- an expression that computes the content and converts the result to a character string
-
makeStringLiteral
Method to make a string literal from a token identified as a string literal. This is trivial in XPath, but in XQuery the method is overridden to identify pseudo-XML character and entity references- Overrides:
makeStringLiteralin classXPathParser- Parameters:
token- the string as written (or as returned by the tokenizer)doUnescaping- if true, XML escape sequences (`&#xHH;`, etc) are recognized and expanded.- Returns:
- The string value of the string literal, after dereferencing entity and character references
- Throws:
XPathException- if parsing fails
-
unescape
Unescape character references and built-in entity references in a string- Overrides:
unescapein classXPathParser- Parameters:
token- the input string, which may include XML-style character references or built-in entity references- Returns:
- the string with character references and built-in entity references replaced by their expansion
- Throws:
XPathException- if a malformed character or entity reference is found
-
parseStringConstructor
Parse a string constructor: introduced in XQuery 3.1. A StringConstructor is delimited by"``[ ... ]``"and contains embedded expressions signalled by"`{" Expr? "}`"- Overrides:
parseStringConstructorin classXPathParser- Throws:
XPathException
-
requireXQuery
- Overrides:
requireXQueryin classXPathParser- Throws:
XPathException
-
uriLiteral
Handle a URI literal. This is whitespace-normalized as well as being unescaped- Parameters:
in- the string as written- Returns:
- the URI after unescaping of entity and character references followed by whitespace normalization
- Throws:
XPathException- if an error is found while unescaping the URI
-
atStartOfRelativePath
protected boolean atStartOfRelativePath()Description copied from class:XPathParserTest whether the current token is one that can start a RelativePathExpression, satisfying the special rule for disambiguation after a lone leading slash.- Overrides:
atStartOfRelativePathin classXPathParser- Returns:
- true if the current token is to be interpreted as the start of a relative path expression.
-
testPermittedAxis
- Overrides:
testPermittedAxisin classXPathParser- Throws:
XPathException
-
getLanguage
Get the current language (XPath or XQuery)- Overrides:
getLanguagein classXPathParser- Returns:
- a string representation of the language being parsed, for use in error messages
-