def ImportName(): found_name = yield AnyId found_alias = yield ps.times(ps.token(TOKEN.AS) >> AnyId, 0, 1) found_alias = found_alias[0] if len(found_alias) > 0 else None return AST.IMPORTNAME(name=found_name, alias=found_alias)
if type(el) == list: res += indent_print(el, level + 1) else: res += level * INDENT_CHARS + el + "\n" return res if __name__ == "__main__": test = AST.SPL( imports=[ AST.IMPORT(name=Token(None, TOKEN.IDENTIFIER, "stdlib"), importlist=None), AST.IMPORT(name=Token(None, TOKEN.IDENTIFIER, "math"), importlist=[ AST.IMPORTNAME(name=Token(None, TOKEN.IDENTIFIER, "power"), alias=Token(None, TOKEN.IDENTIFIER, "pow")) ]) ], decls=[ AST.VARDECL( type=None, id=Token(None, TOKEN.IDENTIFIER, "temp"), expr=AST.DEFERREDEXPR(contents=[Token(None, TOKEN.INT, 2)])), AST.VARDECL( type=AST.TYPE(val=AST.BASICTYPE( type_id=Token(None, TOKEN.TYPE_IDENTIFIER, "Char")) ), # TODO make this work for type node id=Token(None, TOKEN.IDENTIFIER, "hey"), expr=AST.DEFERREDEXPR( contents=[Token(None, TOKEN.CHAR, 'a')])),