public class ExpressionParser
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
ExpressionParser.ForClause |
protected static class |
ExpressionParser.TemporaryContainer |
Modifier and Type | Field and Description |
---|---|
protected boolean |
compileWithTracing |
protected StaticContext |
env |
protected int |
language |
protected NameChecker |
nameChecker |
protected java.util.Stack |
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 and Description |
---|
ExpressionParser()
Create an expression parser
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.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 java.lang.String |
getLanguage()
Get the current language (XPath or XQuery)
|
java.util.Stack |
getRangeVariableStack()
Get the range variable stack.
|
Tokenizer |
getTokenizer()
Get the tokenizer (the lexical analyzer)
|
protected void |
grumble(java.lang.String message)
Report a syntax error (a static error with error code XP0003)
|
protected void |
grumble(java.lang.String message,
java.lang.String errorCode)
Report a static error
|
boolean |
isCompileWithTracing()
Determine whether trace hooks are included in the compiled code.
|
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)
|
int |
makeNameCode(java.lang.String qname,
boolean useDefault)
Make a NameCode, using the static context for namespace resolution
|
int |
makeNameCodeSilently(java.lang.String qname,
boolean useDefault)
Make a NameCode, using the static 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 Literal |
makeStringLiteral(java.lang.String currentTokenValue)
Method to make a string literal from a token identified as a string
literal.
|
StructuredQName |
makeStructuredQName(java.lang.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(java.lang.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 |
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.
|
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 Expression |
parseRemainingPath(Expression start)
Parse the remaining steps of an absolute path expression (one starting in "/" or "//").
|
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.
|
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(java.util.Stack 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(java.lang.String message)
Output a warning message
|
protected Tokenizer t
protected StaticContext env
protected java.util.Stack rangeVariables
protected NameChecker nameChecker
protected boolean scanOnly
protected boolean compileWithTracing
protected int language
protected static final int XPATH
protected static final int XSLT_PATTERN
protected static final int SEQUENCE_TYPE
protected static final int XQUERY
public void setCompileWithTracing(boolean trueOrFalse)
trueOrFalse
- true if trace code is to be compiled in, false otherwisepublic boolean isCompileWithTracing()
public Tokenizer getTokenizer()
protected void nextToken() throws XPathException
XPathException
protected void expect(int token) throws XPathException
token
- the expected tokenXPathException
- if the current token is not the expected
tokenprotected void grumble(java.lang.String message) throws XPathException
message
- the error messageXPathException
- always thrown: an exception containing the
supplied messageprotected void grumble(java.lang.String message, java.lang.String errorCode) throws XPathException
message
- the error messageerrorCode
- the error codeXPathException
- always thrown: an exception containing the
supplied messageprotected void warning(java.lang.String message) throws XPathException
message
- the text of the messageXPathException
protected java.lang.String getLanguage()
protected java.lang.String currentTokenDisplay()
public Expression parse(java.lang.String expression, int start, int terminator, int lineNumber, StaticContext env) throws XPathException
expression
- the expression expressed as a Stringstart
- offset within the string where parsing is to startterminator
- character to treat as terminating the expressionlineNumber
- location of the start of the expression, for diagnosticsenv
- the static context for the expressionXPathException
- if the expression contains a syntax errorpublic Pattern parsePattern(java.lang.String pattern, StaticContext env) throws XPathException
pattern
- the pattern expressed as a Stringenv
- the static context for the patternXPathException
- if the pattern contains a syntax errorpublic SequenceType parseSequenceType(java.lang.String input, StaticContext env) throws XPathException
input
- the string, which should conform to the XPath SequenceType
productionenv
- the static contextXPathException
- if any error is encounteredprotected Expression parseExpression() throws XPathException
XPathException
- if the expression contains a syntax errorprotected Expression parseExprSingle() throws XPathException
XPathException
- if any error is encounteredprotected Expression parseTypeswitchExpression() throws XPathException
XPathException
protected Expression parseValidateExpression() throws XPathException
XPathException
protected Expression parseExtensionExpression() throws XPathException
XPathException
protected Expression parseForExpression() throws XPathException
XPathException
- if any error is encounteredprotected Expression parseMappingExpression() throws XPathException
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
- if any error is encounteredprotected SequenceType parseSequenceType() throws XPathException
XPathException
- if any error is encounteredprotected Expression parseRelativePath() throws XPathException
XPathException
- if any error is encounteredprotected Expression parseRemainingPath(Expression start) throws XPathException
start
- the initial implicit expression: root() in the case of "/", root()/descendant-or-self::node in
the case of "//"XPathException
protected Expression parseStepExpression() throws XPathException
XPathException
- if any error is encounteredprotected Literal makeStringLiteral(java.lang.String currentTokenValue) throws XPathException
currentTokenValue
- the token as read (excluding quotation marks)XPathException
protected Expression parseConstructor() throws XPathException
XPathException
protected NodeTest parseNodeTest(short nodeType) throws XPathException
nodeType
- the node type being sought if one is specifiedXPathException
- if any error is encounteredprotected Expression parseFunctionCall() throws XPathException
XPathException
- if any error is encounteredprotected void declareRangeVariable(Binding declaration) throws XPathException
declaration
- the variable declaration to be added to the stackXPathException
- if any error is encounteredprotected void undeclareRangeVariable()
public java.util.Stack getRangeVariableStack()
public void setRangeVariableStack(java.util.Stack stack)
stack
- the stack to be used for local variables declared within the expressionpublic final int makeNameCode(java.lang.String qname, boolean useDefault) throws XPathException
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
- if the name is invalid, or the prefix
undeclaredpublic final int makeNameCodeSilently(java.lang.String qname, boolean useDefault) throws XPathException, QNameException
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
- if the name is invalid, or the prefix
undeclaredQNameException
public final StructuredQName makeStructuredQName(java.lang.String qname, boolean useDefault) throws XPathException
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
- if the name is invalid, or the prefix
undeclaredpublic NameTest makeNameTest(short nodeType, java.lang.String qname, boolean useDefault) throws XPathException
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 unprefixedXPathException
- if the QName is invalidpublic NamespaceTest makeNamespaceTest(short nodeType, java.lang.String prefix) throws XPathException
nodeType
- integer code identifying the type of node requiredprefix
- the namespace prefixXPathException
- if the namespace prefix is not declaredpublic LocalNameTest makeLocalNameTest(short nodeType, java.lang.String localName) throws XPathException
nodeType
- the kind of node to be matchedlocalName
- the requred local nameXPathException
- if the local name is invalidprotected void setLocation(Expression exp)
exp
- the expression whose location information is to be setprotected void setLocation(Expression exp, int offset)
exp
- the expression whose location information is to be setoffset
- the character position within the expression (ignoring newlines)protected Expression makeTracer(int startOffset, Expression exp, int construct, StructuredQName qName)
startOffset
- the position of the expression in the soruceexp
- the expression to be wrappedconstruct
- integer constant identifying the kind of constructqName
- the name of the construct (if applicable)protected boolean isKeyword(java.lang.String s)
s
- The string to be compared with the current tokenpublic void setScanOnly(boolean scanOnly)
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.