aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--yapymake/makefile/__init__.py5
-rw-r--r--yapymake/util/peekable_iterator.py7
2 files changed, 8 insertions, 4 deletions
diff --git a/yapymake/makefile/__init__.py b/yapymake/makefile/__init__.py
index ddd049d..a5cb19d 100644
--- a/yapymake/makefile/__init__.py
+++ b/yapymake/makefile/__init__.py
@@ -130,8 +130,9 @@ class Makefile:
prerequisite_tokens, command_tokens = semicolon_split
prerequisites = self.expand_macros(prerequisite_tokens).split()
command_token_strings = [command_tokens]
- while lines_iter.peek().startswith('\t'):
- command_token_strings.append(tokenize(next(lines_iter).lstrip('\t')))
+ while (peeked := lines_iter.peek()) is not None and peeked.startswith('\t'):
+ # TODO handle escaped newlines
+ command_token_strings.append(tokenize(next(lines_iter).lstrip('\t').rstrip('\n')))
commands = [CommandLine(c) for c in command_token_strings]
# we don't know yet if it's a target rule or an inference rule
diff --git a/yapymake/util/peekable_iterator.py b/yapymake/util/peekable_iterator.py
index 67bd59d..cd2fcac 100644
--- a/yapymake/util/peekable_iterator.py
+++ b/yapymake/util/peekable_iterator.py
@@ -24,7 +24,10 @@ class PeekableIterator(Iterator[T]):
return result
return next(self._inner)
- def peek(self) -> T:
+ def peek(self) -> Optional[T]:
if self._peeked is None:
- self._peeked = next(self._inner)
+ try:
+ self._peeked = next(self._inner)
+ except StopIteration:
+ self._peeked = None
return self._peeked