From 786fc2f80aa5c2d626674c7c9125c4c3be874af6 Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Mon, 28 Nov 2016 18:02:34 +0100 Subject: addresses #25 comment after empty (null) values can remove comment between key en value --- tokens.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'tokens.py') diff --git a/tokens.py b/tokens.py index 56adbe6..a4646bd 100644 --- a/tokens.py +++ b/tokens.py @@ -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]: -- cgit v1.2.1