protected String parseUntilTerminator ( DdlTokenStream tokens ) throws ParsingException { final StringBuilder sb = new StringBuilder ( ) ; boolean lastTokenWasPeriod = false ; Position prevPosition = ( tokens . hasNext ( ) ? tokens . nextPosition ( ) : Position . EMPTY_CONTENT_POSITION ) ; String prevToken = "" ; while ( tokens . hasNext ( ) && ! tokens . matches ( DdlTokenizer . STATEMENT_KEY ) && ( ( doUseTerminator ( ) && ! isTerminator ( tokens ) ) || ! doUseTerminator ( ) ) ) { final Position currPosition = tokens . nextPosition ( ) ; final String thisToken = tokens . consume ( ) ; final boolean thisTokenIsPeriod = thisToken . equals ( PERIOD ) ; final boolean thisTokenIsComma = thisToken . equals ( COMMA ) ; if ( lastTokenWasPeriod || thisTokenIsPeriod || thisTokenIsComma ) { sb . append ( thisToken ) ; } else if ( ( currPosition . getIndexInContent ( ) - prevPosition . getIndexInContent ( ) - prevToken . length ( ) ) > 0 ) { sb . append ( SPACE ) . append ( thisToken ) ; } else { sb . append ( thisToken ) ; } if ( thisTokenIsPeriod ) { lastTokenWasPeriod = true ; } else { lastTokenWasPeriod = false ; } prevToken = thisToken ; prevPosition = currPosition ; } return sb . toString ( ) ; }
Utility method which parses tokens until a terminator is found another statement is identified or there are no more tokens .