| java.lang.Object net.sf.saxon.expr.ExpressionParser
All known Subclasses: net.sf.saxon.query.QueryParser,
ExpressionParser | public class ExpressionParser (Code) | | Parser for XPath expressions and XSLT patterns.
This code was originally inspired by James Clark's xt but has been totally rewritten (several times)
author: Michael Kay |
Inner Class :public static class ForClause | |
Method Summary | |
protected String | currentTokenDisplay() | protected void | declareRangeVariable(VariableDeclaration 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 String | getLanguage() | public Stack | getRangeVariableStack() Get the range variable stack. | public Tokenizer | getTokenizer() | protected void | grumble(String message) | protected void | grumble(String message, String errorCode) | protected boolean | isKeyword(String s) Test whether the current token is a given keyword. | public LocalNameTest | makeLocalNameTest(short nodeType, String localName) | final public int | makeNameCode(String qname, boolean useDefault) Make a NameCode, using this Element as the context for namespace resolution
throws: net.sf.saxon.trans.StaticError - if the name is invalid, or the prefixundeclared Parameters: qname - The name as written, in the form "[prefix:]localname" Parameters: useDefault - Defines the action when there is no prefix. | public NameTest | makeNameTest(short nodeType, String qname, boolean useDefault) | public NamespaceTest | makeNamespaceTest(short nodeType, String prefix) | protected StringValue | makeStringLiteral(String currentTokenValue) Method to make a string literal from a token identified as a string
literal. | protected Expression | makeTracer(int startOffset, Expression exp, int construct, int objectNameCode) | protected void | nextToken() | public Expression | parse(String expression, int start, int terminator, int lineNumber, StaticContext env) | protected Expression | parseConstructor() Parse a node constructor. | protected Expression | parseExprSingle() | protected Expression | parseExpression() | protected Expression | parseExtensionExpression() | protected Expression | parseForExpression() | protected Expression | parseMappingExpression() Parse a mapping expression. | protected NodeTest | parseNodeTest(short nodeType) Parse a NodeTest. | public Pattern | parsePattern(String pattern, StaticContext env) | 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 "//"). | public SequenceType | parseSequenceType(String input, StaticContext env) | protected SequenceType | parseSequenceType() Parse the sequence type production. | protected Expression | parseStepExpression() | protected Expression | parseTypeswitchExpression() Parse a Typeswitch Expression. | protected Expression | parseValidateExpression() Parse a Validate Expression. | protected void | setLocation(Expression exp) Set location information on an expression. | protected void | setLocation(Expression exp, int offset) Set location information on an expression. | public void | setRangeVariableStack(Stack stack) Set the range variable stack. | public void | setScanOnly(boolean scanOnly) | protected void | undeclareRangeVariable() | protected void | warning(String message) |
SEQUENCE_TYPE | final protected static int SEQUENCE_TYPE(Code) | | |
XPATH | final protected static int XPATH(Code) | | |
XQUERY | final protected static int XQUERY(Code) | | |
XSLT_PATTERN | final protected static int XSLT_PATTERN(Code) | | |
language | protected int language(Code) | | |
scanOnly | protected boolean scanOnly(Code) | | |
ExpressionParser | public ExpressionParser()(Code) | | |
currentTokenDisplay | protected String currentTokenDisplay()(Code) | | Display the current token in an error message
the display representation of the token |
declareRangeVariable | protected void declareRangeVariable(VariableDeclaration declaration) throws StaticError(Code) | | Declare a range variable (record its existence within the parser).
A range variable is a variable declared within an expression, as distinct
from a variable declared in the context.
Parameters: declaration - the VariableDeclaration to be added to the stack throws: net.sf.saxon.trans.StaticError - if any error is encountered |
expect | protected void expect(int token) throws StaticError(Code) | | Expect a given token; fail if the current token is different. Note that this method
does not read any tokens.
Parameters: token - the expected token throws: net.sf.saxon.trans.StaticError - if the current token is not the expectedtoken |
getLanguage | protected String getLanguage()(Code) | | Get the current language (XPath or XQuery)
|
getRangeVariableStack | public Stack getRangeVariableStack()(Code) | | Get the range variable stack. Used when parsing a nested subexpression
inside an attribute constructor
|
grumble | protected void grumble(String message) throws StaticError(Code) | | Report a syntax error (a static error with error code XP0003)
Parameters: message - the error message exception: net.sf.saxon.trans.StaticError - always thrown: an exception containing thesupplied message |
isKeyword | protected boolean isKeyword(String s)(Code) | | Test whether the current token is a given keyword.
Parameters: s - The string to be compared with the current token true if they are the same |
makeLocalNameTest | public LocalNameTest makeLocalNameTest(short nodeType, String localName) throws StaticError(Code) | | Make a LocalNameTest (*:name)
Parameters: nodeType - the kind of node to be matched Parameters: localName - the requred local name throws: net.sf.saxon.trans.StaticError - if the local name is invalid a LocalNameTest, a pattern which matches all nodes of a givenlocal name, regardless of namespace |
makeNameCode | final public int makeNameCode(String qname, boolean useDefault) throws StaticError(Code) | | Make a NameCode, using this Element as the context for namespace resolution
throws: net.sf.saxon.trans.StaticError - if the name is invalid, or the prefixundeclared Parameters: qname - The name as written, in the form "[prefix:]localname" Parameters: useDefault - Defines the action when there is no prefix. Iftrue, use the default namespace URI for element names. If false,use no namespace URI (as for attribute names). the namecode, which can be used to identify this name in thename pool |
makeNameTest | public NameTest makeNameTest(short nodeType, String qname, boolean useDefault) throws StaticError(Code) | | Make a NameTest, using the static context for namespace resolution
Parameters: nodeType - the type of node required (identified by a constant inclass Type) Parameters: qname - the lexical QName of the required node Parameters: useDefault - true if the default namespace should be used whenthe QName is unprefixed throws: net.sf.saxon.trans.StaticError - if the QName is invalid a NameTest, representing a pattern that tests for a node of agiven node kind and a given name |
makeNamespaceTest | public NamespaceTest makeNamespaceTest(short nodeType, String prefix) throws StaticError(Code) | | Make a NamespaceTest (name:*)
Parameters: nodeType - integer code identifying the type of node required Parameters: prefix - the namespace prefix throws: net.sf.saxon.trans.StaticError - if the namespace prefix is not declared the NamespaceTest, a pattern that matches all nodes in thisnamespace |
makeStringLiteral | protected StringValue makeStringLiteral(String currentTokenValue) throws StaticError(Code) | | 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. Note that the job of handling
doubled string delimiters is done by the tokenizer.
Parameters: currentTokenValue - The string value of the string literal |
makeTracer | protected Expression makeTracer(int startOffset, Expression exp, int construct, int objectNameCode)(Code) | | If tracing, wrap an instruction in a trace instruction
|
nextToken | protected void nextToken() throws StaticError(Code) | | Read the next token, catching any exception thrown by the tokenizer
|
parse | public Expression parse(String expression, int start, int terminator, int lineNumber, StaticContext env) throws StaticError(Code) | | Parse a string representing an expression
throws: net.sf.saxon.trans.StaticError - if the expression contains a syntax error Parameters: expression - the expression expressed as a String Parameters: start - offset within the string where parsing is to start Parameters: terminator - character to treat as terminating the expression Parameters: lineNumber - location of the start of the expression, for diagnostics Parameters: env - the static context for the expression an Expression object representing the result of parsing |
parseConstructor | protected Expression parseConstructor() throws StaticError(Code) | | Parse a node constructor. This is allowed only in XQuery, so the method throws
an error for XPath.
|
parseExtensionExpression | protected Expression parseExtensionExpression() throws StaticError(Code) | | Parse an Extension Expression
This construct is XQuery-only, so the XPath version of this
method throws an error unconditionally
|
parseMappingExpression | protected Expression parseMappingExpression() throws StaticError(Code) | | Parse a mapping expression. This is a common routine that handles
XPath for expressions and quantified expressions.
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.
throws: net.sf.saxon.trans.StaticError - if any error is encountered the resulting subexpression |
parseNodeTest | protected NodeTest parseNodeTest(short nodeType) throws StaticError(Code) | | Parse a NodeTest.
One of QName, prefix:*, *:suffix, *, text(), node(), comment(), or
processing-instruction(literal?), or element(~,~), attribute(~,~), etc.
throws: net.sf.saxon.trans.StaticError - if any error is encountered Parameters: nodeType - the node type being sought if one is specified the resulting NodeTest object |
parsePattern | public Pattern parsePattern(String pattern, StaticContext env) throws StaticError(Code) | | Parse a string representing an XSLT pattern
throws: net.sf.saxon.trans.StaticError - if the pattern contains a syntax error Parameters: pattern - the pattern expressed as a String Parameters: env - the static context for the pattern a Pattern object representing the result of parsing |
parseRelativePath | protected Expression parseRelativePath() throws StaticError(Code) | | Parse a relative path (a sequence of steps). Called when the current token immediately
follows a separator (/ or //), or an implicit separator (XYZ is equivalent to ./XYZ)
throws: net.sf.saxon.trans.StaticError - if any error is encountered the resulting subexpression |
parseRemainingPath | protected Expression parseRemainingPath(Expression start) throws StaticError(Code) | | Parse the remaining steps of an absolute path expression (one starting in "/" or "//"). Note that the
token immediately after the "/" or "//" has already been read, and in the case of "/", it has been confirmed
that we have a path expression starting with "/" rather than a standalone "/" expression.
Parameters: start - the initial implicit expression: root() in the case of "/", root()/descendant-or-self::node inthe case of "//" the completed path expression throws: StaticError - |
parseSequenceType | public SequenceType parseSequenceType(String input, StaticContext env) throws StaticError(Code) | | Parse a string representing a sequence type
Parameters: input - the string, which should conform to the XPath SequenceTypeproduction Parameters: env - the static context throws: net.sf.saxon.trans.StaticError - if any error is encountered a SequenceType object representing the type |
parseSequenceType | protected SequenceType parseSequenceType() throws StaticError(Code) | | Parse the sequence type production.
Provisionally, we use the syntax (QName | node-kind "()") ( "*" | "+" | "?" )?
We also allow "element of type QName" and "attribute of type QName"
The QName must be the name of a built-in schema-defined data type.
throws: net.sf.saxon.trans.StaticError - if any error is encountered the resulting subexpression |
parseTypeswitchExpression | protected Expression parseTypeswitchExpression() throws StaticError(Code) | | Parse a Typeswitch Expression.
This construct is XQuery-only, so the XPath version of this
method throws an error unconditionally
|
parseValidateExpression | protected Expression parseValidateExpression() throws StaticError(Code) | | Parse a Validate Expression.
This construct is XQuery-only, so the XPath version of this
method throws an error unconditionally
|
setLocation | protected void setLocation(Expression exp)(Code) | | Set location information on an expression. At present this consists of a simple
line number. Needed mainly for XQuery.
|
setLocation | protected void setLocation(Expression exp, int offset)(Code) | | Set location information on an expression. At present only the line number
is retained. Needed mainly for XQuery. This version of the method supplies an
explicit offset (character position within the expression or query), which the tokenizer
can convert to a line number and column number.
|
setRangeVariableStack | public void setRangeVariableStack(Stack stack)(Code) | | Set the range variable stack. Used when parsing a nested subexpression
inside an attribute constructor.
|
setScanOnly | public void setScanOnly(boolean scanOnly)(Code) | | |
undeclareRangeVariable | protected void undeclareRangeVariable()(Code) | | Note when the most recently declared range variable has gone out of scope
|
|
|