summaryrefslogtreecommitdiff
path: root/scanner.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2019-05-16 22:53:16 +0200
committerAnthon van der Neut <anthon@mnt.org>2019-05-16 22:53:16 +0200
commit6f802bba09690a61d753910119811167016b8ab7 (patch)
tree2929e547d8ade18cd6cb466212029d782d773471 /scanner.py
parent79ce3ac7ab98fee2a2896e38113135d3679920de (diff)
downloadruamel.yaml-6f802bba09690a61d753910119811167016b8ab7.tar.gz
indentation of comments after folded/lit scalars0.15.96
fixes issue #290 *When this change indeed resolves your problem, please **Close** this issue*. *(You can do so using the WorkFlow pull-down (close to the top right of this page))*
Diffstat (limited to 'scanner.py')
-rw-r--r--scanner.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/scanner.py b/scanner.py
index 9ed711a..46cd9d7 100644
--- a/scanner.py
+++ b/scanner.py
@@ -1237,7 +1237,7 @@ class Scanner(object):
# Eat whitespaces and comments until we reach the next token.
comment = self.scan_to_next_token()
while comment:
- trailing.append(comment[0])
+ trailing.append(' ' * comment[1].column + comment[0])
comment = self.scan_to_next_token()
# Keep track of the trailing whitespace and following comments
@@ -1824,7 +1824,14 @@ class RoundTripScanner(Scanner):
and self.tokens[0].end_mark.line == self.tokens[1].start_mark.line
):
self.tokens_taken += 1
- self.tokens[0].add_post_comment(self.tokens.pop(1))
+ c = self.tokens.pop(1)
+ self.fetch_more_tokens()
+ while len(self.tokens) > 1 and isinstance(self.tokens[1], CommentToken):
+ self.tokens_taken += 1
+ c1 = self.tokens.pop(1)
+ c.value = c.value + (' ' * c1.start_mark.column) + c1.value
+ self.fetch_more_tokens()
+ self.tokens[0].add_post_comment(c)
elif (
len(self.tokens) > 1
and isinstance(self.tokens[0], ScalarToken)
@@ -1843,7 +1850,7 @@ class RoundTripScanner(Scanner):
while len(self.tokens) > 1 and isinstance(self.tokens[1], CommentToken):
self.tokens_taken += 1
c1 = self.tokens.pop(1)
- c.value = c.value + (' ' * c.start_mark.column) + c1.value
+ c.value = c.value + (' ' * c1.start_mark.column) + c1.value
self.fetch_more_tokens()
self.tokens_taken += 1
return self.tokens.pop(0)