refactor($parse): simplifying some while(true) loops

Part of #8901