diff options
Diffstat (limited to 'yapymake/makefile/token.py')
-rw-r--r-- | yapymake/makefile/token.py | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/yapymake/makefile/token.py b/yapymake/makefile/token.py index 57ad4f9..d9ed5ac 100644 --- a/yapymake/makefile/token.py +++ b/yapymake/makefile/token.py @@ -54,12 +54,20 @@ class TokenString(Iterable['Token']): first_token.text = first_token.text.lstrip() self._tokens[0] = first_token - def rstrip(self) -> None: + def rstrip(self, chars: Optional[str] = None) -> None: last_token = self._tokens[-1] if isinstance(last_token, TextToken): - last_token.text = last_token.text.rstrip() + last_token.text = last_token.text.rstrip(chars) self._tokens[-1] = last_token + def endswith(self, pattern: str) -> bool: + last_token = self._tokens[-1] + return isinstance(last_token, TextToken) and last_token.text.endswith(pattern) + + def concat(self, other: 'TokenString') -> 'TokenString': + return TokenString([*self._tokens, *other._tokens]) + + @dataclass() class Token: pass |