Package org.htmlunit.xpath.compiler
Class Compiler
java.lang.Object
org.htmlunit.xpath.compiler.OpMap
org.htmlunit.xpath.compiler.Compiler
An instance of this class compiles an XPath string expression into a Expression object. This
class compiles the string into a sequence of operation codes (op map) and then builds from that
into an Expression tree.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final boolean
private int
private PrefixResolver
The current prefixResolver for the execution context.(package private) final ErrorListener
The error listener where errors will be sent.private final FunctionTable
The FunctionTable for all xpath build-in functionsFields inherited from class org.htmlunit.xpath.compiler.OpMap
BLOCKTOKENQUEUESIZE, m_currentPattern, m_opMap, m_tokenQueue, MAPINDEX_LENGTH, MAXTOKENQUEUESIZE
-
Constructor Summary
ConstructorsConstructorDescriptionCompiler
(ErrorListener errorHandler, FunctionTable fTable) Construct a Compiler object with a specific ErrorListener. -
Method Summary
Modifier and TypeMethodDescriptionprotected Expression
and
(int opPos) Compile an 'and' operation.protected Expression
arg
(int opPos) Compile a function argument.protected Expression
bool
(int opPos) Compile a 'boolean(...)' operation.compile
(int opPos) Execute the XPath object from a given opcode position.(package private) Expression
compileFunction
(int opPos) Compile a built-in XPath function.private Expression
compileOperation
(Operation operation, int opPos) Bottle-neck compilation of an operation with left and right operands.private void
compilePredicates
(int opPos, Expression[] predicates) Compiles predicates in the step.private Expression
compileUnary
(UnaryOperation unary, int opPos) Bottle-neck compilation of a unary operation.int
countPredicates
(int opPos) Count the number of predicates in the step.protected Expression
div
(int opPos) Compile a 'div' operation.protected Expression
equals
(int opPos) Compile a '=' operation.void
Tell the user of an error, and probably throw an exception.getCompiledPredicates
(int opPos) Compile a zero or more predicates for a given match pattern.(package private) FunctionTable
Get the function tableint
Get the level of the location path or union being constructed.Get the current namespace context for the xpath.int
getWhatToShow
(int opPos) Get aNodeFilter
bit set that tells what to show for a given node test.protected Expression
group
(int opPos) Compile an expression group.protected Expression
gt
(int opPos) Compile a '&gr;' operation.protected Expression
gte
(int opPos) Compile a '>=' operation.protected Expression
literal
(int opPos) Compile a literal string value.locationPath
(int opPos) Compile a location path.locationPathPattern
(int opPos) Compile a location match pattern unit expression.protected Expression
lt
(int opPos) Compile a '<' operation.protected Expression
lte
(int opPos) Compile a '<=' operation.protected Expression
matchPattern
(int opPos) Compile an entire match pattern expression.protected Expression
minus
(int opPos) Compile a '-' operation.protected Expression
mod
(int opPos) Compile a 'mod' operation.protected Expression
mult
(int opPos) Compile a '*' operation.protected Expression
neg
(int opPos) Compile a unary '-' operation.protected Expression
notequals
(int opPos) Compile a '!=' operation.protected Expression
number
(int opPos) Compile a 'number(...)' operation.protected Expression
numberlit
(int opPos) Compile a literal number value.protected Expression
or
(int opPos) Compile an 'or' operation.protected Expression
plus
(int opPos) Compile a '+' operation.predicate
(int opPos) Compile a location step predicate expression.void
Set the current namespace context for the xpath.protected StepPattern
stepPattern
(int opPos, int stepCount, StepPattern ancestorPattern) Compile a step pattern unit expression, used for both location paths and match patterns.protected Expression
string
(int opPos) Compile a 'string(...)' operation.protected Expression
union
(int opPos) Compile a location path union.Methods inherited from class org.htmlunit.xpath.compiler.OpMap
getArgLengthOfStep, getFirstChildPos, getFirstChildPosOfStep, getFirstPredicateOpPos, getNextOpPos, getNextStepPos, getOp, getPatternString, getStepLocalName, getStepNS, getStepTestType, getTokenQueue, getTokenQueueSize, setOp, shrink, toString
-
Field Details
-
locPathDepth
private int locPathDepth -
DEBUG
private static final boolean DEBUG- See Also:
-
m_currentPrefixResolver
The current prefixResolver for the execution context. -
m_errorHandler
The error listener where errors will be sent. If this is null, errors and warnings will be sent to System.err. May be null. -
m_functionTable
The FunctionTable for all xpath build-in functions
-
-
Constructor Details
-
Compiler
Construct a Compiler object with a specific ErrorListener.- Parameters:
errorHandler
- Error listener where messages will be sent, or null if messages should be sent to System err.fTable
- The FunctionTable object where the xpath build-in functions are stored.
-
-
Method Details
-
compile
Execute the XPath object from a given opcode position.- Parameters:
opPos
- The current position in the xpath.m_opMap array.- Returns:
- The result of the XPath.
- Throws:
TransformerException
- if there is a syntax or other error.
-
compileOperation
Bottle-neck compilation of an operation with left and right operands.- Parameters:
operation
- non-null reference to parent operation.opPos
- The op map position of the parent operation.- Returns:
- reference to
Operation
instance. - Throws:
TransformerException
- if there is a syntax or other error.
-
compileUnary
Bottle-neck compilation of a unary operation.- Parameters:
unary
- The parent unary operation.opPos
- The position in the op map of the parent operation.- Returns:
- The unary argument.
- Throws:
TransformerException
- if syntax or other error occurs.
-
or
Compile an 'or' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Or
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
and
Compile an 'and' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
And
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
notequals
Compile a '!=' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
NotEquals
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
equals
Compile a '=' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Equals
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
lte
Compile a '<=' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Lte
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
lt
Compile a '<' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Lt
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
gte
Compile a '>=' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Gte
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
gt
Compile a '&gr;' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Gt
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
plus
Compile a '+' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Plus
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
minus
Compile a '-' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Minus
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
mult
Compile a '*' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Mult
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
div
Compile a 'div' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Div
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
mod
Compile a 'mod' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Mod
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
neg
Compile a unary '-' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Neg
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
string
Compile a 'string(...)' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
String
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
bool
Compile a 'boolean(...)' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Bool
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
number
Compile a 'number(...)' operation.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Number
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
literal
Compile a literal string value.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
XString
instance.
-
numberlit
Compile a literal number value.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
XNumber
instance.
-
group
Compile an expression group.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to the contained expression.
- Throws:
TransformerException
- if a error occurs creating the Expression.
-
arg
Compile a function argument.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to the argument expression.
- Throws:
TransformerException
- if a error occurs creating the Expression.
-
union
Compile a location path union. The UnionPathIterator itself may createLocPathIterator
children.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
LocPathIterator
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
getLocationPathDepth
public int getLocationPathDepth()Get the level of the location path or union being constructed.- Returns:
- 0 if it is a top-level path.
-
getFunctionTable
FunctionTable getFunctionTable()Get the function table -
locationPath
Compile a location path. The LocPathIterator itself may createAxesWalker
children.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
LocPathIterator
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
predicate
Compile a location step predicate expression.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- the contained predicate expression.
- Throws:
TransformerException
- if a error occurs creating the Expression.
-
matchPattern
Compile an entire match pattern expression.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
UnionPattern
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
locationPathPattern
Compile a location match pattern unit expression.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
StepPattern
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
getWhatToShow
public int getWhatToShow(int opPos) Get aNodeFilter
bit set that tells what to show for a given node test.- Parameters:
opPos
- the op map position for the location step.- Returns:
NodeFilter
bit set that tells what to show for a given node test.
-
stepPattern
protected StepPattern stepPattern(int opPos, int stepCount, StepPattern ancestorPattern) throws TransformerException Compile a step pattern unit expression, used for both location paths and match patterns.- Parameters:
opPos
- The current position in the m_opMap array.stepCount
- The number of steps to expect.ancestorPattern
- The owning StepPattern, which may be null.- Returns:
- reference to
StepPattern
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
getCompiledPredicates
Compile a zero or more predicates for a given match pattern.- Parameters:
opPos
- The position of the first predicate the m_opMap array.- Returns:
- reference to array of
Expression
instances. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
countPredicates
Count the number of predicates in the step.- Parameters:
opPos
- The position of the first predicate the m_opMap array.- Returns:
- The number of predicates for this step.
- Throws:
TransformerException
- if a error occurs creating the Expression.
-
compilePredicates
Compiles predicates in the step.- Parameters:
opPos
- The position of the first predicate the m_opMap array.predicates
- An empty pre-determined array ofExpression
s, that will be filled in.- Throws:
TransformerException
- if any
-
compileFunction
Compile a built-in XPath function.- Parameters:
opPos
- The current position in the m_opMap array.- Returns:
- reference to
Function
instance. - Throws:
TransformerException
- if a error occurs creating the Expression.
-
error
Tell the user of an error, and probably throw an exception.- Overrides:
error
in classOpMap
- Parameters:
msg
- An error msgkey that corresponds to one of the constants found inXPATHErrorResources
, which is a key for a format string.args
- An array of arguments represented in the format string, which may be null.- Throws:
TransformerException
- if the current ErrorListoner determines to throw an exception.
-
getNamespaceContext
Get the current namespace context for the xpath.- Returns:
- The current prefix resolver, *may* be null, though hopefully not.
-
setNamespaceContext
Set the current namespace context for the xpath.- Parameters:
pr
- The resolver for prefixes in the XPath expression.
-