Commit 0e3c66da authored by Tom Niget's avatar Tom Niget

Allow calling join() with strs

parent 27378412
...@@ -17,7 +17,7 @@ class UniversalVisitor: ...@@ -17,7 +17,7 @@ class UniversalVisitor:
def visit(self, node): def visit(self, node):
"""Visit a node.""" """Visit a node."""
TB = f"emitting C++ code for {highlight(node)}" TB = f"emitting C++ code for {highlight(node)}"
#TB_SKIP = True # TB_SKIP = True
if type(node) == list: if type(node) == list:
for n in node: for n in node:
...@@ -113,6 +113,7 @@ class NodeVisitor(UniversalVisitor): ...@@ -113,6 +113,7 @@ class NodeVisitor(UniversalVisitor):
else: else:
raise NotImplementedError(node) raise NotImplementedError(node)
class CoroutineMode(Flag): class CoroutineMode(Flag):
SYNC = 1 SYNC = 1
FAKE = 2 | SYNC FAKE = 2 | SYNC
...@@ -121,21 +122,32 @@ class CoroutineMode(Flag): ...@@ -121,21 +122,32 @@ class CoroutineMode(Flag):
TASK = 16 | ASYNC TASK = 16 | ASYNC
JOIN = 32 | ASYNC JOIN = 32 | ASYNC
class FunctionEmissionKind(enum.Enum): class FunctionEmissionKind(enum.Enum):
DECLARATION = enum.auto() DECLARATION = enum.auto()
DEFINITION = enum.auto() DEFINITION = enum.auto()
METHOD = enum.auto() METHOD = enum.auto()
LAMBDA = enum.auto() LAMBDA = enum.auto()
def join(sep: str, items: Iterable[Iterable[str]]) -> Iterable[str]: def join(sep: str, items: Iterable[Iterable[str]]) -> Iterable[str]:
items = iter(items) items = iter(items)
try: try:
yield from next(items) it = next(items)
if type(it) is str:
yield it
else:
yield from it
for item in items: for item in items:
yield sep yield sep
yield from item it = item
if type(it) is str:
yield it
else:
yield from it
except StopIteration: except StopIteration:
return return
def flatmap(f, items): def flatmap(f, items):
return chain.from_iterable(map(f, items)) return chain.from_iterable(map(f, items))
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment