diff options
author | Melody Horn <melody@boringcactus.com> | 2021-03-25 21:21:07 -0600 |
---|---|---|
committer | Melody Horn <melody@boringcactus.com> | 2021-03-25 21:21:07 -0600 |
commit | 383c904c0f2667e8afabc76568a5e8376e617696 (patch) | |
tree | ef3e292a688ee43cbbeab222c58feafc9a13aff2 /yapymake/makefile/token.py | |
parent | 40c9e2383d2e989cf5e51f6f855b869c7235f694 (diff) | |
download | yapymake-383c904c0f2667e8afabc76568a5e8376e617696.tar.gz yapymake-383c904c0f2667e8afabc76568a5e8376e617696.zip |
allow GNUish macro assignments (`?=`, `+=`)
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 |