Package com.igormaznitsa.jcp.expression
Class ExpressionParser
java.lang.Object
com.igormaznitsa.jcp.expression.ExpressionParser
This class is a parser allows to parse an expression and make a tree as the output
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static enum
The enumeration describes inside states of the parsesstatic enum
The enumeration describes some special items which can be met in the expression -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ExpressionParser
It contains the instance for the parser, because the parser is a singletone -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ExpressionParser
private static boolean
isDelimiter
(char chr) private static boolean
isDelimiterOrOperatorChar
(char chr) private static boolean
isOperatorChar
(char chr) (package private) ExpressionItem
nextItem
(PushbackReader reader, PreprocessorContext context) Read the next item from the readerparse
(String expressionStr, PreprocessorContext context) To parse an expression represented as a string and get a treereadExpression
(PushbackReader reader, ExpressionTree tree, PreprocessorContext context, boolean insideBracket, boolean argument) It reads an expression from a reader and fill a treeprivate ExpressionTree
readFunction
(AbstractFunction function, PushbackReader reader, PreprocessorContext context, FilePositionInfo[] includeStack, String sources) The auxiliary method allows to form a function and its arguments as a tree(package private) ExpressionItem
readFunctionArgument
(PushbackReader reader, ExpressionTree tree, PreprocessorContext context, FilePositionInfo[] callStack, String source) The auxiliary method allows to read a function argument
-
Field Details
-
INSTANCE
It contains the instance for the parser, because the parser is a singletone
-
-
Constructor Details
-
ExpressionParser
public ExpressionParser()
-
-
Method Details
-
getInstance
-
parse
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:
IOException
- it will be thrown if there is a problem to read the expression string
-
readExpression
public ExpressionItem readExpression(PushbackReader reader, ExpressionTree tree, PreprocessorContext context, boolean insideBracket, boolean argument) throws 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:
IOException
- it will be thrown if there is a problem in reading from the reader
-
readFunction
private ExpressionTree readFunction(AbstractFunction function, PushbackReader reader, PreprocessorContext context, @MustNotContainNull FilePositionInfo[] includeStack, String sources) throws 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:
IOException
- it will be thrown if there is any problem to read chars
-
readFunctionArgument
ExpressionItem readFunctionArgument(PushbackReader reader, ExpressionTree tree, PreprocessorContext context, @MustNotContainNull FilePositionInfo[] callStack, String source) throws 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:
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
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:
IOException
- it will be thrown if there is any error during a char reading
-