Package net.sf.saxon.query
Class QueryParser
java.lang.Object
net.sf.saxon.expr.ExpressionParser
net.sf.saxon.query.QueryParser
This class defines extensions to the XPath parser to handle the additional
syntax supported in XQuery
-
Nested Class Summary
Nested classes/interfaces inherited from class net.sf.saxon.expr.ExpressionParser
ExpressionParser.ForClause, ExpressionParser.TemporaryContainer
-
Field Summary
FieldsFields inherited from class net.sf.saxon.expr.ExpressionParser
compileWithTracing, env, language, nameChecker, rangeVariables, scanOnly, SEQUENCE_TYPE, t, XPATH, XQUERY, XSLT_PATTERN
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor for internal use: this class should be instantiated via the QueryModule -
Method Summary
Modifier and TypeMethodDescriptionvoid
applyModuleImport
(net.sf.saxon.query.QueryParser.Import mImport) Get the executable containing this expression.protected String
Get the current language (XPath or XQuery)protected void
Report a static errorstatic 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
(String token) Method to make a string literal from a token identified as a string literal.makeXQueryExpression
(String query, QueryModule staticContext, Configuration config) Create an XQueryExpressionprotected Expression
Parse a node constructor.protected Expression
Parse an Extension Expression.protected Expression
Parse a FLWOR expression.protected void
parseFunctionDeclaration
(boolean isUpdating) Parse a function declaration.final void
parseLibraryModule
(String queryString, QueryModule env) Parse a library module.protected void
Parse the "declare revalidation" declaration.protected Expression
Parse a Typeswitch Expression.protected void
Parse an updating function declaration (allowed in XQuery Update only)protected Expression
Parse a Validate Expression.setDefaultValue
(String exp) Parse the expression (inside a string literal) used to define default values for external variables.void
setDisableCycleChecks
(boolean disable) Disable checks for certain kinds of cycle.void
setExecutable
(Executable exec) Set the executable used for this query expressionMethods inherited from class net.sf.saxon.expr.ExpressionParser
currentTokenDisplay, declareRangeVariable, expect, getRangeVariableStack, getTokenizer, grumble, isCompileWithTracing, isKeyword, makeLocalNameTest, makeNameCode, makeNameCodeSilently, makeNamespaceTest, makeNameTest, makeStructuredQName, makeTracer, nextToken, parse, parseExpression, parseExprSingle, parseFunctionCall, parseMappingExpression, parseNodeTest, parsePattern, parseRelativePath, parseRemainingPath, parseSequenceType, parseSequenceType, parseStepExpression, setCompileWithTracing, setLocation, setLocation, setRangeVariableStack, setScanOnly, undeclareRangeVariable, warning
-
Field Details
-
executable
-
importedModules
-
-
Constructor Details
-
QueryParser
public QueryParser()Constructor for internal use: this class should be instantiated via the QueryModule
-
-
Method Details
-
makeXQueryExpression
public XQueryExpression makeXQueryExpression(String query, QueryModule staticContext, Configuration config) throws XPathException Create an XQueryExpression- Parameters:
query
- the source text of the querystaticContext
- the static context of the queryconfig
- the Saxon configuration- Returns:
- the compiled XQuery expression
- Throws:
XPathException
-
getExecutable
Get the executable containing this expression.- Returns:
- the executable
-
setExecutable
Set the executable used for this query expression- Parameters:
exec
- the executable
-
setDisableCycleChecks
public void setDisableCycleChecks(boolean disable) Disable checks for certain kinds of cycle. This is equivalent todeclare option saxon:allow-cycles "true"
- Parameters:
disable
- true if checks for import cycles are to be suppressed, that is, if cycles should be allowed
-
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
-
grumble
Report a static error- Overrides:
grumble
in classExpressionParser
- Parameters:
message
- the error messageerrorCode
- the error code- Throws:
XPathException
- always thrown: an exception containing the supplied message
-
parseRevalidationDeclaration
Parse the "declare revalidation" declaration. Syntax: not allowed unless XQuery update is in use- Throws:
XPathException
-
applyModuleImport
- Throws:
XPathException
-
parseFunctionDeclaration
Parse a function declaration.Syntax:
<"declare" "function"> <QName "("> ParamList? (")" | (<")" "as"> SequenceType)) (EnclosedExpr | "external")On entry, the "define function" has already been recognized
- Throws:
XPathException
- if a syntax error is found
-
parseUpdatingFunctionDeclaration
Parse an updating function declaration (allowed in XQuery Update only)- Throws:
XPathException
-
setDefaultValue
Parse the expression (inside a string literal) used to define default values for external variables. This requires instantiating a nested XPath parser.- Parameters:
exp
- holds the expression used to define a default value- Returns:
- the compiled expression that computes the default value
-
parseForExpression
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:
parseForExpression
in classExpressionParser
- Returns:
- the resulting subexpression
- Throws:
XPathException
- if any error is encountered
-
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.
-
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:
parseTypeswitchExpression
in classExpressionParser
- Returns:
- the expression that results from the parsing
- Throws:
XPathException
-
parseValidateExpression
Parse a Validate Expression. This construct is XQuery-only. The syntax allows: validate mode? { Expr } mode ::= "strict" | "lax"- Overrides:
parseValidateExpression
in classExpressionParser
- Returns:
- the parsed expression; except that this version of the method always throws an exception
- Throws:
XPathException
-
parseExtensionExpression
Parse an Extension Expression. Syntax: "(#" QName arbitrary-text "#)")+ "{" expr? "}"- Overrides:
parseExtensionExpression
in classExpressionParser
- Returns:
- the parsed expression; except that this version of the method always throws an exception
- Throws:
XPathException
-
parseConstructor
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 classExpressionParser
- Returns:
- an Expression for evaluating the parsed constructor
- Throws:
XPathException
- in the event of a syntax error.
-
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:
makeStringLiteral
in classExpressionParser
- 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
-
getLanguage
Get the current language (XPath or XQuery)- Overrides:
getLanguage
in classExpressionParser
- Returns:
- a string representation of the language being parsed, for use in error messages
-