Class XQueryParser
- java.lang.Object
-
- net.sf.saxon.expr.parser.XPathParser
-
- net.sf.saxon.query.XQueryParser
-
public class XQueryParser extends XPathParser
This class defines extensions to the XPath parser to handle the additional syntax supported in XQuery
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XQueryParser.Unescaper
-
Nested classes/interfaces inherited from class net.sf.saxon.expr.parser.XPathParser
XPathParser.Accelerator, XPathParser.NestedLocation, XPathParser.ParsedLanguage
-
-
Field Summary
Fields Modifier and Type Field Description protected Executable
executable
java.util.Set<java.lang.String>
importedModules
static StructuredQName
SAXON_MEMO_FUNCTION
static java.lang.String
XQUERY10
static java.lang.String
XQUERY30
static java.lang.String
XQUERY31
-
Fields inherited from class net.sf.saxon.expr.parser.XPathParser
allowSaxonExtensions, allowXPath30Syntax, allowXPath30XSLTExtensions, allowXPath31Syntax, catchDepth, charChecker, codeInjector, env, language, languageVersion, parserExtension, qNameParser, rangeVariables, scanOnly, t
-
-
Constructor Summary
Constructors Constructor Description XQueryParser()
Constructor for internal use: this class should be instantiated via the QueryModule
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyModuleImport(net.sf.saxon.query.XQueryParser.Import mImport)
protected boolean
atStartOfRelativePath()
Test whether the current token is one that can start a RelativePathExpressionprotected static boolean
containsLoopingClause(java.util.List<Clause> clauseList)
protected void
customizeTokenizer(Tokenizer t)
Callback to tailor the tokenizerprotected void
ensureSchemaAware(java.lang.String featureName)
Executable
getExecutable()
Get the executable containing this expression.protected java.lang.String
getLanguage()
Get the current language (XPath or XQuery)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.protected void
lookAhead()
Lookahead one token, catching any exception thrown by the tokenizer.protected LetExpression
makeLetExpression()
Make a LetExpression.protected void
makeSimpleContent(Expression content, SimpleNodeConstructor inst, int offset)
Make the instructions for the children of a node with simple content (attribute, text, PI, etc)static Expression
makeStringJoin(Expression exp, StaticContext env)
Make a string-join expression that concatenates the string-values of items in a sequence with intervening spaces.protected Literal
makeStringLiteral(java.lang.String token, boolean doUnescaping)
Method to make a string literal from a token identified as a string literal.XQueryExpression
makeXQueryExpression(java.lang.String query, QueryModule mainModule, Configuration config)
Create an XQueryExpressionprotected AnnotationList
parseAnnotationsList()
Parse the annotations that can appear in a variable or function declarationprotected Expression
parseConstructor()
Parse a node constructor.protected Expression
parseExtensionExpression()
Parse an Extension Expression.protected Expression
parseFLWORExpression()
Parse a FLWOR expression.void
parseFunctionDeclaration(AnnotationList annotations)
Parse a function declaration.void
parseLibraryModule(java.lang.String queryString, QueryModule env)
Parse a library module.protected void
parseOutputDeclaration(StructuredQName varName, java.lang.String value)
protected void
parseRevalidationDeclaration()
Parse the "declare revalidation" declaration.Expression
parseStringConstructor()
Parse a string constructor: introduced in XQuery 3.1protected Expression
parseSwitchExpression()
Parse a Switch Expression.protected Expression
parseTryCatchExpression()
Parse a Try/Catch Expression.protected void
parseTypeAliasDeclaration()
Parse a type alias declaration.protected Expression
parseTypeswitchExpression()
Parse a Typeswitch Expression.protected Expression
parseValidateExpression()
Parse a Validate Expression.protected java.lang.String
readCollationName()
void
setExecutable(Executable exec)
Set the executable used for this query expressionvoid
setStreaming(boolean option)
Say whether the query should be compiled and evaluated to use streaming.static Expression
stringify(Expression exp, boolean noNodeIfEmpty, StaticContext env)
Convert an expression so it generates a space-separated sequence of stringsprotected void
testPermittedAxis(int axis, java.lang.String errorCode)
protected java.lang.CharSequence
unescape(java.lang.String token)
Unescape character references and built-in entity references in a stringjava.lang.String
uriLiteral(java.lang.String in)
Handle a URI literal.-
Methods inherited from class net.sf.saxon.expr.parser.XPathParser
checkLanguageVersion30, checkLanguageVersion31, checkMapExtensions, checkSyntaxExtensions, currentTokenDisplay, declareRangeVariable, disallowedAtStartOfRelativePath, expect, findRangeVariable, generateApplyCall, getCodeInjector, getMissingFunctionExplanation, getPlainType, getQNameParser, getRangeVariables, getStaticContext, getTokenizer, grumble, grumble, grumble, grumble, isAllowAbsentExpression, isAllowXPath31Syntax, isKeyword, isNamespaceTestAllowed, isReservedFunctionName30, isReservedFunctionName31, isReservedInQuery, makeCurriedFunction, makeFingerprint, makeLocalNameTest, makeLocation, makeLocation, makeNamespaceTest, makeNameTest, makeNestedLocation, makeNodeName, makeQNameTest, makeStructuredQName, makeStructuredQNameSilently, makeTracer, nextToken, operatorPrecedence, parse, parseArrayCurlyConstructor, parseArrayItemType, parseArraySquareConstructor, parseArrowPostfix, parseBackTickedStringLiteral, parseBasicStep, parseBinaryExpression, parseDynamicFunctionCall, parseExpression, parseExprSingle, parseExtendedItemType, parseExtendedSequenceType, parseFunctionArgument, parseFunctionCall, parseFunctionItemType, parseInlineFunction, parseItemType, parseLookup, parseMapExpression, parseMapItemType, parseNamedFunctionReference, parseNodeTest, parseNumericLiteral, parseParenthesizedExpression, parsePathExpression, parsePredicate, parsePredicate, parseRelativePath, parseRemainingPath, parseSequenceType, parseSequenceType, parseSimpleMappingExpression, parseStepExpression, parseStringLiteral, parseVariableReference, reportMissingFunction, resolveFunctionName, setAccelerator, setAllowAbsentExpression, setCatchDepth, setCodeInjector, setLanguage, setLocation, setLocation, setLocation, setParserExtension, setQNameParser, setRangeVariables, setRangeVariableStack, setScanOnly, undeclareRangeVariable, warning, whyDisallowedType
-
-
-
-
Field Detail
-
XQUERY10
public static final java.lang.String XQUERY10
- See Also:
- Constant Field Values
-
XQUERY30
public static final java.lang.String XQUERY30
- See Also:
- Constant Field Values
-
XQUERY31
public static final java.lang.String XQUERY31
- See Also:
- Constant Field Values
-
executable
protected Executable executable
-
importedModules
public final java.util.Set<java.lang.String> importedModules
-
SAXON_MEMO_FUNCTION
public static final StructuredQName SAXON_MEMO_FUNCTION
-
-
Method Detail
-
makeXQueryExpression
public XQueryExpression makeXQueryExpression(java.lang.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
-
getExecutable
public Executable getExecutable()
Get the executable containing this expression.- Returns:
- the executable
-
setExecutable
public void setExecutable(Executable exec)
Set the executable used for this query expression- Parameters:
exec
- the executable
-
customizeTokenizer
protected void customizeTokenizer(Tokenizer t)
Callback to tailor the tokenizer- Overrides:
customizeTokenizer
in 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
public final void parseLibraryModule(java.lang.String queryString, QueryModule env) throws XPathException
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
protected AnnotationList parseAnnotationsList() throws XPathException
Parse the annotations that can appear in a variable or function declaration- Overrides:
parseAnnotationsList
in classXPathParser
- Returns:
- the annotations as a list
- Throws:
XPathException
- in the event of a syntax error
-
parseRevalidationDeclaration
protected void parseRevalidationDeclaration() throws XPathException
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
protected void ensureSchemaAware(java.lang.String featureName) throws XPathException
- Throws:
XPathException
-
applyModuleImport
public void applyModuleImport(net.sf.saxon.query.XQueryParser.Import mImport) throws XPathException
- Throws:
XPathException
-
parseFunctionDeclaration
public void parseFunctionDeclaration(AnnotationList annotations) throws XPathException
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
-
parseTypeAliasDeclaration
protected void parseTypeAliasDeclaration() throws XPathException
Parse a type alias declaration. Allowed only in Saxon-PE and higher- Throws:
XPathException
- if parsing fails
-
parseOutputDeclaration
protected void parseOutputDeclaration(StructuredQName varName, java.lang.String value) throws XPathException
- Throws:
XPathException
-
parseFLWORExpression
protected Expression parseFLWORExpression() throws XPathException
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:
parseFLWORExpression
in classXPathParser
- Returns:
- the resulting subexpression
- Throws:
XPathException
- if any error is encountered
-
makeLetExpression
protected LetExpression 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
protected static boolean containsLoopingClause(java.util.List<Clause> clauseList)
-
makeStringJoin
public static Expression makeStringJoin(Expression exp, StaticContext env)
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
protected java.lang.String readCollationName() throws XPathException
- Throws:
XPathException
-
parseTypeswitchExpression
protected Expression parseTypeswitchExpression() throws XPathException
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:
parseTypeswitchExpression
in classXPathParser
- Returns:
- the expression that results from the parsing
- Throws:
XPathException
- if parsing fails
-
parseSwitchExpression
protected Expression parseSwitchExpression() throws XPathException
Parse a Switch Expression. This construct is XQuery-3.0-only. SwitchExpr ::= "switch" "(" Expr ")" SwitchCaseClause+ "default" "return" ExprSingle SwitchCaseClause ::= ("case" ExprSingle)+ "return" ExprSingle- Overrides:
parseSwitchExpression
in classXPathParser
- Returns:
- the parsed expression
- Throws:
XPathException
- in the event of a syntax error
-
parseValidateExpression
protected Expression parseValidateExpression() throws XPathException
Parse a Validate Expression. This construct is XQuery-only. The syntax allows: validate mode? { Expr } mode ::= "strict" | "lax"- Overrides:
parseValidateExpression
in classXPathParser
- Returns:
- the parsed expression; except that this version of the method always throws an exception
- Throws:
XPathException
- if parsing fails
-
parseExtensionExpression
protected Expression parseExtensionExpression() throws XPathException
Parse an Extension Expression. Syntax: "(#" QName arbitrary-text "#)")+ "{" expr? "}"- Overrides:
parseExtensionExpression
in classXPathParser
- Returns:
- the parsed expression; except that this version of the method always throws an exception
- Throws:
XPathException
- if parsing fails
-
parseConstructor
protected Expression parseConstructor() throws XPathException
Parse a node constructor. This is allowed only in XQuery. This method handles both the XML-like "direct" constructors, and the XQuery-based "computed" constructors.- Overrides:
parseConstructor
in classXPathParser
- Returns:
- an Expression for evaluating the parsed constructor
- Throws:
XPathException
- in the event of a syntax error.
-
parseTryCatchExpression
protected Expression parseTryCatchExpression() throws XPathException
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:
parseTryCatchExpression
in 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
protected void makeSimpleContent(Expression content, SimpleNodeConstructor inst, int offset)
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
-
stringify
public static Expression stringify(Expression exp, boolean noNodeIfEmpty, StaticContext env)
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
protected Literal makeStringLiteral(java.lang.String token, boolean doUnescaping) throws XPathException
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:
makeStringLiteral
in classXPathParser
- Parameters:
token
- the string as written (or as returned by the tokenizer)- Returns:
- The string value of the string literal, after dereferencing entity and character references
- Throws:
XPathException
- if parsing fails
-
unescape
protected java.lang.CharSequence unescape(java.lang.String token) throws XPathException
Unescape character references and built-in entity references in a string- Overrides:
unescape
in 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
public Expression parseStringConstructor() throws XPathException
Parse a string constructor: introduced in XQuery 3.1- Overrides:
parseStringConstructor
in classXPathParser
- Throws:
XPathException
-
uriLiteral
public java.lang.String uriLiteral(java.lang.String in) throws XPathException
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
-
lookAhead
protected void lookAhead() throws XPathException
Lookahead one token, catching any exception thrown by the tokenizer. This method is only called from the query parser when switching from character-at-a-time mode to tokenizing mode- Throws:
XPathException
- if parsing fails
-
atStartOfRelativePath
protected boolean atStartOfRelativePath()
Description copied from class:XPathParser
Test whether the current token is one that can start a RelativePathExpression- Overrides:
atStartOfRelativePath
in classXPathParser
- Returns:
- the resulting subexpression
-
testPermittedAxis
protected void testPermittedAxis(int axis, java.lang.String errorCode) throws XPathException
- Overrides:
testPermittedAxis
in classXPathParser
- Throws:
XPathException
-
getLanguage
protected java.lang.String getLanguage()
Get the current language (XPath or XQuery)- Overrides:
getLanguage
in classXPathParser
- Returns:
- a string representation of the language being parsed, for use in error messages
-
-