Class TokenStream

java.lang.Object
io.pebbletemplates.pebble.lexer.TokenStream

public class TokenStream extends Object
  • Field Details

    • tokens

      private ArrayList<Token> tokens
    • current

      private int current
    • filename

      private String filename
  • Constructor Details

    • TokenStream

      public TokenStream(Collection<Token> tokens, String name)
      Constructor for a Token Stream
      Parameters:
      tokens - A collection of tokens
      name - The filename of the template that these tokens came from
  • Method Details

    • next

      public Token next()
      Consumes and returns the next token in the stream.
      Returns:
      The next token
    • expect

      public Token expect(Token.Type type)
      Checks the current token to see if it matches the provided type. If it doesn't match this will throw a SyntaxException. This will consume a token.
      Parameters:
      type - The type of token that we expect
      Returns:
      Token The current token
    • expect

      public Token expect(Token.Type type, String value)
      Checks the current token to see if it matches the provided type. If it doesn't match this will throw a SyntaxException. This will consume a token.
      Parameters:
      type - The type of token that we expect
      value - The expected value of the token
      Returns:
      Token The current token
    • peek

      public Token peek()
      Returns the next token in the stream without consuming it.
      Returns:
      The next token
    • peek

      public Token peek(int number)
      Returns a future token in the stream without consuming any.
      Parameters:
      number - How many tokens to lookahead
      Returns:
      The token we are peeking at
    • isEOF

      public boolean isEOF()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • current

      public Token current()
      Looks at the current token. Does not consume the token.
      Returns:
      Token The current token
    • getFilename

      public String getFilename()
    • getTokens

      public ArrayList<Token> getTokens()
      used for testing purposes
      Returns:
      List of tokens