net.sf.saxon.query

Class QueryParser

public class QueryParser extends ExpressionParser

This class defines extensions to the XPath parser to handle the additional syntax supported in XQuery
Nested Class Summary
protected static classQueryParser.LetClause
Field Summary
protected Executableexecutable
SetimportedModules
ListmoduleImports
ListnamespacesToBeSealed
protected StringqueryVersion
ListschemaImports
Constructor Summary
QueryParser()
Constructor for internal use: this class should be instantiated via the QueryModule
Method Summary
voidapplyModuleImport(QueryParser.Import mImport)
ExecutablegetExecutable()
Get the executable containing this expression.
protected StringgetLanguage()
Get the current language (XPath or XQuery)
intgetPermittedFunctions()
Get the permitted set of standard functions in this environment
protected voidgrumble(String message, StructuredQName errorCode)
Report a static error
protected voidlookAhead()
Lookahead one token, catching any exception thrown by the tokenizer.
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)
Method to make a string literal from a token identified as a string literal.
XQueryExpressionmakeXQueryExpression(String query, QueryModule staticContext, Configuration config)
Create an XQueryExpression
QueryParsernewParser()
Create a new parser of the same kind
protected ExpressionparseConstructor()
Parse a node constructor.
protected voidparseContextItemDeclaration()
Parse a context item declaration.
protected voidparseDecimalFormatDeclaration()
Parse the "declare decimal-format" declaration.
protected voidparseDefaultDecimalFormat()
protected ExpressionparseExtensionExpression()
Parse an Extension Expression.
protected ExpressionparseForExpression()
Parse a FLWOR expression.
protected voidparseFunctionDeclaration(boolean isUpdating)
Parse a function declaration.
protected voidparseGroupByClause(List clauseList)
Parse a Group By clause.
voidparseLibraryModule(String queryString, QueryModule env)
Parse a library module.
protected ExpressionparseNamedNamespaceConstructor(int offset)
protected ExpressionparseNamespaceConstructor(int offset)
protected voidparseOuterForClause(List clauseList)
Parse an "outer for" clause - XQuery 1.1 only
protected voidparseRevalidationDeclaration()
Parse the "declare revalidation" declaration.
protected ExpressionparseTypeswitchExpression()
Parse a Typeswitch Expression.
protected voidparseUpdatingFunctionDeclaration()
Parse an updating function declaration (allowed in XQuery Update only)
protected ExpressionparseValidateExpression()
Parse a Validate Expression.
protected ExpressionprocessGroupingExpression(List<FLWORClause> clauseList, Expression action)
Process a grouping expression Not supported in 1.0; subclassed in the XQuery 1.1 parser
protected StringreadCollationName()
ExpressionsetDefaultValue(String exp)
Parse the expression (inside a string literal) used to define default values for external variables.
voidsetDisableCycleChecks(boolean disable)
Disable checks for certain kinds of cycle.
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

queryVersion

protected String queryVersion

schemaImports

List schemaImports

Constructor Detail

QueryParser

public QueryParser()
Constructor for internal use: this class should be instantiated via the QueryModule

Method Detail

applyModuleImport

public void applyModuleImport(QueryParser.Import mImport)

getExecutable

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

Returns: the executable

getLanguage

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

getPermittedFunctions

public int getPermittedFunctions()
Get the permitted set of standard functions in this environment

grumble

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

Parameters: message the error message

Throws: XPathException always thrown: an exception containing the supplied message

lookAhead

protected void lookAhead()
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

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 content inst the skeletal instruction for creating the node offset the character position of this construct within the source query

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 sequence env 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.

makeStringLiteral

protected Literal 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 the string as written (or as returned by the tokenizer)

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

makeXQueryExpression

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

Parameters: query the source text of the query staticContext the static context of the query config the Saxon configuration

Returns: the compiled XQuery expression

newParser

public QueryParser newParser()
Create a new parser of the same kind

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: XPathException in the event of a syntax error.

parseContextItemDeclaration

protected void parseContextItemDeclaration()
Parse a context item declaration. Allowed only in XQuery 1.1

parseDecimalFormatDeclaration

protected void parseDecimalFormatDeclaration()
Parse the "declare decimal-format" declaration. Allowed in XQuery 1.1 only

parseDefaultDecimalFormat

protected void parseDefaultDecimalFormat()

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: XPathException if any error is encountered

parseFunctionDeclaration

protected void parseFunctionDeclaration(boolean isUpdating)
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

parseGroupByClause

protected void parseGroupByClause(List clauseList)
Parse a Group By clause. Not supported in 1.0; subclassed in the XQuery 1.1 parser

Throws: XPathException

parseLibraryModule

public final void parseLibraryModule(String queryString, QueryModule 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: XPathException if the expression contains a syntax error

parseNamedNamespaceConstructor

protected Expression parseNamedNamespaceConstructor(int offset)

parseNamespaceConstructor

protected Expression parseNamespaceConstructor(int offset)

parseOuterForClause

protected void parseOuterForClause(List clauseList)
Parse an "outer for" clause - XQuery 1.1 only

Parameters: clauseList

Throws: XPathException

parseRevalidationDeclaration

protected void parseRevalidationDeclaration()
Parse the "declare revalidation" declaration. Syntax: not allowed unless XQuery update is in use

Throws: XPathException

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" ExprSingle

parseUpdatingFunctionDeclaration

protected void parseUpdatingFunctionDeclaration()
Parse an updating function declaration (allowed in XQuery Update only)

parseValidateExpression

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

processGroupingExpression

protected Expression processGroupingExpression(List<FLWORClause> clauseList, Expression action)
Process a grouping expression Not supported in 1.0; subclassed in the XQuery 1.1 parser

Parameters: clauseList the list of clauses (for, let, group by) action the return clause, optionally wrapped with if-then-else to reflect the where clause

Throws: XPathException

readCollationName

protected String readCollationName()

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.

Parameters: exp holds the expression used to define a default value

Returns: the compiled expression that computes the default value

setDisableCycleChecks

public void setDisableCycleChecks(boolean disable)
Disable checks for certain kinds of cycle. This is equivalent to

declare option saxon:allow-cycles "true"

Parameters: disable true if checks for import cycles are to be suppressed, that is, if cycles should be allowed

setExecutable

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

Parameters: exec the executable