public class Tokenizer
extends java.lang.Object
Tokenizer takes an input stream of character and turns it into a stream of Tokens.
Each Token represents a high-level component of the template. For example, the following template:
Text {{ hello }} stuff {% if (blah) %} more stuff {% end %}
Corresponds to the following stream of tokens:
TokenType=FIXED, Content="Text "
TokenType=ECHO, Content=" hello "
TokenType=FIXED, Content=" stuff "
TokenType=TAG, Content=" if (blah) "
TokenType=FIXED, Content=" more stuff "
TokenType=TAG, Content=" end "| Constructor and Description |
|---|
Tokenizer(LineReader ins)
|
Tokenizer(LineReader ins,
TokenFactory tokenFactory)
|
| Modifier and Type | Method and Description |
|---|---|
Token |
getNextToken()
Gets the next token from the stream, or null if there's no tokens left.
|
ResourcePointer |
getPointer() |
public Tokenizer(LineReader ins)
ins - A LineReader to read tokens from.public Tokenizer(LineReader ins, @Nullable TokenFactory tokenFactory)
ins - A LineReader to read tokens from.tokenFactory - A TokenFactory for creating the tokens. If null, a default token factory that just
creates instances of Token is used.@Nullable public Token getNextToken() throws CarrotException
Token in the stream, or null if we're at the end of the stream.CarrotException - when there's an error parsing the tokens.public ResourcePointer getPointer()
ResourcePointer, useful for outputting where in the file an error occurred.