예제 #1
0
    def process_args(self, stack):
        """
        Looks for the mutation name token in the stack and filter seen arguments.
        """
        dot_op = self._toks(stack, before="mut_arguments")
        toks = [t.value for t in Stack.flatten(dot_op)]
        mut_name = toks.pop()
        # remove '.' from mut_name (.<mut_name>)
        expr = "".join(toks[:-1])

        # second or further arguments -> filter used arguments
        prev_args = Stack.find_all_until(stack,
                                         "mut_arguments", ["dot_expr"],
                                         start=1,
                                         offset=3)
        # '(' (<name> ':' <expr>)*
        prev_args = [*prev_args]

        args = self.args(expr, mut_name, prev_args)

        seen = {}
        for arg in args:
            arg_name = arg.name.lower()
            if arg_name in seen:
                continue
            seen[arg_name] = True
            # ignore previously used args
            if arg_name not in prev_args:
                yield arg
예제 #2
0
    def process_when_args(self, stack):
        """
        Process a when statement with args.
        """
        name = Stack.extract(stack, "when_expression")[0].value
        actions = Stack.extract(stack, "when_action")
        suffix = Stack.extract(stack, "when_action_suffix")
        prev_args = [
            *Stack.find_all_until(
                stack, "when_arglist", ["when_expression"], start=0, offset=3)
        ]
        event = None
        assert len(actions) == 2
        action = actions[0].value
        # it might have been the event name or an argument
        if len(suffix) > 0 and suffix[0].value == ":":
            prev_args.append(actions[1].value)
        else:
            event = actions[1].value

        yield from self.service.when(name, action, event, prev_args)
예제 #3
0
    def process_args(self, stack):
        """
        Extract previous token for service or function argument completion
        with at least one previous argument. This looks for seen args
        and filters them out.
        """
        suffixes = ["fn_suffix", "service_suffix"]
        last_rule = Stack.find_closest_rule(stack, suffixes)

        # second or further arguments -> filter used arguments
        # <name> ':' <expr>
        prev_args = [
            *Stack.find_all_until(
                stack, "arglist", suffixes, start=0, offset=3)
        ]

        if last_rule == "service_suffix":
            yield from self.service.process_args(stack, prev_args)
        else:
            assert last_rule == "fn_suffix"
            yield from self.function.process_args(stack, prev_args)
예제 #4
0
def test_stack_find_all_until_no_rule():
    stack = Parser().stack("foo bar foo:1")
    with raises(AssertionError):
        [*Stack.find_all_until(stack, "arglist", ["no_rule"])]
예제 #5
0
def test_stack_find_all_until_3():
    stack = Parser().stack("foo bar arg1:1 + 1 arg2:2 arg3: (foo bar arg4:1)")
    res = Stack.find_all_until(stack, "arglist", ["service_suffix"])
    assert [*res] == ["arg1", "arg2", "arg3"]
예제 #6
0
def test_stack_find_all_until():
    stack = Parser().stack("foo bar arg1:1")
    res = Stack.find_all_until(stack, "arglist", ["service_suffix"])
    assert [*res] == ["arg1"]