java.lang.Object
com.tangosol.coherence.dsltools.precedence.OPScanner

public class OPScanner extends Object
OPScanner gives clients a streaming api that returns a next OPToken by processing a java.lang.String using a TokenTable to convert lower level BaseTokens into the high functionality OPTokens. Since BaseTokens support a composite sequence token OPScanner supports nested scanning.
Author:
djl 2009.03.02
  • Field Details

    • m_data

      protected BaseTokenStream m_data
      The source of BaseTokens to process
    • m_current

      protected BaseToken m_current
      The current BaseTokens from data
    • m_currentToken

      protected OPToken m_currentToken
      The current OPToken translated from current
    • m_tokenTable

      protected TokenTable m_tokenTable
      The TokenTable that defines the translation from BaseTokens to OPTokens
    • m_setOperators

      protected Set<CharSequence> m_setOperators
      The set of valid operators used by this scanner
  • Constructor Details

    • OPScanner

      public OPScanner(TokenTable tokenTable, Set<CharSequence> setOperators)
      Construct a new OPScanner using the given TokenTable.
      Parameters:
      tokenTable - the TokenTable that defines the mapping from BaseTokens
      setOperators - the set of operators to use
  • Method Details

    • scan

      public void scan(String s)
      Initialize a new OPScanner to process the given String and load first token into current.
      Parameters:
      s - the String to convert to a stream of tokens
    • scan

      public void scan(Reader r)
      Initialize a new OPScanner to process the given Reader and load first token into current.
      Parameters:
      r - the Reader to use as source for a stream of tokens
    • reset

      public void reset()
      Reset this scanner to process the current BaseTokenStream
    • setStrictness

      public void setStrictness(boolean fStrict)
      The given flag determines the strictness in that an unknown token throws an exception otherwise they are turned into an identifier. The default setting is false.
      Parameters:
      fStrict - boolean to control the strictness
    • next

      public OPToken next()
      Move to the next token in the stream and return it.
      Returns:
      the current token
    • isEnd

      public boolean isEnd()
      If the Scanner is at the end answer true otherwise answer false.
      Returns:
      the boolean that answers as to whether the stream is atEnd
    • isEndOfStatement

      public boolean isEndOfStatement()
      If the scanner is at the end of a statement return true. A statement end is signified by either a semi-colon or the end of the token stream.
      Returns:
      true if the scanner is at the end of a statement
    • getCurrent

      public OPToken getCurrent()
      Answer the current OPToken.
      Returns:
      the current token
    • getCurrentBaseToken

      public BaseToken getCurrentBaseToken()
      Answer the current BaseToken.
      Returns:
      the current BaseToken
    • getCurrentAsString

      public String getCurrentAsString()
      Answer the string representation of the current BaseToken.
      Returns:
      the string representation of the current BaseToken
    • peekNextAsString

      public String peekNextAsString()
      Answer the string representation of the next BaseToken.
      Returns:
      the string representation of the next BaseToken
    • peekNext

      public BaseToken peekNext()
      Answer the string representation of the next BaseToken.
      Returns:
      the string representation of the next BaseToken
    • peekNext2AsStrings

      public String[] peekNext2AsStrings()
      Answer the String[] representation of the next two BaseTokens.
      Returns:
      the String[] representation of the next BaseToken
    • getCurrentAsStringWithAdvance

      public String getCurrentAsStringWithAdvance()
      Answer the string representation of the current BaseToken and advance.
      Returns:
      the string representation of the current BaseToken
    • matches

      public boolean matches(String sWord)
      Test to see if the current BaseToken's string matches the given string. The token table's ignoringCase flag is consulted to see if case matters.
      Parameters:
      sWord - the string to match with
      Returns:
      a boolean indication of the success of the match
    • matches

      public boolean matches(String sWord, boolean fIgnoreCase)
      Test to see if the current BaseToken's string matches the given string. The given flag controls whether case is interesting.
      Parameters:
      sWord - the string to match with
      fIgnoreCase - the flag that indicates if case is interesting
      Returns:
      a boolean indication of the success of the match
    • advanceWhenMatching

      public boolean advanceWhenMatching(String sWord)
      Test to see if the current BaseToken's string matches the given string and advance if true. * The token table's ignoringCase flag is consulted to see if case matters.
      Parameters:
      sWord - the string to match with
      Returns:
      a boolean indication of the success of the match
    • advance

      public OPToken advance(String s)
      Advance to the next token and expect it to match the given string. If expectations are not met then throw an Exception. The token table's ignoringCase flag is consulted to see if case matters.
      Parameters:
      s - the string that should match the next token
      Returns:
      the next OPToken
    • advance

      public OPToken advance(String s, boolean fIgnoreCase)
      Advance to the next token and expect it to match the given string. If expectations are not met then throw an Exception. The given flag controls whether case is interesting.
      Parameters:
      s - the string that should match the next token
      fIgnoreCase - the flag that indicates if case is interesting
      Returns:
      the next OPToken
    • advance

      public OPToken advance()
      Advance to the next token.
      Returns:
      the next OPToken
    • pushStream

      public void pushStream(BaseTokenStream ts)
      Remember the current BaseTokenStream and stream over the given stream.
      Parameters:
      ts - the BaseTokenStream to now stream over
    • popStream

      public void popStream()
      Restore the remembered BaseTokenStream as the source of streaming.
    • enableTokenNamed

      public void enableTokenNamed(String name)
      Enable the token named by the given string.
      Parameters:
      name - the name of the OPToken to enable
    • disableTokenNamed

      public void disableTokenNamed(String name)
      Disable the token named by the given string.
      Parameters:
      name - the name of the OPToken to disable
    • classify

      protected OPToken classify()
      Figure out how to map the current BaseToken to a OPToken and return it.
      Returns:
      the current OPToken