def service(self, tree):
     # unknown for now
     if tree.service_fragment.output is not None:
         tree.service_fragment.output.expect(
             0, 'service_no_inline_output')
     try:
         # check whether variable exists
         t = self.path(tree.path)
         service_to_mutation(tree)
         return self.resolve_mutation(t, tree)
     except CompilerError as e:
         # ignore only invalid variables (must be services)
         if e.error == 'var_not_defined':
             return AnyType.instance()
         raise e
Example #2
0
    def service(self, tree):
        # unknown for now
        if tree.service_fragment.output is not None:
            tree.service_fragment.output.expect(0, 'service_no_inline_output')
        t = None
        try:
            # check whether variable exists
            t = self.path(tree.path)
        except CompilerError:
            # ignore invalid variables (not existent or invalid)
            # -> must be a service
            return base_symbol(AnyType.instance())

        # variable exists -> mutation
        service_to_mutation(tree)
        return self.resolve_mutation(t, tree)
Example #3
0
    def visit(cls, node, block, entity, pred, fun, parent):
        if not hasattr(node, 'children') or len(node.children) == 0:
            return

        if node.data == 'block':
            # only generate a fake_block once for every line
            # node: block in which the fake assignments should be inserted
            block = cls.fake_tree(node)
        elif node.data == 'entity' or node.data == 'key_value':
            # set the parent where the inline_expression path should be
            # inserted
            entity = node
        elif node.data == 'service' and node.child(0).data == 'path':
            entity = node

        # create fake lines for base_expressions too, but only when required:
        # 1) `expressions` are already allowed to be nested
        # 2) `assignment_fragments` are ignored to avoid two lines for simple
        #    service/mutation assignments (`a = my_service command`)
        if node.data == 'base_expression' and \
                node.child(0).data != 'expression' and \
                parent.data != 'assignment_fragment':
            # replace base_expression too
            fun(node, block, node)
            node.children = [Tree('path', node.children)]

        for c in node.children:
            cls.visit(c, block, entity, pred, fun, parent=node)

        if pred(node):
            assert entity is not None
            assert block is not None
            fake_tree = block
            if not isinstance(fake_tree, FakeTree):
                fake_tree = cls.fake_tree(block)

            # Evaluate from leaf to the top
            fun(node, fake_tree, entity.path)

            # split services into service calls and mutations
            if entity.data == 'service':
                entity.entity = Tree('entity', [entity.path])
                service_to_mutation(entity)
    def service(self, tree):
        # unknown for now
        if tree.service_fragment.output is not None:
            tree.service_fragment.output.expect(0, 'service_no_inline_output')

        command = tree.service_fragment.command
        tree.expect(command is not None, 'service_without_command')

        self.check_service_fragment_arguments(tree.service_fragment)

        t = None
        try:
            # check whether variable exists
            t = self.path(tree.path)
        except CompilerError:
            # ignore invalid variables (not existent or invalid)
            # -> must be a service
            return base_symbol(self.resolve_service(tree))

        # variable exists -> mutation
        service_to_mutation(tree)
        return self.resolve_mutation(t, tree)