[parsing] fix some bugs and improve performance of the scanner