Package nl.rrd.wool.expressions
Class ExpressionParser
- java.lang.Object
-
- nl.rrd.wool.expressions.ExpressionParser
-
public class ExpressionParser extends Object
An expression parser can readExpressions from text input. After construction, you can read expressions withreadExpression(). If you construct the parser with aLineColumnNumberReader, then you can rewind the input after each call ofreadExpression(), regardless of whether it returns a token or null or a parse error. Rewinding can be useful if an expression is embedded inside other text input.
-
-
Field Summary
Fields Modifier and Type Field Description static Token.Type[][]PRECEDENCE
-
Constructor Summary
Constructors Constructor Description ExpressionParser(Reader reader)ExpressionParser(String input)ExpressionParser(Tokenizer tokenizer)ExpressionParser(LineColumnNumberReader reader)
-
Method Summary
Modifier and Type Method Description voidclose()Closes the parser and the input reader.intgetColNum()Returns the current column number.ExpressionParserConfiggetConfig()intgetLineNum()Returns the current line number.ExpressionreadExpression()Tries to read the next expression.ExpressionreadOperand()Tries to read an operand.voidrewind()Rewinds theLineColumnNumberReaderso it is reset to the same position as before the last call ofreadExpression().voidsetConfig(ExpressionParserConfig config)
-
-
-
Field Detail
-
PRECEDENCE
public static final Token.Type[][] PRECEDENCE
-
-
Constructor Detail
-
ExpressionParser
public ExpressionParser(String input)
-
ExpressionParser
public ExpressionParser(Reader reader)
-
ExpressionParser
public ExpressionParser(LineColumnNumberReader reader)
-
ExpressionParser
public ExpressionParser(Tokenizer tokenizer)
-
-
Method Detail
-
close
public void close() throws IOExceptionCloses the parser and the input reader.- Throws:
IOException- if the reader can't be closed
-
getConfig
public ExpressionParserConfig getConfig()
-
setConfig
public void setConfig(ExpressionParserConfig config)
-
readExpression
public Expression readExpression() throws LineNumberParseException, IOException
Tries to read the next expression. If the end of input is reached, this method returns null.- Returns:
- the expression or null
- Throws:
LineNumberParseException- if a parse error occursIOException- if a reading error occurs
-
readOperand
public Expression readOperand() throws LineNumberParseException, IOException
Tries to read an operand. That is an expression with any operators. If the end of input is reached, this method returns null.- Returns:
- the operand 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 ofreadExpression().- Throws:
IOException- if an I/O error occurs
-
-