CPython 3.14 with syntactic macros, compiled to WebAssembly and running in this tab. Edit the macro module and the program, then run: you get the output, the program after macro expansion, and the syntax tree the parser produced.
Ctrl/⌘ + Enter runs. main.py is the program; the other files are importable modules.
1
Python is loading (about 12 MB the first time). The example runs as soon as it is ready.
What main.py printed.
What this build understands
from! module import name [as alias]
Compile-time import of one macro, visible in the enclosing scope from that line on. import! module.name as alias also works.
name! args [import x] [as y]: body
Statement macro. Arguments, clauses and body are all optional. In the body, "red" = 1 is allowed.
name! next statement
Sibling macro: it receives the statement that follows it.
value = name!(args)
Expression macro. A line that starts with name! is always a statement macro, as the PEP specifies; wrap it in parentheses to use an expression macro there.
ast.MacroStmt · ast.MacroExpr · ast.StmtExpr
The new tree nodes (also as macro_stmt, macro_expr, stmt_expr).
macros.macro_processor(kind, version, *parts)
Decorator for processors. Also macros.new_name(node) for hygienic names and macros.expand(tree).