Exemplo n.º 1
0
    def __call__(self, ctx, *args):
        bindings = self.bind_parameters(args)

        new_ctx = MergedExecutionContext(ExecutionContext(bindings), ctx,
                                         self.ctx)
        code = yield CodeResult(self.body, new_ctx)
        yield CodeResult(code, ctx)
Exemplo n.º 2
0
    def __call__(self, ctx, *args):
        bindings = {}
        for i, x in enumerate(args):
            bindings['%' + str(i)] = x

        new_ctx = MergedExecutionContext(ExecutionContext(bindings), ctx,
                                         self.ctx)
        yield CodeResult(self.body, new_ctx)
Exemplo n.º 3
0
    def __init__(self, ctx=None, with_stdlib=False):
        self.last_frame = None
        self.operation_stack = []
        self.result_stack = []

        self.ctx = ExecutionContext(ctx)
        if with_stdlib:
            load_stdlib(self)
Exemplo n.º 4
0
    def handle_match(self, ctx, expr, var, *cases):
        value = yield CodeResult(var, ctx)
        for pattern, result in cases:
            pattern_is_list = isinstance(pattern, (list, tuple))
            var_is_list = isinstance(value, (list, tuple))

            if pattern_is_list and var_is_list:
                names = self.ensure_list_of_identifiers(pattern)
                try:
                    binds = unpack_bind(names, value)
                except RuntimeError:
                    continue
                else:
                    yield CodeResult(result, ExecutionContext(ctx, **binds))
                    break
            elif not pattern_is_list:
                name = self.ensure_identifier(pattern)
                yield CodeResult(result, ExecutionContext(ctx, name=value))
                break
        else:
            raise RuntimeError('pattern matching failed')
Exemplo n.º 5
0
    def handle_let(self, ctx, expr, bindings, body):
        new_ctx = ExecutionContext(ctx)
        for i in range(0, len(bindings), 2):
            value = yield CodeResult(bindings[i + 1], new_ctx)
            if isinstance(bindings[i], (list, tuple)):
                names = self.ensure_list_of_identifiers(bindings[i])
                unpack_bind(names, value, new_ctx)
            else:
                name = self.ensure_identifier(bindings[i])
                new_ctx[name] = value

        yield CodeResult(body, new_ctx)
Exemplo n.º 6
0
def test_member():
    ctx = ExecutionContext(None)
    ctx['s'] = '  abc  '
    inpr = IterativeInterpreter(ctx)
    assert eval_expr(r'(. strip s)', inpr) == ctx['s'].strip