コード例 #1
0
ファイル: transformator.py プロジェクト: jbrezmorf/flow123d
 def _delete_value(self, root, lines, node):
     """Delete value and return start possition deleted value"""
     l1, c1, l2, c2 = node.span.start.line-1, node.span.start.column-1, \
         node.span.end.line-1, node.span.end.column-1
     l1, c1 = StructureChanger.skip_tar(lines, l1, c1, l2, c2)
     StructureChanger.delete_structure(lines, l1, c1, l2, c2)
     return l1, c1
コード例 #2
0
ファイル: transformator.py プロジェクト: jbrezmorf/flow123d
 def _delete_key(self, root, lines, action):
     """Delete key transformation"""
     try:
         node = root.get_node_at_path(action['parameters']['path'])
     except:
         return False
     if "deep" not in action['parameters'] or not  action['parameters']['deep']:
         if len(node.children_keys)>0:
             return False            
     l1, c1, l2, c2 = StructureChanger.node_pos(node)
     anchors = []
     for i in range(l1, l2+1):
         if l1 == l2:
             text = lines[l1][c1:c2]
         elif i == l1:
             text = lines[l1][c1:]
         elif i == l2:
             text = lines[l2][:c2]
         else:
             text = lines[i]
         anchor = re.search(r'\s+&\s*(\S+)\s+', text)
         if anchor is None:
             anchor = re.search(r'\s+&\s*(\S+)$', text)
         if anchor is not None:
             anchors.append(anchor.group(1))
     if len(anchors) > 0:
         self._rewrite_first_ref(root, lines, anchors)
     # try delete with comma after or prev
     nl2, nc2 = self._next_spread(lines, l2, c2)
     if nl2 == l2 and nc2 == c2:
         l1, c1 = self._prev_spred(lines, l1, c1)
     else:
         l2 = nl2
         c2 = nc2
     # try exclude comments
     l1, c1, l2, c2 = StructureChanger.leave_comments(lines, l1, c1, l2, c2) 
     l1, c1, l2, c2 = StructureChanger.add_delete_item_chars(lines, l1, c1, l2, c2)
     StructureChanger.delete_structure(lines, l1, c1, l2, c2)
     return True