org.apache.xpath.compiler
Class Lexer

java.lang.Object
  extended by org.apache.xpath.compiler.Lexer

 class Lexer
extends java.lang.Object

This class is in charge of lexical processing of the XPath expression into tokens.


Field Summary
private  Compiler m_compiler
          The target XPath.
(package private)  PrefixResolver m_namespaceContext
          The prefix resolver to map prefixes to namespaces in the XPath.
private  int[] m_patternMap
          Ignore this, it is going away.
private  int m_patternMapSize
          Ignore this, it is going away.
(package private)  XPathParser m_processor
          The XPath processor object.
(package private) static int TARGETEXTRA
          This value is added to each element name in the TARGETEXTRA that is a 'target' (right-most top-level element name).
 
Constructor Summary
Lexer(Compiler compiler, PrefixResolver resolver, XPathParser xpathProcessor)
          Create a Lexer object.
 
Method Summary
private  void addToTokenQueue(java.lang.String s)
          Add a token to the token queue.
(package private)  int getKeywordToken(java.lang.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(java.lang.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(java.util.Vector 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 tokenize(java.lang.String pat)
          Walk through the expression and build a token queue, and a map of the top-level elements.
(package private)  void tokenize(java.lang.String pat, java.util.Vector targetStrings)
          Walk through the expression and build a token queue, and a map of the top-level elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_compiler

private Compiler m_compiler
The target XPath.


m_namespaceContext

PrefixResolver m_namespaceContext
The prefix resolver to map prefixes to namespaces in the XPath.


m_processor

XPathParser m_processor
The XPath processor object.


TARGETEXTRA

static final int TARGETEXTRA
This value is added to each element name in the TARGETEXTRA that is a 'target' (right-most top-level element name).

See Also:
Constant Field Values

m_patternMap

private int[] m_patternMap
Ignore 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_patternMapSize
Ignore this, it is going away. The number of elements that m_patternMap maps;

Constructor Detail

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 Detail

tokenize

void tokenize(java.lang.String pat)
        throws javax.xml.transform.TransformerException
Walk through the expression and build a token queue, and a map of the top-level elements.

Parameters:
pat - XSLT Expression.
Throws:
javax.xml.transform.TransformerException

tokenize

void tokenize(java.lang.String pat,
              java.util.Vector targetStrings)
        throws javax.xml.transform.TransformerException
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:
javax.xml.transform.TransformerException

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 final void resetTokenMark(int mark)
Reset token queue mark and m_token to a given position.

Parameters:
mark - The new position.

getKeywordToken

final int getKeywordToken(java.lang.String key)
Given a string, return the corresponding keyword token.

Parameters:
key - The keyword.
Returns:
An opcode value.

recordTokenString

private void recordTokenString(java.util.Vector targetStrings)
Record the current token in the passed vector.

Parameters:
targetStrings - Vector of string.

addToTokenQueue

private final void addToTokenQueue(java.lang.String s)
Add a token to the token queue.

Parameters:
s - The token.

mapNSTokens

private int mapNSTokens(java.lang.String pat,
                        int startSubstring,
                        int posOfNSSep,
                        int posOfScan)
                 throws javax.xml.transform.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:
javax.xml.transform.TransformerException