|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--net.sf.saxon.expr.ExpressionParser
Parser for XPath expressions and XSLT patterns. This code was originally inspired by James Clark's xt but has been totally rewritten (several times)
Nested Class Summary | |
static class |
ExpressionParser.ForClause
|
Field Summary | |
protected StaticContext |
env
|
protected int |
numberOfRangeVariables
|
protected java.util.Stack |
rangeVariables
|
protected boolean |
scanOnly
|
protected Tokenizer |
t
|
Constructor Summary | |
ExpressionParser()
|
Method Summary | |
protected java.lang.String |
currentTokenDisplay()
Display the current token in an error message |
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 |
Executable |
getExecutable()
Get the executable containing this expression. |
protected java.lang.String |
getLanguage()
Get the current language (XPath or XQuery) |
java.util.Stack |
getRangeVariableStack()
Get the range variable stack. |
Tokenizer |
getTokenizer()
|
protected void |
grumble(java.lang.String message)
Report a parsing error |
protected boolean |
isKeyword(java.lang.String s)
Test whether the current token is a given keyword. |
LocalNameTest |
makeLocalNameTest(short nodeType,
java.lang.String localName)
Make a LocalNameTest (*:name) |
protected javax.xml.transform.SourceLocator |
makeLocator()
Create a SourceLocator for use in an exception |
int |
makeNameCode(java.lang.String qname,
boolean useDefault)
Make a NameCode, using this Element as the context for namespace resolution |
NamespaceTest |
makeNamespaceTest(short nodeType,
java.lang.String prefix)
Make a NamespaceTest (name:*) |
NameTest |
makeNameTest(short nodeType,
java.lang.String qname,
boolean useDefault)
Make a NameTest, using the static context for namespace resolution |
protected StringValue |
makeStringLiteral(java.lang.String currentTokenValue)
Method to make a string literal from a token identified as a string literal. |
protected void |
nextToken()
Read the next token, catching any exception thrown by the tokenizer |
Expression |
parse(java.lang.String expression,
int start,
int terminator,
StaticContext env)
Parse a string representing an expression |
protected Expression |
parseConstructor()
Parse a node constructor. |
protected Expression |
parseExpression()
Parse a top-level Expression: ExprSingle ( ',' ExprSingle )* |
protected Expression |
parseExprSingle()
Parse an ExprSingle |
protected Expression |
parseForExpression()
Parse a FOR expression: for $x in expr (',' $y in expr)* 'return' expr |
protected Expression |
parseMappingExpression()
Parse a mapping expression. |
protected NodeTest |
parseNodeTest(short nodeType)
Parse a NodeTest. |
Pattern |
parsePattern(java.lang.String pattern,
StaticContext env)
Parse a string representing an XSLT pattern |
protected Expression |
parseRelativePath()
Parse a relative path (a sequence of steps). |
protected SequenceType |
parseSequenceType()
Parse the sequence type production. |
SequenceType |
parseSequenceType(java.lang.String input,
StaticContext env)
Parse a string representing a sequence type |
protected Expression |
parseStepExpression()
Parse a step (including an optional sequence of predicates) |
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 line,
Executable executable)
Set location information on an expression. |
void |
setRangeVariableStack(java.util.Stack stack)
Set the range variable stack. |
void |
setScanOnly(boolean scanOnly)
|
protected void |
undeclareRangeVariable()
Note when the most recently declared range variable has gone out of scope |
protected void |
warning(java.lang.String message)
Output a warning message |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected Tokenizer t
protected StaticContext env
protected int numberOfRangeVariables
protected java.util.Stack rangeVariables
protected boolean scanOnly
Constructor Detail |
public ExpressionParser()
Method Detail |
public Tokenizer getTokenizer()
protected void nextToken() throws XPathException.Static
XPathException.Static
protected void expect(int token) throws XPathException.Static
token
- the expected token
XPathException.Static.Static
- if the current token is not the expected
token
XPathException.Static
protected void grumble(java.lang.String message) throws XPathException.Static
message
- the error message
XPathException.Static.Static
- always thrown: an exception containing the
supplied message
XPathException.Static
protected void warning(java.lang.String message) throws XPathException.Static
XPathException.Static
protected java.lang.String getLanguage()
protected java.lang.String currentTokenDisplay()
public Expression parse(java.lang.String expression, int start, int terminator, StaticContext env) throws XPathException.Static
expression
- the expression expressed as a Stringenv
- the static context for the expression
XPathException.Static
- if the expression contains a syntax errorpublic Pattern parsePattern(java.lang.String pattern, StaticContext env) throws XPathException.Static
pattern
- the pattern expressed as a Stringenv
- the static context for the pattern
XPathException.Static
- if the pattern contains a syntax errorpublic SequenceType parseSequenceType(java.lang.String input, StaticContext env) throws XPathException.Static
input
- the string, which should conform to the XPath SequenceType
productionenv
- the static context
XPathException.Static
- if any error is encounteredprotected Expression parseExpression() throws XPathException.Static
XPathException.Static
- if the expression contains a syntax errorprotected Expression parseExprSingle() throws XPathException.Static
XPathException.Static
- if any error is encounteredprotected Expression parseTypeswitchExpression() throws XPathException.Static
XPathException.Static
protected Expression parseValidateExpression() throws XPathException.Static
XPathException.Static
protected Expression parseForExpression() throws XPathException.Static
XPathException.Static
- if any error is encounteredprotected Expression parseMappingExpression() throws XPathException.Static
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.
XPathException.Static
- if any error is encounteredprotected SequenceType parseSequenceType() throws XPathException.Static
XPathException.Static
- if any error is encounteredprotected Expression parseRelativePath() throws XPathException.Static
XPathException.Static
- if any error is encounteredprotected Expression parseStepExpression() throws XPathException.Static
XPathException.Static
- if any error is encounteredprotected StringValue makeStringLiteral(java.lang.String currentTokenValue) throws XPathException.Static
currentTokenValue
-
XPathException.Static
protected Expression parseConstructor() throws XPathException.Static
XPathException.Static
protected NodeTest parseNodeTest(short nodeType) throws XPathException.Static
nodeType
- the node type being sought if one is specified
XPathException.Static
- if any error is encounteredprotected void declareRangeVariable(VariableDeclaration declaration) throws XPathException.Static
declaration
- the VariableDeclaration to be added to the stack
XPathException.Static
- if any error is encounteredprotected void undeclareRangeVariable()
public java.util.Stack getRangeVariableStack()
public void setRangeVariableStack(java.util.Stack stack)
public final int makeNameCode(java.lang.String qname, boolean useDefault) throws XPathException.Static
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).
XPathException.Static
- if the name is invalid, or the prefix
undeclaredpublic NameTest makeNameTest(short nodeType, java.lang.String qname, boolean useDefault) throws XPathException.Static
nodeType
- the type of node required (identified by a constant in
class Type)qname
- the lexical QName of the required nodeuseDefault
- true if the default namespace should be used when
the QName is unprefixed
XPathException.Static
- if the QName is invalidpublic NamespaceTest makeNamespaceTest(short nodeType, java.lang.String prefix) throws XPathException.Static
nodeType
- integer code identifying the type of node requiredprefix
- the namespace prefix
XPathException.Static
- if the namespace prefix is not declaredpublic LocalNameTest makeLocalNameTest(short nodeType, java.lang.String localName) throws XPathException.Static
nodeType
- the kind of node to be matchedlocalName
- the requred local name
XPathException.Static
- if the local name is invalidprotected void setLocation(Expression exp)
protected void setLocation(Expression exp, int line, Executable executable)
public Executable getExecutable()
protected javax.xml.transform.SourceLocator makeLocator()
protected boolean isKeyword(java.lang.String s)
s
- The string to be compared with the current token
public void setScanOnly(boolean scanOnly)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |