1.1 --- a/moinformat/tree/moin.py Mon Aug 13 17:55:16 2018 +0200
1.2 +++ b/moinformat/tree/moin.py Mon Aug 13 22:52:54 2018 +0200
1.3 @@ -69,6 +69,13 @@
1.4 def empty(self):
1.5 return not self.nodes
1.6
1.7 + def insert_after(self, old, new):
1.8 +
1.9 + "Insert after 'old' in the children the 'new' node."
1.10 +
1.11 + index = self.nodes.index(old)
1.12 + self.nodes.insert(index + 1, new)
1.13 +
1.14 def node(self, index):
1.15 try:
1.16 return self.nodes[index]
1.17 @@ -106,6 +113,12 @@
1.18 if text:
1.19 self.append(text)
1.20
1.21 + def remove(self, node):
1.22 +
1.23 + "Remove 'node' from the children."
1.24 +
1.25 + self.nodes.remove(node)
1.26 +
1.27 def replace(self, old, new):
1.28
1.29 "Replace 'old' with 'new' in the children."
1.30 @@ -113,6 +126,21 @@
1.31 i = self.nodes.index(old)
1.32 self.nodes[i] = new
1.33
1.34 + def split_at(self, node):
1.35 +
1.36 + """
1.37 + Split the container at 'node', returning a new container holding the
1.38 + nodes following 'node' that are moved from this container.
1.39 + """
1.40 +
1.41 + i = self.nodes.index(node)
1.42 + following = self.__class__(self.nodes[i+1:])
1.43 +
1.44 + # Remove the node and the following parts from this container.
1.45 +
1.46 + del self.nodes[i:]
1.47 + return following
1.48 +
1.49 def text_content(self):
1.50
1.51 """
1.52 @@ -130,6 +158,12 @@
1.53
1.54 return "".join(l)
1.55
1.56 + def whitespace_only(self):
1.57 +
1.58 + "Return whether the container provides only whitespace text."
1.59 +
1.60 + return not self.text_content().strip()
1.61 +
1.62 def __str__(self):
1.63 return self.prettyprint()
1.64
1.65 @@ -508,14 +542,15 @@
1.66
1.67 "Macro details."
1.68
1.69 - def __init__(self, name, args, parent, nodes=None):
1.70 + def __init__(self, name, args, parent, region, nodes=None):
1.71 Container.__init__(self, nodes or [])
1.72 self.name = name
1.73 + self.args = args
1.74 self.parent = parent
1.75 - self.args = args
1.76 + self.region = region
1.77
1.78 def __repr__(self):
1.79 - return "Macro(%r, %r, %r, %r)" % (self.name, self.args, self.parent, self.nodes)
1.80 + return "Macro(%r, %r, %r, %r, %r)" % (self.name, self.args, self.parent, self.region, self.nodes)
1.81
1.82 def prettyprint(self, indent=""):
1.83 l = ["%sMacro: name=%r args=%r" % (indent, self.name, self.args)]