Package nl.rrd.wool.expressions
Class Tokenizer
- java.lang.Object
-
- nl.rrd.wool.expressions.Tokenizer
-
public class Tokenizer extends Object
A tokenizer can read tokens from text input. It is used by theExpressionParser. A token is an atomic element of an expression.After construction, you can read tokens with
readToken(). If you construct the tokenizer with aLineColumnNumberReader, then you can rewind the input after each call ofreadToken(), regardless of whether it returns a token or null or a parse error. Rewinding can be useful if the tokens are embedded inside other text input.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the tokenizer and the input reader.intgetColNum()Returns the current column number.intgetLineNum()Returns the current line number.LineColumnNumberReadergetReader()Returns the reader used by this tokenizer.TokenreadToken()Tries to read the next token.voidrewind()Rewinds theLineColumnNumberReaderso it is reset to the same position as before the last call ofreadToken().
-
-
-
Constructor Detail
-
Tokenizer
public Tokenizer(String input)
-
Tokenizer
public Tokenizer(Reader reader)
-
Tokenizer
public Tokenizer(LineColumnNumberReader reader)
-
-
Method Detail
-
getReader
public LineColumnNumberReader getReader()
Returns the reader used by this tokenizer.- Returns:
- the reader
-
close
public void close() throws IOExceptionCloses the tokenizer and the input reader.- Throws:
IOException- if the reader can't be closed
-
readToken
public Token readToken() throws LineNumberParseException, IOException
Tries to read the next token. If the end of input is reached, this method returns null.- Returns:
- the token or null
- Throws:
LineNumberParseException- if a parse error occursIOException- if a reading error occurs
-
getLineNum
public int getLineNum()
Returns the current line number.- Returns:
- the current line number
-
getColNum
public int getColNum()
Returns the current column number.- Returns:
- the current column number
-
rewind
public void rewind() throws IOExceptionRewinds theLineColumnNumberReaderso it is reset to the same position as before the last call ofreadToken().- Throws:
IOException- if an I/O error occurs
-
-