[issue37995] Multiline ast.dump()
Raymond Hettinger
report at bugs.python.org
Sun Sep 1 16:24:08 EDT 2019
Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
FWIW, I wrote a generic AST pretty printer for a personal compiler project (see attached file). Perhaps it can be adapted to the Python AST.
## Example input ###############################
Program(procs=[Procedure(name='FACTORIAL', params=['N'], is_test=False, body=Block(blocknum=0, stmts=[Assign(name=Output(is_bool=False), value=Number(x=1)), Assign(name=Cell(i=0), value=Number(x=1)), Loop(times=Id(name='N'), fixed=False, body=Block(blocknum=1, stmts=[Assign(name=Output(is_bool=False), value=BinOp(value1=Output(is_bool=False), op='x', value2=Cell(i=0))), Assign(name=Cell(i=0), value=BinOp(value1=Cell(i=0), op='+', value2=Number(x=1)))]))]))], calls=[])
## Example output ###############################
Program(
procs = [
Procedure(
name = 'FACTORIAL',
params = [
'N'
],
is_test = False,
body = Block(
blocknum = 0,
stmts = [
Assign(
name = Output(is_bool=False),
value = Number(x=1)
),
Assign(
name = Cell(i=0),
value = Number(x=1)
),
Loop(
times = Id(name='N'),
fixed = False,
body = Block(
blocknum = 1,
stmts = [
Assign(
name = Output(is_bool=False),
value = BinOp(
value1 = Output(is_bool=False),
op = 'x',
value2 = Cell(i=0)
)
),
Assign(
name = Cell(i=0),
value = BinOp(
value1 = Cell(i=0),
op = '+',
value2 = Number(x=1)
)
)
]
)
)
]
)
)
],
calls = []
)
----------
Added file: https://bugs.python.org/file48579/ast_bloop.py
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37995>
_______________________________________
More information about the Python-bugs-list
mailing list