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
FieldsModifier and TypeFieldDescriptionprotected Executable
(package private) List
(package private) List
(package private) List
Fields inherited from class net.sf.saxon.expr.ExpressionParser
env, language, nameChecker, rangeVariables, scanOnly, SEQUENCE_TYPE, t, XPATH, XQUERY, XSLT_PATTERN
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Protected Constructor: this class should be instantiated via the StaticQueryContext -
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 StringValue
makeStringLiteral
(String token) Method to make a string literal from a token identified as a string literal.makeXQueryExpression
(String query, StaticQueryContext staticContext, Configuration config) Create an XQueryExpressionprotected Expression
Parse a node constructor.protected Expression
Parse an Extension Expression.protected Expression
Parse a FLWOR expression.final void
parseLibraryModule
(String queryString, StaticQueryContext env) Parse a library module.protected Expression
Parse a Typeswitch Expression.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
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, isKeyword, makeLocalNameTest, makeNameCode, makeNamespaceTest, makeNameTest, makeTracer, nextToken, parse, parseExpression, parseExprSingle, parseFunctionCall, parseMappingExpression, parseNodeTest, parsePattern, parseRelativePath, parseRemainingPath, parseSequenceType, parseSequenceType, parseStepExpression, setLocation, setLocation, setRangeVariableStack, setScanOnly, undeclareRangeVariable, warning
-
Field Details
-
Constructor Details
-
QueryParser
protected QueryParser()Protected Constructor: this class should be instantiated via the StaticQueryContext
-
-
Method Details
-
makeXQueryExpression
public XQueryExpression makeXQueryExpression(String query, StaticQueryContext staticContext, Configuration config) throws XPathException Create an XQueryExpression- Throws:
XPathException
-
getExecutable
Get the executable containing this expression. -
setExecutable
Set the executable used for this query expression -
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:
StaticError
- 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:
StaticError
- always thrown: an exception containing the supplied message
-
applyModuleImport
- Throws:
StaticError
-
setDefaultValue
Parse the expression (inside a string literal) used to define default values for external variables. This requires instantiating a nested XPath parser. -
parseForExpression
Parse a FLWOR expression. This replaces the XPath "for" expression. Full syntax: [41] FLWORExpr ::= (ForClause | LetClause)+ WhereClause? OrderByClause? "return" ExprSingle [42] ForClause ::= invalid input: '<'"for" "$"> VarName TypeDeclaration? PositionalVar? "in" ExprSingle ("," "$" VarName TypeDeclaration? PositionalVar? "in" ExprSingle)* [43] PositionalVar ::= "at" "$" VarName [44] LetClause ::= invalid input: '<'"let" "$"> VarName TypeDeclaration? ":=" ExprSingle ("," "$" VarName TypeDeclaration? ":=" ExprSingle)* [45] WhereClause ::= "where" Expr [46] OrderByClause ::= (invalid input: '<'"order" "by"> | invalid input: '<'"stable" "order" "by">) OrderSpecList [47] OrderSpecList ::= OrderSpec ("," OrderSpec)* [48] OrderSpec ::= ExprSingle OrderModifier [49] OrderModifier ::= ("ascending" | "descending")? (invalid input: '<'"empty" "greatest"> | invalid input: '<'"empty" "least">)? ("collation" StringLiteral)?- Overrides:
parseForExpression
in classExpressionParser
- Returns:
- the resulting subexpression
- Throws:
StaticError
- 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. -
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
- Throws:
StaticError
-
parseValidateExpression
Parse a Validate Expression. This construct is XQuery-only. The syntax allows: validate mode? { Expr } mode ::= "strict" | "lax"- Overrides:
parseValidateExpression
in classExpressionParser
- Throws:
StaticError
-
parseExtensionExpression
Parse an Extension Expression. Syntax: "(#" QName arbitrary-text "#)")+ "{" expr? "}"- Overrides:
parseExtensionExpression
in classExpressionParser
- Throws:
StaticError
-
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:
StaticError
- 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
-- Returns:
- The string value of the string literal, after dereferencing entity and character references
- Throws:
StaticError
-
getLanguage
Get the current language (XPath or XQuery)- Overrides:
getLanguage
in classExpressionParser
-