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

Allow calling join() with strs

parent 27378412
......@@ -17,7 +17,7 @@ class UniversalVisitor:
def visit(self, node):
"""Visit a node."""
TB = f"emitting C++ code for {highlight(node)}"
#TB_SKIP = True
# TB_SKIP = True
if type(node) == list:
for n in node:
......@@ -113,6 +113,7 @@ class NodeVisitor(UniversalVisitor):
else:
raise NotImplementedError(node)
class CoroutineMode(Flag):
SYNC = 1
FAKE = 2 | SYNC
......@@ -121,21 +122,32 @@ class CoroutineMode(Flag):
TASK = 16 | ASYNC
JOIN = 32 | ASYNC
class FunctionEmissionKind(enum.Enum):
DECLARATION = enum.auto()
DEFINITION = enum.auto()
METHOD = enum.auto()
LAMBDA = enum.auto()
def join(sep: str, items: Iterable[Iterable[str]]) -> Iterable[str]:
items = iter(items)
try:
yield from next(items)
it = next(items)
if type(it) is str:
yield it
else:
yield from it
for item in items:
yield sep
yield from item
it = item
if type(it) is str:
yield it
else:
yield from it
except StopIteration:
return
def flatmap(f, items):
return chain.from_iterable(map(f, items))
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