예제 #1
0
 def trace(self):
     trace = self.__class__.name + ":\n"
     message = "\n" + indent_string(self.message) if "\n" in self.message else self.message
     if self.range_or_pos is not None:
         trace += "    %s: %s" %(str(self.range_or_pos), message)
     else:
         trace += message
     return trace
예제 #2
0
 def trace(self):
     trace = self.__class__.name + ":\n"
     message = "\n" + indent_string(
         self.message) if "\n" in self.message else self.message
     if self.range_or_pos is not None:
         trace += "    %s: %s" % (str(self.range_or_pos), message)
     else:
         trace += message
     return trace
예제 #3
0
    def arrange(self, node: Code):
        if not isinstance(node, Node):
            return

        element = None
        if self.direction == ReadDirection.LEFT_TO_RIGHT:
            element = node.first
        elif self.direction == ReadDirection.RIGHT_TO_LEFT:
            element = node.last

        while element is not None:
            nxt = element.next if self.direction == ReadDirection.LEFT_TO_RIGHT else element.prev

            for r in self.rules:
                if r.applies(element):

                    #region Debug Printing
                    if G.Options.PRINT_ARRANGEMENT_OUTPUTS:
                        node.insert(element, Identifier("⋅"))
                        out = "        Arrangement: " + r.name + "\n"
                        out += indent_string("BEFORE:", 12) + "\n"
                        out += indent_string(lisp_printer(node), 20)
                        print(out)
                        node.remove(element.next)
                    #endregion

                    nxt = r.apply(element)

                    # region Debug Printing
                    if G.Options.PRINT_ARRANGEMENT_OUTPUTS:
                        if nxt is None:
                            node.insert(node.last, Identifier("⋅"))
                        else:
                            node.insert(nxt, Identifier("⋅"))
                        out = indent_string("After:", 12) + "\n"
                        out += indent_string(lisp_printer(node), 20)
                        print(out)
                        if nxt is None:
                            node.remove(node.last)
                        else:
                            node.remove(nxt.next)
                    # endregion
                    break
            element = nxt
예제 #4
0
    def arrange(self, node:Code):
        if not isinstance(node, Node):
            return

        element = None
        if self.direction == ReadDirection.LEFT_TO_RIGHT:
            element = node.first
        elif self.direction == ReadDirection.RIGHT_TO_LEFT:
            element = node.last

        while element is not None:
            nxt = element.next if self.direction == ReadDirection.LEFT_TO_RIGHT else element.prev

            for r in self.rules:
                if r.applies(element):

                    #region Debug Printing
                    if G.Options.PRINT_ARRANGEMENT_OUTPUTS:
                        node.insert(element, Identifier("⋅"))
                        out ="        Arrangement: " + r.name + "\n"
                        out += indent_string("BEFORE:", 12) + "\n"
                        out += indent_string(lisp_printer(node), 20)
                        print(out)
                        node.remove(element.next)
                    #endregion

                    nxt = r.apply(element)

                    # region Debug Printing
                    if G.Options.PRINT_ARRANGEMENT_OUTPUTS:
                        if nxt is None:
                            node.insert(node.last, Identifier("⋅"))
                        else:
                            node.insert(nxt, Identifier("⋅"))
                        out = indent_string("After:", 12) + "\n"
                        out += indent_string(lisp_printer(node), 20)
                        print(out)
                        if nxt is None:
                            node.remove(node.last)
                        else:
                            node.remove(nxt.next)
                    # endregion
                    break
            element = nxt
예제 #5
0
def apply_transducer_chain(transducer_chain: List[TreeTransducer], form: Code):
    """
    Applies each tree transducer in a given list, in turn.
    """
    for tt in transducer_chain:
        if isinstance(form, Node) and len(form) > 0:
            tt.transduce(form)
            if G.Options.PRINT_TREE_TRANSDUCER_OUTPUTS is True:
                if G.Options.PRINT_TREE_TRANSDUCER_OUTPUTS_LIST is None or tt.name in G.Options.PRINT_TREE_TRANSDUCER_OUTPUTS_LIST:
                    print(
                        indent_string(
                            "After transducer: " + tt.name + "\n" +
                            indented_lisp_printer(form), 4))