Package com.igormaznitsa.jcp.expression
Class ExpressionParser
- java.lang.Object
-
- com.igormaznitsa.jcp.expression.ExpressionParser
-
public final class ExpressionParser extends java.lang.ObjectThis class is a parser allows to parse an expression and make a tree as the output
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classExpressionParser.ParserStateThe enumeration describes inside states of the parsesstatic classExpressionParser.SpecialItemThe enumeration describes some special items which can be met in the expression
-
Field Summary
Fields Modifier and Type Field Description private static ExpressionParserINSTANCEIt contains the instance for the parser, because the parser is a singletone
-
Constructor Summary
Constructors Constructor Description ExpressionParser()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ExpressionParsergetInstance()private static booleanisDelimiter(char chr)private static booleanisDelimiterOrOperatorChar(char chr)private static booleanisOperatorChar(char chr)(package private) ExpressionItemnextItem(java.io.PushbackReader reader, PreprocessorContext context)Read the next item from the readerExpressionTreeparse(java.lang.String expressionStr, PreprocessorContext context)To parse an expression represented as a string and get a treeExpressionItemreadExpression(java.io.PushbackReader reader, ExpressionTree tree, PreprocessorContext context, boolean insideBracket, boolean argument)It reads an expression from a reader and fill a treeprivate ExpressionTreereadFunction(AbstractFunction function, java.io.PushbackReader reader, PreprocessorContext context, FilePositionInfo[] includeStack, java.lang.String sources)The auxiliary method allows to form a function and its arguments as a tree(package private) ExpressionItemreadFunctionArgument(java.io.PushbackReader reader, ExpressionTree tree, PreprocessorContext context, FilePositionInfo[] callStack, java.lang.String source)The auxiliary method allows to read a function argument
-
-
-
Field Detail
-
INSTANCE
private static final ExpressionParser INSTANCE
It contains the instance for the parser, because the parser is a singletone
-
-
Method Detail
-
getInstance
public static ExpressionParser getInstance()
-
parse
public ExpressionTree parse(java.lang.String expressionStr, PreprocessorContext context) throws java.io.IOException
To parse an expression represented as a string and get a tree- Parameters:
expressionStr- the expression string to be parsed, must not be nullcontext- a preprocessor context to be used to get variable values- Returns:
- a tree containing parsed expression
- Throws:
java.io.IOException- it will be thrown if there is a problem to read the expression string
-
readExpression
public ExpressionItem readExpression(java.io.PushbackReader reader, ExpressionTree tree, PreprocessorContext context, boolean insideBracket, boolean argument) throws java.io.IOException
It reads an expression from a reader and fill a tree- Parameters:
reader- the reader to be used as the character source, must not be nulltree- the result tree to be filled by read items, must not be nullcontext- a preprocessor context to be used for variablesinsideBracket- the flag shows that the expression can be ended by a bracketargument- the flag shows that the expression can be ended by a comma- Returns:
- the last read expression item (a comma or a bracket for instance), it can be null
- Throws:
java.io.IOException- it will be thrown if there is a problem in reading from the reader
-
readFunction
private ExpressionTree readFunction(AbstractFunction function, java.io.PushbackReader reader, PreprocessorContext context, @MustNotContainNull FilePositionInfo[] includeStack, java.lang.String sources) throws java.io.IOException
The auxiliary method allows to form a function and its arguments as a tree- Parameters:
function- the function which arguments will be read from the stream, must not be nullreader- the reader to be used as the character source, must not be nullcontext- a preprocessor context, it will be used for a user functions and variablesincludeStack- the current file include stack, can be nullsources- the current source line, can be null- Returns:
- an expression tree containing parsed function arguments
- Throws:
java.io.IOException- it will be thrown if there is any problem to read chars
-
readFunctionArgument
ExpressionItem readFunctionArgument(java.io.PushbackReader reader, ExpressionTree tree, PreprocessorContext context, @MustNotContainNull FilePositionInfo[] callStack, java.lang.String source) throws java.io.IOException
The auxiliary method allows to read a function argument- Parameters:
reader- a reader to be the character source, must not be nulltree- the result tree to be filled by read items, must not be nullcontext- a preprocessor contextcallStack- the current file call stack, can be nullsource- the current source line, can be null- Returns:
- the last read expression item (a comma or a bracket)
- Throws:
java.io.IOException- it will be thrown if there is any error during char reading from the reader
-
isDelimiterOrOperatorChar
private static boolean isDelimiterOrOperatorChar(char chr)
-
isDelimiter
private static boolean isDelimiter(char chr)
-
isOperatorChar
private static boolean isOperatorChar(char chr)
-
nextItem
ExpressionItem nextItem(java.io.PushbackReader reader, PreprocessorContext context) throws java.io.IOException
Read the next item from the reader- Parameters:
reader- a reader to be used as the char source, must not be nullcontext- a preprocessor context- Returns:
- a read expression item, it can be null if the end is reached
- Throws:
java.io.IOException- it will be thrown if there is any error during a char reading
-
-