Interface CssTokenizer

All Known Implementing Classes:
ListCssTokenizer, StreamCssTokenizer

public interface CssTokenizer
Defines the API of a CSS Tokenizer.
Author:
Werner Randelshofer
  • Method Details

    • currentValue

      default @Nullable String currentValue()
      Returns the current value converted to a string. The returned value can be used for String comparisons of the value.
      Returns:
      the current value
    • currentNumber

      @Nullable Number currentNumber()
    • currentNumberNonNull

      default @NonNull Number currentNumberNonNull()
    • currentString

      @Nullable String currentString()
      Returns the current string value.
      Returns:
      the current string value
    • currentStringNonNull

      default @NonNull String currentStringNonNull()
    • current

      int current()
      Returns the current token type.
      Returns:
      the current token type
    • getLineNumber

      int getLineNumber()
    • getSourceLocator

      @Nullable SourceLocator getSourceLocator()
    • getStartPosition

      int getStartPosition()
    • getEndPosition

      int getEndPosition()
    • getNextPosition

      int getNextPosition()
      Gets the current position.
      Returns:
      the start position of the token if a token has been pushed back, the end position of the token otherwise
    • next

      int next() throws IOException
      Gets the next token skipping whitespaces and comments.
      Returns:
      the next non-whitespace token
      Throws:
      IOException - on io exception
    • nextNoSkip

      int nextNoSkip() throws IOException
      Gets the next token without skipping whitespaces and comments.
      Returns:
      the next token
      Throws:
      IOException - on io exception
    • skipIfPresent

      default void skipIfPresent(int ttype) throws IOException
      Skips the next token if it is of type ttype.
      Parameters:
      ttype - the token type t skip
      Throws:
      IOException
    • nextIsIdentNone

      default boolean nextIsIdentNone() throws IOException
      Invokes next() and checks if it is a "none" identifier.
      Returns:
      true if "none"
      Throws:
      IOException - on io error
    • currentIsIdentNone

      default boolean currentIsIdentNone()
      Invokes current() and checks if it is a "none" identifier.
      Returns:
      true if "none"
    • requireNextToken

      default void requireNextToken(int ttype, String message) throws ParseException, IOException
      Fetches the next token and throws a parse exception if it is not of the required type.
      Parameters:
      ttype - the required token type
      message - the error message
      Throws:
      ParseException - if the token is not of the required type
      IOException - on IO exception
    • createParseException

      default ParseException createParseException(String message)
      Creates a parse exception which contains the specified message, the token that was found, and the current position of the tokenizier.
      Parameters:
      message - the message
      Returns:
      a new parse exception
    • requireNextNoSkip

      default void requireNextNoSkip(int ttype, String message) throws ParseException, IOException
      Fetches the next token and throws a parse exception if it is not of the required type.
      Parameters:
      ttype - the required token type
      message - the error message
      Throws:
      ParseException - if the token is not of the required type
      IOException - on IO exception
    • pushBack

      void pushBack()
      Pushes the current token back.
    • getToken

      CssToken getToken()
    • toTokenList

      default @NonNull List<CssToken> toTokenList() throws IOException
      Scans the remaining tokens and adds them to a list.
      Returns:
      a new list
      Throws:
      IOException - on io exception