import asyncio from typing import Any, List async def minilisp( reader: asyncio.StreamReader ) -> Any: stack : list[ Any ] = [] token = b'' def shift() -> None: nonlocal token if token: stack[ -1 ].append( token.decode() ) token = b'' while True: byte = await reader.readexactly( 1 ) if byte == b'(': shift() stack.append( [] ) elif byte == b')': shift() x = stack.pop() if stack: stack[ -1 ].append( x ) else: return x elif byte.isspace(): shift() else: token += byte import run_tests