diff options
author | Anthon van der Neut <anthon@mnt.org> | 2021-05-06 08:36:49 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2021-05-06 08:36:49 +0200 |
commit | 17b35c376fd0fc9a94ba0adfdbf5bf63a6177dc9 (patch) | |
tree | 49a76a7328cbc20efde9603d5373ecf003adbbc6 /tokens.py | |
parent | 3d77f16e00124b74e150625396617b41e41da014 (diff) | |
download | ruamel.yaml-17b35c376fd0fc9a94ba0adfdbf5bf63a6177dc9.tar.gz |
* extend EOL token handling
* extending comment
Diffstat (limited to 'tokens.py')
-rw-r--r-- | tokens.py | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -1,6 +1,6 @@ # coding: utf-8 -from ruamel.yaml.compat import _F +from ruamel.yaml.compat import _F, nprintf if False: # MYPY from typing import Text, Any, Dict, Optional, List # NOQA @@ -89,13 +89,17 @@ class Token: self._comment[0] = [] self._comment[0].append(comment) - def add_comment_eol(self, comment): + def add_comment_eol(self, comment, comment_type): if not hasattr(self, '_comment'): self._comment = [None, None, None] else: assert len(self._comment) == 3 assert self._comment[1] is None - self._comment[1] = comment + if self.comment[1] is None: + self._comment[1] = [] + self._comment[1].extend([None] * (comment_type + 1 - len(self.comment[1]))) + # nprintf('commy', self.comment, comment_type) + self._comment[1][comment_type] = comment def add_comment_post(self, comment): if not hasattr(self, '_comment'): @@ -184,11 +188,9 @@ class Token: target._comment = c # nprint('mco2:', self, target, target.comment, empty) return self - return - raise NotImplemtedError # if self and target have both pre, eol or post comments, something seems wrong for idx in range(3): - if c[idx] and tc[idx]: + if c[idx] is not None and tc[idx] is not None: raise NotImplementedError(_F('overlap in comment {c!r} {tc!r}', c=c, tc=tc)) # move the comment parts for idx in range(3): |