<s> from . . language . ast import Node <EOL> from . . language . parser import Loc <EOL> def ast_to_code ( ast , indent = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> code = [ ] <EOL> def append ( line ) : <EOL> code . append ( ( '<STR_LIT:U+0020>' * indent ) + line ) <EOL> if isinstance ( ast , Node ) : <EOL> append ( '<STR_LIT>' . format ( ast . __class__ . __name__ ) ) <EOL> indent += <NUM_LIT:1> <EOL> for i , k in enumerate ( ast . _fields , <NUM_LIT:1> ) : <EOL> v = getattr ( ast , k ) <EOL> append ( '<STR_LIT>' . format ( <EOL> k , <EOL> ast_to_code ( v , indent ) , <EOL> ) ) <EOL> if ast . loc : <EOL> append ( '<STR_LIT>' . format ( ast_to_code ( ast . loc , indent ) ) ) <EOL> indent -= <NUM_LIT:1> <EOL> append ( '<STR_LIT:)>' ) <EOL> elif isinstance ( ast , Loc ) : <EOL> append ( '<STR_LIT>' . format ( ast . start , ast . end ) ) <EOL> elif isinstance ( ast , list ) : <EOL> if ast : <EOL> append ( '<STR_LIT:[>' ) <EOL> indent += <NUM_LIT:1> <EOL> for i , it in enumerate ( ast , <NUM_LIT:1> ) : <EOL> is_last = i == len ( ast ) <EOL> append ( ast_to_code ( it , indent ) + ( '<STR_LIT:U+002C>' if not is_last else '<STR_LIT>' ) ) <EOL> indent -= <NUM_LIT:1> <EOL> append ( '<STR_LIT:]>' ) <EOL> else : <EOL> append ( '<STR_LIT>' ) <EOL> else : <EOL> append ( repr ( ast ) ) <EOL> return '<STR_LIT:\n>' . join ( code ) . strip ( ) </s>
