

def add_parser_method(name, *_specs):
    if (name in CACHE):
        (otherspec, checker) = CACHE[name]
        assert (otherspec == _specs)
        return checker
    else:
        specs = unroll.unrolling_iterable(map(make_spec, _specs))

        def checker(self):
            arg = self.next()
            for spec in specs:
                if spec.conforms(arg):
                    return arg
            raise_error(self, arg)
        checker.__name__ = name

        def raise_error(self, arg):
            names = ' '.join([spec.repr() for spec in specs])
            if (len(_specs) == 1):
                types = names[0]
            else:
                types = ('(or/c %s)' % names)
            msg = ('%s: expected %s at argument %d got %s' % (self.context, types, self.index, arg.tostring()))
            raise SchemeException(msg)

        @jit.unroll_safe
        def _checker(self):
            length = (len(self.args) - self.index)
            results = ([None] * length)
            for i in range(length):
                results[i] = checker(self)
            return results
    CACHE[name] = (_specs, checker)
    setattr(ArgParser, name, checker)
    setattr(ArgParser, ('_' + name), _checker)
    return checker

dataset/ETHPy150Open samth/pycket/pycket/argument_parser.py add_parser_method/original