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
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
def _test_arrangement_equals(self, code: str, lisp_form: str): code1 = lyc_parser.parse(code) code2 = lyc_parser.parse(lisp_form) self.assertTrue( self._code_equals(code1, code2), msg="Code '%s' != '%s'" % (lisp_printer(code1), lisp_printer(code2)) )
def __str__(self): import anoky.syntax.lisp_printer as LispPrinter return LispPrinter.lisp_printer(self)
def __str__(self): from anoky.syntax.lisp_printer import lisp_printer return lisp_printer(self)
def _test_arrangement_equals(self, code: str, lisp_form: str): code1 = lyc_parser.parse(code) code2 = lyc_parser.parse(lisp_form) self.assertTrue(self._code_equals(code1, code2), msg="Code '%s' != '%s'" % (lisp_printer(code1), lisp_printer(code2)))