diff options
author | Anthon van der Neut <anthon@mnt.org> | 2016-11-28 18:02:34 +0100 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2016-11-28 18:02:34 +0100 |
commit | 786fc2f80aa5c2d626674c7c9125c4c3be874af6 (patch) | |
tree | eedc7a090bcecc52ce4925cc76af8f1090792c9f /tokens.py | |
parent | 0ab4dd3ca904554aecc272d707ce1946a56a50d4 (diff) | |
download | ruamel.yaml-786fc2f80aa5c2d626674c7c9125c4c3be874af6.tar.gz |
addresses #25 comment after empty (null) values0.13.2
can remove comment between key en value
Diffstat (limited to 'tokens.py')
-rw-r--r-- | tokens.py | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -35,10 +35,11 @@ class Token(object): def comment(self): return getattr(self, '_comment', None) - def move_comment(self, target): + def move_comment(self, target, empty=False): """move a comment from this token to target (normally next token) used to combine e.g. comments before a BlockEntryToken to the ScalarToken that follows it + empty is a special for empty values -> comment after key """ c = self.comment if c is None: @@ -46,9 +47,14 @@ class Token(object): # don't push beyond last element if isinstance(target, StreamEndToken): return + if isinstance(self, ValueToken) and isinstance(target, BlockEntryToken): + return delattr(self, '_comment') tc = target.comment if not tc: # target comment, just insert + # special for empty value in key: value issue 25 + if empty: + c = [c[0], c[1], None, None, c[0]] target._comment = c return self if c[0] and tc[0] or c[1] and tc[1]: |