net.sf.saxon.query
Class QueryParser

java.lang.Object
  extended by net.sf.saxon.expr.ExpressionParser
      extended by net.sf.saxon.query.QueryParser

 class QueryParser
extends ExpressionParser

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
protected  Executable executable
           
 java.util.Set importedModules
           
(package private)  java.util.List moduleImports
           
(package private)  java.util.List namespacesToBeSealed
           
(package private)  java.util.List schemaImports
           
 
Fields inherited from class net.sf.saxon.expr.ExpressionParser
env, language, nameChecker, rangeVariables, scanOnly, SEQUENCE_TYPE, t, XPATH, XQUERY, XSLT_PATTERN
 
Constructor Summary
protected QueryParser()
          Protected Constructor: this class should be instantiated via the StaticQueryContext
 
Method Summary
 void applyModuleImport(net.sf.saxon.query.QueryParser.Import mImport)
           
 Executable getExecutable()
          Get the executable containing this expression.
protected  java.lang.String getLanguage()
          Get the current language (XPath or XQuery)
protected  void grumble(java.lang.String message, java.lang.String errorCode)
          Report a static error
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  StringValue makeStringLiteral(java.lang.String token)
          Method to make a string literal from a token identified as a string literal.
 XQueryExpression makeXQueryExpression(java.lang.String query, StaticQueryContext staticContext, Configuration config)
          Create an XQueryExpression
protected  Expression parseConstructor()
          Parse a node constructor.
protected  Expression parseExtensionExpression()
          Parse an Extension Expression.
protected  Expression parseForExpression()
          Parse a FLWOR expression.
 void parseLibraryModule(java.lang.String queryString, StaticQueryContext env)
          Parse a library module.
protected  Expression parseTypeswitchExpression()
          Parse a Typeswitch Expression.
protected  Expression parseValidateExpression()
          Parse a Validate Expression.
 Expression setDefaultValue(java.lang.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 expression
 
Methods inherited from class net.sf.saxon.expr.ExpressionParser
currentTokenDisplay, declareRangeVariable, expect, getRangeVariableStack, getTokenizer, grumble, isKeyword, makeLocalNameTest, makeNameCode, makeNamespaceTest, makeNameTest, makeTracer, nextToken, parse, parseExpression, parseExprSingle, parseMappingExpression, parseNodeTest, parsePattern, parseRelativePath, parseRemainingPath, parseSequenceType, parseSequenceType, parseStepExpression, setLocation, setLocation, setRangeVariableStack, setScanOnly, undeclareRangeVariable, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

executable

protected Executable executable

importedModules

public java.util.Set importedModules

namespacesToBeSealed

java.util.List namespacesToBeSealed

schemaImports

java.util.List schemaImports

moduleImports

java.util.List moduleImports
Constructor Detail

QueryParser

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

Method Detail

makeXQueryExpression

public XQueryExpression makeXQueryExpression(java.lang.String query,
                                             StaticQueryContext staticContext,
                                             Configuration config)
                                      throws XPathException
Create an XQueryExpression

Throws:
XPathException

getExecutable

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


setExecutable

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


parseLibraryModule

public final void parseLibraryModule(java.lang.String queryString,
                                     StaticQueryContext env)
                              throws StaticError
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

protected void grumble(java.lang.String message,
                       java.lang.String errorCode)
                throws StaticError
Report a static error

Overrides:
grumble in class ExpressionParser
Parameters:
message - the error message
errorCode - the error code
Throws:
StaticError - always thrown: an exception containing the supplied message

applyModuleImport

public void applyModuleImport(net.sf.saxon.query.QueryParser.Import mImport)
                       throws StaticError
Throws:
StaticError

setDefaultValue

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


parseForExpression

protected Expression parseForExpression()
                                 throws StaticError
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 class ExpressionParser
Returns:
the resulting subexpression
Throws:
StaticError - if any error is encountered

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.


parseTypeswitchExpression

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

Overrides:
parseTypeswitchExpression in class ExpressionParser
Throws:
StaticError

parseValidateExpression

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

Overrides:
parseValidateExpression in class ExpressionParser
Throws:
StaticError

parseExtensionExpression

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

Overrides:
parseExtensionExpression in class ExpressionParser
Throws:
StaticError

parseConstructor

protected Expression parseConstructor()
                               throws StaticError
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 class ExpressionParser
Returns:
an Expression for evaluating the parsed constructor
Throws:
StaticError - in the event of a syntax error.

makeStringLiteral

protected StringValue makeStringLiteral(java.lang.String token)
                                 throws StaticError
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 class ExpressionParser
Parameters:
token -
Returns:
The string value of the string literal, after dereferencing entity and character references
Throws:
StaticError

getLanguage

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

Overrides:
getLanguage in class ExpressionParser