net.sf.saxon.expr
public class ExpressionParser extends Object
Nested Class Summary | |
---|---|
static interface | ExpressionParser.FLWORClause |
static class | ExpressionParser.ForClause |
protected static class | ExpressionParser.TemporaryContainer |
Field Summary | |
---|---|
protected boolean | compileWithTracing |
protected ExpressionParser.TemporaryContainer | defaultContainer |
protected StaticContext | env |
protected int | language |
protected NameChecker | nameChecker |
protected Stack<Binding> | rangeVariables |
protected boolean | scanOnly |
protected static int | SEQUENCE_TYPE |
protected Tokenizer | t |
protected static int | XPATH |
protected static int | XQUERY |
protected static int | XSLT_PATTERN |
Constructor Summary | |
---|---|
ExpressionParser()
Create an expression parser |
Method Summary | |
---|---|
protected String | currentTokenDisplay()
Display the current token in an error message
|
protected void | declareRangeVariable(Binding declaration)
Declare a range variable (record its existence within the parser).
|
protected void | expect(int token)
Expect a given token; fail if the current token is different. |
protected Binding | findRangeVariable(StructuredQName qName)
Locate a range variable with a given name. |
protected String | getLanguage()
Get the current language (XPath or XQuery) |
Stack<Binding> | getRangeVariableStack()
Get the range variable stack. |
Tokenizer | getTokenizer()
Get the tokenizer (the lexical analyzer) |
protected void | grumble(String message)
Report a syntax error (a static error with error code XP0003) |
protected void | grumble(String message, String errorCode)
Report a static error
|
protected void | grumble(String message, StructuredQName errorCode)
Report a static error
|
boolean | isCompileWithTracing()
Determine whether trace hooks are included in the compiled code. |
protected boolean | isKeyword(String s)
Test whether the current token is a given keyword. |
protected boolean | isNamespaceTestAllowed()
Ask whether the syntax namespace-node() is allowed in a node kind test. |
LocalNameTest | makeLocalNameTest(short nodeType, String localName)
Make a LocalNameTest (*:name)
|
int | makeNameCode(String qname, boolean useDefault)
Make a NameCode, using the static context for namespace resolution
|
int | makeNameCodeSilently(String qname, boolean useDefault)
Make a NameCode, using the static context for namespace resolution.
|
NamespaceTest | makeNamespaceTest(short nodeType, String prefix)
Make a NamespaceTest (name:*)
|
NameTest | makeNameTest(short nodeType, String qname, boolean useDefault)
Make a NameTest, using the static context for namespace resolution
|
protected Literal | makeStringLiteral(String currentTokenValue)
Method to make a string literal from a token identified as a string
literal. |
StructuredQName | makeStructuredQName(String qname, boolean useDefault)
Make a Structured QName, using the static context for namespace resolution
|
protected Expression | makeTracer(int startOffset, Expression exp, int construct, StructuredQName qName)
If tracing, wrap an expression in a trace instruction |
protected void | nextToken()
Read the next token, catching any exception thrown by the tokenizer |
Expression | parse(String expression, int start, int terminator, int lineNumber, StaticContext env)
Parse a string representing an expression
|
protected Expression | parseConstructor()
Parse a node constructor. |
protected Expression | parseDynamicFunctionCall(Expression functionItem)
Parse a dynamic function call |
protected Expression | parseExpression()
Parse a top-level Expression:
ExprSingle ( ',' ExprSingle )*
|
protected Expression | parseExprSingle()
Parse an ExprSingle
|
protected Expression | parseExtensionExpression()
Parse an Extension Expression
This construct is XQuery-only, so the XPath version of this
method throws an error unconditionally |
protected Expression | parseForExpression()
Parse a FOR expression:
for $x in expr (',' $y in expr)* 'return' expr
|
protected Expression | parseFunctionCall()
Parse a function call.
function-name '(' ( Expression (',' Expression )* )? |
protected ItemType | parseFunctionItemType()
Get the item type used for function items (XQuery 1.1 higher order functions) |
protected Expression | parseInlineFunction()
Parse an inline function
"function" "(" ParamList? |
protected ItemType | parseItemType()
Parse an ItemType within a SequenceType |
protected Expression | parseLiteralFunctionItem()
Parse a literal function item (introduced in XQuery 1.1)
Syntax: QName # integer
The QName and # have already been read |
protected Expression | parseMappingExpression()
Parse a mapping expression. |
protected NodeTest | parseNodeTest(short nodeType)
Parse a NodeTest.
|
protected ItemType | parseParenthesizedItemType()
Parse a parenthesized item type (allowed in XQuery 1.1 only) |
Pattern | parsePattern(String pattern, StaticContext env)
Parse a string representing an XSLT pattern
|
protected Expression | parseRelativePath()
Parse a relative path (a sequence of steps). |
protected Expression | parseRemainingPath(Expression start)
Parse the remaining steps of an absolute path expression (one starting in "/" or "//"). |
SequenceType | parseSequenceType(String input, StaticContext env)
Parse a string representing a sequence type
|
protected SequenceType | parseSequenceType()
Parse the sequence type production.
|
protected Expression | parseStepExpression()
Parse a step (including an optional sequence of predicates)
|
protected Expression | parseTryCatchExpression()
Parse a try/catch Expression
This construct is XQuery-1.1 only, so the XPath version of this
method throws an error unconditionally |
protected Expression | parseTypeswitchExpression()
Parse a Typeswitch Expression.
|
protected Expression | parseValidateExpression()
Parse a Validate Expression.
|
void | setCompileWithTracing(boolean trueOrFalse)
Set whether trace hooks are to be included in the compiled code. |
protected void | setLocation(Expression exp)
Set location information on an expression. |
protected void | setLocation(Expression exp, int offset)
Set location information on an expression. |
void | setRangeVariableStack(Stack<Binding> stack)
Set the range variable stack. |
void | setScanOnly(boolean scanOnly)
Set that we are parsing in "scan only" |
protected void | undeclareRangeVariable()
Note when the most recently declared range variable has gone out of scope |
protected void | warning(String message)
Output a warning message |
Returns: the display representation of the token
Parameters: declaration the variable declaration to be added to the stack
Throws: XPathException if any error is encountered
Parameters: token the expected token
Throws: XPathException if the current token is not the expected token
Parameters: qName identifies the name of the range variable
Returns: null if not found (this means the variable is probably a context variable); otherwise the relevant RangeVariable
Returns: a string representation of the language being parsed, for use in error messages
Returns: the stack used for locally-declared variables
Returns: the tokenizer (the lexical analyzer)
Parameters: message the error message
Throws: XPathException always thrown: an exception containing the supplied message
Parameters: message the error message
Throws: XPathException always thrown: an exception containing the supplied message
Parameters: message the error message errorCode the error code
Throws: XPathException always thrown: an exception containing the supplied message
Returns: true if trace hooks are included, false if not.
Parameters: s The string to be compared with the current token
Returns: true if they are the same
Returns: false (currently allowed only in XQuery 1.1)
Parameters: nodeType the kind of node to be matched localName the requred local name
Returns: a LocalNameTest, a pattern which matches all nodes of a given local name, regardless of namespace
Throws: XPathException if the local name is invalid
Parameters: qname The name as written, in the form "[prefix:]localname" useDefault Defines the action when there is no prefix. If true, use the default namespace URI for element names. If false, use no namespace URI (as for attribute names).
Returns: the namecode, which can be used to identify this name in the name pool
Throws: XPathException if the name is invalid, or the prefix undeclared
Parameters: qname The name as written, in the form "[prefix:]localname" useDefault Defines the action when there is no prefix. If true, use the default namespace URI for element names. If false, use no namespace URI (as for attribute names).
Returns: the namecode, which can be used to identify this name in the name pool
Throws: XPathException if the name is invalid, or the prefix undeclared
Parameters: nodeType integer code identifying the type of node required prefix the namespace prefix
Returns: the NamespaceTest, a pattern that matches all nodes in this namespace
Throws: XPathException if the namespace prefix is not declared
Parameters: nodeType the type of node required (identified by a constant in class Type) qname the lexical QName of the required node useDefault true if the default namespace should be used when the QName is unprefixed
Returns: a NameTest, representing a pattern that tests for a node of a given node kind and a given name
Throws: XPathException if the QName is invalid
Parameters: currentTokenValue the token as read (excluding quotation marks)
Returns: The string value of the string literal
Parameters: qname The name as written, in the form "[prefix:]localname" useDefault Defines the action when there is no prefix. If true, use the default namespace URI for element names. If false, use no namespace URI (as for attribute names).
Returns: the namecode, which can be used to identify this name in the name pool
Throws: XPathException if the name is invalid, or the prefix undeclared
Parameters: startOffset the position of the expression in the soruce exp the expression to be wrapped construct integer constant identifying the kind of construct qName the name of the construct (if applicable)
Returns: the expression that does the tracing
Parameters: expression the expression expressed as a String start offset within the string where parsing is to start terminator character to treat as terminating the expression lineNumber location of the start of the expression, for diagnostics env the static context for the expression
Returns: an Expression object representing the result of parsing
Throws: XPathException if the expression contains a syntax error
Returns: the expression that results from the parsing
Returns: the expression that results from the parsing
Returns: the Expression object that results from parsing
Throws: XPathException if the expression contains a syntax error
Returns: the resulting subexpression
Throws: XPathException if any error is encountered
Returns: the parsed expression; except that this version of the method always throws an exception
Returns: the resulting subexpression
Throws: XPathException if any error is encountered
Returns: the resulting subexpression
Throws: XPathException if any error is encountered
Throws: XPathException if a syntax error is found
Returns: an ExternalObject representing the function item
Syntax:
(for|some|every) $x in expr (',' $y in expr)* (return|satisfies) expr
On entry, the current token indicates whether a for, some, or every expression is expected.
Returns: the resulting subexpression
Throws: XPathException if any error is encountered
Parameters: nodeType the node type being sought if one is specified
Returns: the resulting NodeTest object
Throws: XPathException if any error is encountered
Parameters: pattern the pattern expressed as a String env the static context for the pattern
Returns: a Pattern object representing the result of parsing
Throws: XPathException if the pattern contains a syntax error
Returns: the resulting subexpression
Throws: XPathException if any error is encountered
Parameters: start the initial implicit expression: root() in the case of "/", root()/descendant-or-self::node in the case of "//"
Returns: the completed path expression
Throws: XPathException
Parameters: input the string, which should conform to the XPath SequenceType production env the static context
Returns: a SequenceType object representing the type
Throws: XPathException if any error is encountered
Returns: the resulting subexpression
Throws: XPathException if any error is encountered
Returns: the resulting subexpression
Throws: XPathException if any error is encountered
Returns: the parsed expression; except that this version of the method always throws an exception
Returns: the expression that results from the parsing
Returns: the parsed expression; except that this version of the method always throws an exception
Parameters: trueOrFalse true if trace code is to be compiled in, false otherwise
Parameters: exp the expression whose location information is to be set
Parameters: exp the expression whose location information is to be set offset the character position within the expression (ignoring newlines)
Parameters: stack the stack to be used for local variables declared within the expression
Parameters: scanOnly true if parsing is to proceed in scan-only mode. In this mode namespace bindings are not yet known, so no attempt is made to look up namespace prefixes.
Parameters: message the text of the message