@ Nullable public ExpressionItem readExpression ( @ Nonnull final PushbackReader reader , @ Nonnull final ExpressionTree tree , @ Nonnull final PreprocessorContext context , final boolean insideBracket , final boolean argument ) throws IOException { boolean working = true ; ExpressionItem result = null ; final FilePositionInfo [ ] stack ; final String sourceLine ; final PreprocessingState state = context . getPreprocessingState ( ) ; stack = state . makeIncludeStack ( ) ; sourceLine = state . getLastReadString ( ) ; ExpressionItem prev = null ; while ( working ) { final ExpressionItem nextItem = nextItem ( reader , context ) ; if ( nextItem == null ) { working = false ; result = null ; } else if ( nextItem . getExpressionItemType ( ) == ExpressionItemType . SPECIAL ) { if ( nextItem == SpecialItem . BRACKET_CLOSING ) { if ( insideBracket ) { working = false ; result = nextItem ; } else if ( argument ) { working = false ; result = nextItem ; } else { final String text = "Detected alone closing bracket" ; throw context . makeException ( "Detected alone closing bracket" , null ) ; } } else if ( nextItem == SpecialItem . BRACKET_OPENING ) { if ( prev != null && prev . getExpressionItemType ( ) == ExpressionItemType . VARIABLE ) { final String text = "Unknown function detected [" + prev . toString ( ) + ' ' ; throw context . makeException ( text , null ) ; } final ExpressionTree subExpression ; subExpression = new ExpressionTree ( stack , sourceLine ) ; if ( SpecialItem . BRACKET_CLOSING != readExpression ( reader , subExpression , context , true , false ) ) { final String text = "Detected unclosed bracket" ; throw context . makeException ( text , null ) ; } tree . addTree ( subExpression ) ; } else if ( nextItem == SpecialItem . COMMA ) { return nextItem ; } } else if ( nextItem . getExpressionItemType ( ) == ExpressionItemType . FUNCTION ) { final AbstractFunction function = ( AbstractFunction ) nextItem ; ExpressionTree functionTree = readFunction ( function , reader , context , stack , sourceLine ) ; tree . addTree ( functionTree ) ; } else { tree . addItem ( nextItem ) ; } prev = nextItem ; } return result ; }
It reads an expression from a reader and fill a tree