net.sf.saxon.query

Class QueryParser

class QueryParser extends ExpressionParser

This class defines extensions to the XPath parser to handle the additional syntax supported in XQuery
Field Summary
protected Executableexecutable
SetimportedModules
ListmoduleImports
ListnamespacesToBeSealed
ListschemaImports
Constructor Summary
protected QueryParser()
Protected Constructor: this class should be instantiated via the StaticQueryContext
Method Summary
voidapplyModuleImport(QueryParser.Import mImport)
ExecutablegetExecutable()
Get the executable containing this expression.
protected StringgetLanguage()
Get the current language (XPath or XQuery)
protected voidgrumble(String message, String errorCode)
Report a static error
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 StringValuemakeStringLiteral(String token)
Method to make a string literal from a token identified as a string literal.
XQueryExpressionmakeXQueryExpression(String query, StaticQueryContext staticContext, Configuration config)
Create an XQueryExpression
protected ExpressionparseConstructor()
Parse a node constructor.
protected ExpressionparseExtensionExpression()
Parse an Extension Expression.
protected ExpressionparseForExpression()
Parse a FLWOR expression.
voidparseLibraryModule(String queryString, StaticQueryContext env)
Parse a library module.
protected ExpressionparseTypeswitchExpression()
Parse a Typeswitch Expression.
protected ExpressionparseValidateExpression()
Parse a Validate Expression.
ExpressionsetDefaultValue(String exp)
Parse the expression (inside a string literal) used to define default values for external variables.
voidsetExecutable(Executable exec)
Set the executable used for this query expression

Field Detail

executable

protected Executable executable

importedModules

public Set importedModules

moduleImports

List moduleImports

namespacesToBeSealed

List namespacesToBeSealed

schemaImports

List schemaImports

Constructor Detail

QueryParser

protected QueryParser()
Protected Constructor: this class should be instantiated via the StaticQueryContext

Method Detail

applyModuleImport

public void applyModuleImport(QueryParser.Import mImport)

getExecutable

public Executable getExecutable()
Get the executable containing this expression.

getLanguage

protected String getLanguage()
Get the current language (XPath or XQuery)

grumble

protected void grumble(String message, String errorCode)
Report a static error

Parameters: message the error message

Throws: net.sf.saxon.trans.StaticError always thrown: an exception containing the supplied message

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.

makeStringLiteral

protected StringValue makeStringLiteral(String token)
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

Parameters: token

Returns: The string value of the string literal, after dereferencing entity and character references

makeXQueryExpression

public XQueryExpression makeXQueryExpression(String query, StaticQueryContext staticContext, Configuration config)
Create an XQueryExpression

parseConstructor

protected Expression 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.

Returns: an Expression for evaluating the parsed constructor

Throws: net.sf.saxon.trans.StaticError in the event of a syntax error.

parseExtensionExpression

protected Expression parseExtensionExpression()
Parse an Extension Expression. Syntax: "(#" QName arbitrary-text "#)")+ "{" expr? "}"

parseForExpression

protected Expression 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)?

Returns: the resulting subexpression

Throws: net.sf.saxon.trans.StaticError if any error is encountered

parseLibraryModule

public final void parseLibraryModule(String queryString, StaticQueryContext env)
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: net.sf.saxon.trans.StaticError if the expression contains a syntax error

parseTypeswitchExpression

protected Expression parseTypeswitchExpression()
Parse a Typeswitch Expression. This construct is XQuery-only. TypeswitchExpr ::= "typeswitch" "(" Expr ")" CaseClause+ "default" ("$" VarName)? "return" ExprSingle CaseClause ::= "case" ("$" VarName "as")? SequenceType "return" Expr

parseValidateExpression

protected Expression parseValidateExpression()
Parse a Validate Expression. This construct is XQuery-only. The syntax allows: validate mode? { Expr } mode ::= "strict" | "lax"

setDefaultValue

public Expression setDefaultValue(String exp)
Parse the expression (inside a string literal) used to define default values for external variables. This requires instantiating a nested XPath parser.

setExecutable

public void setExecutable(Executable exec)
Set the executable used for this query expression