public void parse ( final SelectStatement selectStatement ) { if ( ! lexerEngine . skipIfEqual ( SQLServerKeyword . TOP ) ) { return ; } int beginPosition = lexerEngine . getCurrentToken ( ) . getEndPosition ( ) ; if ( ! lexerEngine . skipIfEqual ( Symbol . LEFT_PAREN ) ) { beginPosition = lexerEngine . getCurrentToken ( ) . getEndPosition ( ) - lexerEngine . getCurrentToken ( ) . getLiterals ( ) . length ( ) ; } SQLExpression sqlExpression = basicExpressionParser . parse ( selectStatement ) ; lexerEngine . skipIfEqual ( Symbol . RIGHT_PAREN ) ; LimitValue rowCountValue ; if ( sqlExpression instanceof SQLNumberExpression ) { int rowCount = ( ( SQLNumberExpression ) sqlExpression ) . getNumber ( ) . intValue ( ) ; rowCountValue = new LimitValue ( rowCount , - 1 , false ) ; selectStatement . addSQLToken ( new RowCountToken ( beginPosition , rowCount ) ) ; } else if ( sqlExpression instanceof SQLParameterMarkerExpression ) { rowCountValue = new LimitValue ( - 1 , ( ( SQLParameterMarkerExpression ) sqlExpression ) . getIndex ( ) , false ) ; } else { throw new SQLParsingException ( lexerEngine ) ; } lexerEngine . unsupportedIfEqual ( SQLServerKeyword . PERCENT ) ; lexerEngine . skipIfEqual ( DefaultKeyword . WITH , SQLServerKeyword . TIES ) ; if ( null == selectStatement . getLimit ( ) ) { Limit limit = new Limit ( ) ; limit . setRowCount ( rowCountValue ) ; selectStatement . setLimit ( limit ) ; } else { selectStatement . getLimit ( ) . setRowCount ( rowCountValue ) ; } }
Parse top .