net.sf.saxon.query
Class QueryParser

java.lang.Object
  |
  +--net.sf.saxon.expr.ExpressionParser
        |
        +--net.sf.saxon.query.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
 
Nested classes inherited from class net.sf.saxon.expr.ExpressionParser
ExpressionParser.ForClause
 
Field Summary
 
Fields inherited from class net.sf.saxon.expr.ExpressionParser
env, numberOfRangeVariables, rangeVariables, scanOnly, t
 
Constructor Summary
QueryParser()
           
 
Method Summary
 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)
          Report a parsing error
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 parseForExpression()
          Parse a FLWOR expression.
 void parseLibraryModule(java.lang.String queryString, StaticQueryContext env, int firstSlot)
          Parse a library module.
 Expression parseQuery(java.lang.String queryString, int start, int terminator, StaticQueryContext env)
          Parse a top-level Query.
protected  Expression parseTypeswitchExpression()
          Parse a Typeswitch Expression.
protected  Expression parseValidateExpression()
          Parse a Validate Expression.
 ValidationContext parseValidationContext()
          Parse a validation context.
 void setExecutable(Executable exec)
          Set the executable used for this query expression
protected  void setLocation(Expression exp, int line, Executable executable)
          Set location information on an expression.
 
Methods inherited from class net.sf.saxon.expr.ExpressionParser
currentTokenDisplay, declareRangeVariable, expect, getRangeVariableStack, getTokenizer, isKeyword, makeLocalNameTest, makeLocator, makeNameCode, makeNamespaceTest, makeNameTest, nextToken, parse, parseExpression, parseExprSingle, parseMappingExpression, parseNodeTest, parsePattern, parseRelativePath, parseSequenceType, parseSequenceType, parseStepExpression, setLocation, setRangeVariableStack, setScanOnly, undeclareRangeVariable, warning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

QueryParser

public QueryParser()
Method Detail

makeXQueryExpression

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

XPathException

parseQuery

public final Expression parseQuery(java.lang.String queryString,
                                   int start,
                                   int terminator,
                                   StaticQueryContext env)
                            throws XPathException
Parse a top-level Query. Prolog? Expression

Parameters:
queryString - The text of the query
start - Offset of the start of the query
terminator - Token expected to follow the query (usually Tokenizer.EOF)
env - The static context
Returns:
the Expression object that results from parsing
Throws:
XPathException - if the expression contains a syntax error

parseLibraryModule

public final void parseLibraryModule(java.lang.String queryString,
                                     StaticQueryContext env,
                                     int firstSlot)
                              throws XPathException.Static
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.
firstSlot - The integer position of the first slot to be allocated to global variables declared in this module
Throws:
XPathException.Static - if the expression contains a syntax error

grumble

protected void grumble(java.lang.String message)
                throws XPathException.Static
Report a parsing error

Overrides:
grumble in class ExpressionParser
Parameters:
message - the error message
Throws:
XPathException.Static - always thrown: an exception containing the supplied message

setLocation

protected void setLocation(Expression exp,
                           int line,
                           Executable executable)
Set location information on an expression. At present this consists of a simple line number. Needed mainly for XQuery. This version of the method supplies an explicit line number.

Overrides:
setLocation in class ExpressionParser

getExecutable

public Executable getExecutable()
Get the executable containing this expression. Returns null for XPath: needed only for XQuery

Overrides:
getExecutable in class ExpressionParser

setExecutable

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


parseForExpression

protected Expression parseForExpression()
                                 throws XPathException.Static
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:
XPathException.Static - if any error is encountered

parseTypeswitchExpression

protected Expression parseTypeswitchExpression()
                                        throws XPathException.Static
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
XPathException.Static

parseValidateExpression

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

Overrides:
parseValidateExpression in class ExpressionParser
XPathException.Static

parseValidationContext

public ValidationContext parseValidationContext()
                                         throws XPathException.Static
Parse a validation context. Syntax ( qname | type(qname) ) ( '/' qname )*

XPathException.Static

parseConstructor

protected Expression parseConstructor()
                               throws XPathException.Static
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:
XPathException.Static - in the event of a syntax error.

makeStringLiteral

protected StringValue makeStringLiteral(java.lang.String token)
                                 throws XPathException.Static
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
XPathException.Static

getLanguage

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

Overrides:
getLanguage in class ExpressionParser