Package org.apache.xpath.compiler
Class XPathParser
java.lang.Object
org.apache.xpath.compiler.XPathParser
public class XPathParser extends Object
Tokenizes and parses XPath expressions. This should really be named
XPathParserImpl, and may be renamed in the future.
-
Field Summary
Fields Modifier and Type Field Description static StringCONTINUE_AFTER_FATAL_ERRORprotected static intFILTER_MATCH_FAILEDResults from checking FilterExpr syntaxprotected static intFILTER_MATCH_PREDICATESprotected static intFILTER_MATCH_PRIMARY -
Constructor Summary
Constructors Constructor Description XPathParser(ErrorListener errorListener, SourceLocator sourceLocator)The parser constructor. -
Method Summary
Modifier and Type Method Description protected booleanAbbreviatedNodeTestStep(boolean isLeadingSlashPermitted)AbbreviatedNodeTestStep ::= '@'? NodeTest Predicateprotected intAdditiveExpr(int addPos)This has to handle construction of the operations so that they are evaluated in pre-fix order.protected voidAndExpr()AndExpr ::= EqualityExpr | AndExpr 'and' EqualityExprprotected voidArgument()Argument ::= Exprprotected intAxisName()Basis ::= AxisName '::' NodeTest | AbbreviatedBasisprotected voidBasis()Basis ::= AxisName '::' NodeTest | AbbreviatedBasisprotected voidBooleanExpr()StringExpr ::= Exprprotected StringdumpRemainingTokenQueue()Dump the remaining token queue.protected intEqualityExpr(int addPos)protected voidExpr()Expr ::= OrExprprotected intFilterExpr()FilterExpr ::= PrimaryExpr | FilterExpr Predicateprotected booleanFunctionCall()FunctionCall ::= FunctionName '(' ( Argument ( ',' Argument)*)? ')'ErrorListenergetErrorListener()Return the current error listener.protected voidIdKeyPattern()IdKeyPattern ::= 'id' '(' Literal ')' | 'key' '(' Literal ',' Literal ')' (Also handle doc())voidinitMatchPattern(Compiler compiler, String expression, PrefixResolver namespaceContext)Given an string, init an XPath object for pattern matches, in order that a parse doesn't have to be done each time the expression is evaluated.voidinitXPath(Compiler compiler, String expression, PrefixResolver namespaceContext)Given an string, init an XPath object for selections, in order that a parse doesn't have to be done each time the expression is evaluated.protected voidLiteral()The value of the Literal is the sequence of characters inside the " or ' characters>.protected voidLocationPath()LocationPath ::= RelativeLocationPath | AbsoluteLocationPathprotected voidLocationPathPattern()LocationPathPattern ::= '/' RelativePathPattern? | IdKeyPattern (('/' | '//') RelativePathPattern)? | '//'? RelativePathPatternprotected intMultiplicativeExpr(int addPos)This has to handle construction of the operations so that they are evaluated in pre-fix order.protected voidNCName()NCName ::= (Letter | '_') (NCNameChar) NCNameChar ::= Letter | Digit | '.' | '-' | '_' | CombiningChar | Extenderprotected voidNodeTest(int axesType)NodeTest ::= WildcardName | NodeType '(' ')' | 'processing-instruction' '(' Literal ')'protected voidNumber()Number ::= [0-9]+('.'[0-9]+)? | '.'[0-9]+protected voidNumberExpr()NumberExpr ::= Exprprotected voidOrExpr()OrExpr ::= AndExpr | OrExpr 'or' AndExprprotected voidPathExpr()PathExpr ::= LocationPath | FilterExpr | FilterExpr '/' RelativeLocationPath | FilterExpr '//' RelativeLocationPathprotected voidPattern()Pattern ::= LocationPathPattern | Pattern '|' LocationPathPatternprotected voidPredicate()Predicate ::= '[' PredicateExpr ']'protected voidPredicateExpr()PredicateExpr ::= Exprprotected booleanPrimaryExpr()PrimaryExpr ::= VariableReference | '(' Expr ')' | Literal | Number | FunctionCallprotected voidQName()QName ::= (Prefix ':')? LocalPart Prefix ::= NCName LocalPart ::= NCNameprotected intRelationalExpr(int addPos).protected booleanRelativeLocationPath()RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPathprotected voidRelativePathPattern()RelativePathPattern ::= StepPattern | RelativePathPattern '/' StepPattern | RelativePathPattern '//' StepPatternvoidsetErrorHandler(ErrorListener handler)Allow an application to register an error event handler, where syntax errors will be sent.protected booleanStep()Step ::= Basis Predicate | AbbreviatedStepprotected booleanStepPattern(boolean isLeadingSlashPermitted)StepPattern ::= AbbreviatedNodeTestStepprotected voidStringExpr()StringExpr ::= Exprprotected voidUnaryExpr()UnaryExpr ::= UnionExpr | '-' UnaryExprprotected voidUnionExpr()The context of the right hand side expressions is the context of the left hand side expression.
-
Field Details
-
CONTINUE_AFTER_FATAL_ERROR
- See Also:
- Constant Field Values
-
FILTER_MATCH_FAILED
protected static final int FILTER_MATCH_FAILEDResults from checking FilterExpr syntax- See Also:
- Constant Field Values
-
FILTER_MATCH_PRIMARY
protected static final int FILTER_MATCH_PRIMARY- See Also:
- Constant Field Values
-
FILTER_MATCH_PREDICATES
protected static final int FILTER_MATCH_PREDICATES- See Also:
- Constant Field Values
-
-
Constructor Details
-
XPathParser
The parser constructor.
-
-
Method Details
-
initXPath
public void initXPath(Compiler compiler, String expression, PrefixResolver namespaceContext) throws TransformerExceptionGiven an string, init an XPath object for selections, in order that a parse doesn't have to be done each time the expression is evaluated.- Parameters:
compiler- The compiler object.expression- A string conforming to the XPath grammar.namespaceContext- An object that is able to resolve prefixes in the XPath to namespaces.- Throws:
TransformerException
-
initMatchPattern
public void initMatchPattern(Compiler compiler, String expression, PrefixResolver namespaceContext) throws TransformerExceptionGiven an string, init an XPath object for pattern matches, in order that a parse doesn't have to be done each time the expression is evaluated.- Parameters:
compiler- The XPath object to be initialized.expression- A String representing the XPath.namespaceContext- An object that is able to resolve prefixes in the XPath to namespaces.- Throws:
TransformerException
-
setErrorHandler
Allow an application to register an error event handler, where syntax errors will be sent. If the error listener is not set, syntax errors will be sent to System.err.- Parameters:
handler- Reference to error listener where syntax errors will be sent.
-
getErrorListener
Return the current error listener.- Returns:
- The error listener, which should not normally be null, but may be.
-
dumpRemainingTokenQueue
Dump the remaining token queue. Thanks to Craig for this.- Returns:
- A dump of the remaining token queue, which may be appended to an error message.
-
Expr
Expr ::= OrExpr- Throws:
TransformerException
-
OrExpr
OrExpr ::= AndExpr | OrExpr 'or' AndExpr- Throws:
TransformerException
-
AndExpr
AndExpr ::= EqualityExpr | AndExpr 'and' EqualityExpr- Throws:
TransformerException
-
EqualityExpr
- Parameters:
addPos- Position where expression is to be added, or -1 for append.- Returns:
- the position at the end of the equality expression.
- Throws:
TransformerException
-
RelationalExpr
.- Parameters:
addPos- Position where expression is to be added, or -1 for append.- Returns:
- the position at the end of the relational expression.
- Throws:
TransformerException
-
AdditiveExpr
This has to handle construction of the operations so that they are evaluated in pre-fix order. So, for 9+7-6, instead of |+|9|-|7|6|, this needs to be evaluated as |-|+|9|7|6|. AdditiveExpr ::= MultiplicativeExpr | AdditiveExpr '+' MultiplicativeExpr | AdditiveExpr '-' MultiplicativeExpr- Parameters:
addPos- Position where expression is to be added, or -1 for append.- Returns:
- the position at the end of the equality expression.
- Throws:
TransformerException
-
MultiplicativeExpr
This has to handle construction of the operations so that they are evaluated in pre-fix order. So, for 9+7-6, instead of |+|9|-|7|6|, this needs to be evaluated as |-|+|9|7|6|. MultiplicativeExpr ::= UnaryExpr | MultiplicativeExpr MultiplyOperator UnaryExpr | MultiplicativeExpr 'div' UnaryExpr | MultiplicativeExpr 'mod' UnaryExpr | MultiplicativeExpr 'quo' UnaryExpr- Parameters:
addPos- Position where expression is to be added, or -1 for append.- Returns:
- the position at the end of the equality expression.
- Throws:
TransformerException
-
UnaryExpr
UnaryExpr ::= UnionExpr | '-' UnaryExpr- Throws:
TransformerException
-
StringExpr
StringExpr ::= Expr- Throws:
TransformerException
-
BooleanExpr
StringExpr ::= Expr- Throws:
TransformerException
-
NumberExpr
NumberExpr ::= Expr- Throws:
TransformerException
-
UnionExpr
The context of the right hand side expressions is the context of the left hand side expression. The results of the right hand side expressions are node sets. The result of the left hand side UnionExpr is the union of the results of the right hand side expressions. UnionExpr ::= PathExpr | UnionExpr '|' PathExpr- Throws:
TransformerException
-
PathExpr
PathExpr ::= LocationPath | FilterExpr | FilterExpr '/' RelativeLocationPath | FilterExpr '//' RelativeLocationPath- Throws:
XSLProcessorException- thrown if the active ProblemListener and XPathContext decide the error condition is severe enough to halt processing.TransformerException
-
FilterExpr
FilterExpr ::= PrimaryExpr | FilterExpr Predicate- Returns:
- FILTER_MATCH_PREDICATES, if this method successfully matched a FilterExpr with one or more Predicates; FILTER_MATCH_PRIMARY, if this method successfully matched a FilterExpr that was just a PrimaryExpr; or FILTER_MATCH_FAILED, if this method did not match a FilterExpr
- Throws:
XSLProcessorException- thrown if the active ProblemListener and XPathContext decide the error condition is severe enough to halt processing.TransformerException
-
PrimaryExpr
PrimaryExpr ::= VariableReference | '(' Expr ')' | Literal | Number | FunctionCall- Returns:
- true if this method successfully matched a PrimaryExpr
- Throws:
TransformerException
-
Argument
Argument ::= Expr- Throws:
TransformerException
-
FunctionCall
FunctionCall ::= FunctionName '(' ( Argument ( ',' Argument)*)? ')'- Returns:
- true if, and only if, a FunctionCall was matched
- Throws:
TransformerException
-
LocationPath
LocationPath ::= RelativeLocationPath | AbsoluteLocationPath- Throws:
TransformerException
-
RelativeLocationPath
RelativeLocationPath ::= Step | RelativeLocationPath '/' Step | AbbreviatedRelativeLocationPath- Throws:
TransformerException
-
Step
Step ::= Basis Predicate | AbbreviatedStep- Throws:
TransformerException
-
Basis
Basis ::= AxisName '::' NodeTest | AbbreviatedBasis- Throws:
TransformerException
-
AxisName
Basis ::= AxisName '::' NodeTest | AbbreviatedBasis- Returns:
- FROM_XXX axes type, found in
Keywords. - Throws:
TransformerException
-
NodeTest
NodeTest ::= WildcardName | NodeType '(' ')' | 'processing-instruction' '(' Literal ')'- Parameters:
axesType- FROM_XXX axes type, found inKeywords.- Throws:
TransformerException
-
Predicate
Predicate ::= '[' PredicateExpr ']'- Throws:
TransformerException
-
PredicateExpr
PredicateExpr ::= Expr- Throws:
TransformerException
-
QName
QName ::= (Prefix ':')? LocalPart Prefix ::= NCName LocalPart ::= NCName- Throws:
TransformerException
-
NCName
protected void NCName()NCName ::= (Letter | '_') (NCNameChar) NCNameChar ::= Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender -
Literal
The value of the Literal is the sequence of characters inside the " or ' characters>. Literal ::= '"' [^"]* '"' | "'" [^']* "'"- Throws:
TransformerException
-
Number
Number ::= [0-9]+('.'[0-9]+)? | '.'[0-9]+- Throws:
TransformerException
-
Pattern
Pattern ::= LocationPathPattern | Pattern '|' LocationPathPattern- Throws:
TransformerException
-
LocationPathPattern
LocationPathPattern ::= '/' RelativePathPattern? | IdKeyPattern (('/' | '//') RelativePathPattern)? | '//'? RelativePathPattern- Throws:
TransformerException
-
IdKeyPattern
IdKeyPattern ::= 'id' '(' Literal ')' | 'key' '(' Literal ',' Literal ')' (Also handle doc())- Throws:
TransformerException
-
RelativePathPattern
RelativePathPattern ::= StepPattern | RelativePathPattern '/' StepPattern | RelativePathPattern '//' StepPattern- Throws:
TransformerException
-
StepPattern
StepPattern ::= AbbreviatedNodeTestStep- Parameters:
isLeadingSlashPermitted- a boolean indicating whether a slash can appear at the start of this step- Returns:
- boolean indicating whether a slash following the step was consumed
- Throws:
TransformerException
-
AbbreviatedNodeTestStep
protected boolean AbbreviatedNodeTestStep(boolean isLeadingSlashPermitted) throws TransformerExceptionAbbreviatedNodeTestStep ::= '@'? NodeTest Predicate- Parameters:
isLeadingSlashPermitted- a boolean indicating whether a slash can appear at the start of this step- Returns:
- boolean indicating whether a slash following the step was consumed
- Throws:
TransformerException
-