summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--comments.py20
-rw-r--r--emitter.py4
2 files changed, 23 insertions, 1 deletions
diff --git a/comments.py b/comments.py
index 1e2bf82..8f69d0e 100644
--- a/comments.py
+++ b/comments.py
@@ -8,6 +8,7 @@ these are not really related, formatting could be factored out as
a separate base
"""
+import sys
import copy
from collections import MutableSet, Sized, Set
@@ -938,3 +939,22 @@ class CommentedSet(MutableSet, CommentedMap):
def __repr__(self):
# type: () -> str
return 'set({0!r})'.format(self.odict.keys())
+
+
+def dump_comments(d, name='', sep='.', out=sys.stdout):
+ """
+ recurisively dump domments all but the toplevel preceded by the path
+ in dotted form x.0.a
+ """
+ if isinstance(d, dict):
+ if name:
+ print(name)
+ print(d.ca, file=out)
+ for k in d:
+ dump_comments(d[k], name=name + sep + k if name else k, sep=sep, out=out)
+ elif isinstance(d, list):
+ if name:
+ print(name)
+ print(d.ca, file=out)
+ for idx, k in enumerate(d):
+ dump_comments(k, name=name + sep + str(idx) if name else k, sep=sep, out=out)
diff --git a/emitter.py b/emitter.py
index 3625619..c288a51 100644
--- a/emitter.py
+++ b/emitter.py
@@ -318,7 +318,6 @@ class Emitter(object):
self.expect_scalar()
elif isinstance(self.event, SequenceStartEvent):
if self.event.comment:
- # print(' >enc', self.event.comment, end=' ')
if self.event.flow_style is False and self.event.comment:
if self.write_post_comment(self.event):
self.indention = False
@@ -373,6 +372,9 @@ class Emitter(object):
self.indent = self.indents.pop()
self.flow_level -= 1
self.write_indicator(u']', False)
+ if self.event.comment and self.event.comment[0]:
+ # eol comment on empty flow sequence
+ self.write_post_comment(self.event)
self.state = self.states.pop()
else:
if self.canonical or self.column > self.best_width: