Package org.htmlunit.xpath.compiler
Class Lexer
java.lang.Object
org.htmlunit.xpath.compiler.Lexer
This class is in charge of lexical processing of the XPath expression into tokens.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Compiler
The target XPath.(package private) final PrefixResolver
The prefix resolver to map prefixes to namespaces in the XPath.private int[]
Ignore this, it is going away.private int
Ignore this, it is going away.(package private) final XPathParser
The XPath processor object.(package private) static final int
This value is added to each element name in the TARGETEXTRA that is a 'target' (right-most top-level element name). -
Constructor Summary
ConstructorsConstructorDescriptionLexer
(Compiler compiler, PrefixResolver resolver, XPathParser xpathProcessor) Create a Lexer object. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
Add a token to the token queue.(package private) final int
getKeywordToken
(String key) Given a string, return the corresponding keyword token.private int
getTokenQueuePosFromMap
(int i) Given a map pos, return the corresponding token queue pos.private int
mapNSTokens
(String pat, int startSubstring, int posOfNSSep, int posOfScan) When a seperator token is found, see if there's a element name or the like to map.private boolean
mapPatternElemPos
(int nesting, boolean isStart, boolean isAttrName) Record the current position on the token queue as long as this is a top-level element.private void
recordTokenString
(List<String> targetStrings) Record the current token in the passed vector.private void
resetTokenMark
(int mark) Reset token queue mark and m_token to a given position.(package private) void
Walk through the expression and build a token queue, and a map of the top-level elements.
-
Field Details
-
m_compiler
The target XPath. -
m_namespaceContext
The prefix resolver to map prefixes to namespaces in the XPath. -
m_processor
The XPath processor object. -
TARGETEXTRA
static final int TARGETEXTRAThis value is added to each element name in the TARGETEXTRA that is a 'target' (right-most top-level element name).- See Also:
-
m_patternMap
private int[] m_patternMapIgnore this, it is going away. This holds a map to the m_tokenQueue that tells where the top-level elements are. It is used for pattern matching so the m_tokenQueue can be walked backwards. Each element that is a 'target', (right-most top level element name) has TARGETEXTRA added to it. -
m_patternMapSize
private int m_patternMapSizeIgnore this, it is going away. The number of elements that m_patternMap maps;
-
-
Constructor Details
-
Lexer
Lexer(Compiler compiler, PrefixResolver resolver, XPathParser xpathProcessor) Create a Lexer object.- Parameters:
compiler
- The owning compiler for this lexer.resolver
- The prefix resolver for mapping qualified name prefixes to namespace URIs.xpathProcessor
- The parser that is processing strings to opcodes.
-
-
Method Details
-
tokenize
Walk through the expression and build a token queue, and a map of the top-level elements.- Parameters:
pat
- XSLT Expression.targetStrings
- Vector to hold Strings, may be null.- Throws:
TransformerException
- if any
-
mapPatternElemPos
private boolean mapPatternElemPos(int nesting, boolean isStart, boolean isAttrName) Record the current position on the token queue as long as this is a top-level element. Must be called before the next token is added to the m_tokenQueue.- Parameters:
nesting
- The nesting count for the pattern element.isStart
- true if this is the start of a pattern.isAttrName
- true if we have determined that this is an attribute name.- Returns:
- true if this is the start of a pattern.
-
getTokenQueuePosFromMap
private int getTokenQueuePosFromMap(int i) Given a map pos, return the corresponding token queue pos.- Parameters:
i
- The index in the m_patternMap.- Returns:
- the token queue position.
-
resetTokenMark
private void resetTokenMark(int mark) Reset token queue mark and m_token to a given position.- Parameters:
mark
- The new position.
-
getKeywordToken
Given a string, return the corresponding keyword token.- Parameters:
key
- The keyword.- Returns:
- An opcode value.
-
recordTokenString
Record the current token in the passed vector.- Parameters:
targetStrings
- Vector of string.
-
addToTokenQueue
Add a token to the token queue.- Parameters:
s
- The token.
-
mapNSTokens
private int mapNSTokens(String pat, int startSubstring, int posOfNSSep, int posOfScan) throws TransformerException When a seperator token is found, see if there's a element name or the like to map.- Parameters:
pat
- The XPath name string.startSubstring
- The start of the name string.posOfNSSep
- The position of the namespace seperator (':').posOfScan
- The end of the name index.- Returns:
- -1 always.
- Throws:
TransformerException
- if any
-