Package io.pebbletemplates.pebble.lexer
Class TokenStream
- java.lang.Object
-
- io.pebbletemplates.pebble.lexer.TokenStream
-
public class TokenStream extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description TokenStream(java.util.Collection<Token> tokens, java.lang.String name)
Constructor for a Token Stream
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Token
current()
Looks at the current token.Token
expect(Token.Type type)
Checks the current token to see if it matches the provided type.Token
expect(Token.Type type, java.lang.String value)
Checks the current token to see if it matches the provided type.java.lang.String
getFilename()
java.util.ArrayList<Token>
getTokens()
used for testing purposesboolean
isEOF()
Token
next()
Consumes and returns the next token in the stream.Token
peek()
Returns the next token in the stream without consuming it.Token
peek(int number)
Returns a future token in the stream without consuming any.java.lang.String
toString()
-
-
-
Field Detail
-
tokens
private java.util.ArrayList<Token> tokens
-
current
private int current
-
filename
private java.lang.String filename
-
-
Constructor Detail
-
TokenStream
public TokenStream(java.util.Collection<Token> tokens, java.lang.String name)
Constructor for a Token Stream- Parameters:
tokens
- A collection of tokensname
- The filename of the template that these tokens came from
-
-
Method Detail
-
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, java.lang.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 expectvalue
- 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 java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
current
public Token current()
Looks at the current token. Does not consume the token.- Returns:
- Token The current token
-
getFilename
public java.lang.String getFilename()
-
getTokens
public java.util.ArrayList<Token> getTokens()
used for testing purposes- Returns:
- List of tokens
-
-