ranges: break the range list parsing into a separate function