summaryrefslogtreecommitdiff
path: root/comments.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2015-09-14 22:25:27 +0200
committerAnthon van der Neut <anthon@mnt.org>2015-09-14 22:25:27 +0200
commitddba56acde2ca5e558ea4ab23bfa93331f5eb8aa (patch)
treeaa76c7b61c5c9564f811692b82b24b1ddd4f8ac9 /comments.py
parentd5012887a2318457e6c3003d4940bd39c46ff85b (diff)
downloadruamel.yaml-ddba56acde2ca5e558ea4ab23bfa93331f5eb8aa.tar.gz
Fix issue 9
Added possibility to store and retrieve mapping and sequence element positions
Diffstat (limited to 'comments.py')
-rw-r--r--comments.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/comments.py b/comments.py
index 0db9457..987ec1f 100644
--- a/comments.py
+++ b/comments.py
@@ -98,6 +98,35 @@ class LineCol(object):
def __init__(self):
self.line = None
self.col = None
+ self.data = None
+
+ def add_kv_line_col(self, key, data):
+ if self.data is None:
+ self.data = {}
+ self.data[key] = data
+
+ def key(self, k):
+ return self._kv(k, 0, 1)
+
+ def value(self, k):
+ return self._kv(k, 2, 3)
+
+ def _kv(self, k, x0, x1):
+ if self.data is None:
+ return None
+ data = self.data[k]
+ return data[x0], data[x1]
+
+ def item(self, idx):
+ if self.data is None:
+ return None
+ return self.data[idx]
+
+ def add_idx_line_col(self, key, data):
+ if self.data is None:
+ self.data = {}
+ self.data[key] = data
+
class Anchor(object):
attrib = anchor_attrib
@@ -187,6 +216,12 @@ class CommentedBase(object):
self.lc.line = line
self.lc.col = col
+ def _yaml_set_kv_line_col(self, key, data):
+ self.lc.add_kv_line_col(key, data)
+
+ def _yaml_set_idx_line_col(self, key, data):
+ self.lc.add_idx_line_col(key, data)
+
@property
def anchor(self):
if not hasattr(self, Anchor.attrib):