use enumerate in place of 'for ti in range(i, tokens.len()) ... match tokens[ti] ...'