def SPL(): found_imports = yield ps.many(ImportDecl) found_decls = yield ps.many(Decl) return AST.SPL(imports=found_imports, decls=found_decls)
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')])), AST.TYPESYN(type_id=Token(None, TOKEN.TYPE_IDENTIFIER, "String"), def_type=AST.TYPE(val=AST.LISTTYPE(type=AST.TYPE( val=AST.BASICTYPE(type_id=Token( None, TOKEN.TYPE_IDENTIFIER, "Char")))))), AST.FUNDECL( kind=FunKind.INFIXL, fixity=Token(None, TOKEN.INT, 4), id=Token(None, TOKEN.OP_IDENTIFIER, "%%"), params=[ Token(None, TOKEN.IDENTIFIER, "x"), Token(None, TOKEN.IDENTIFIER, "y") ], type=AST.FUNTYPE(from_types=[ AST.TYPE(val=AST.BASICTYPE( type_id=Token(None, TOKEN.TYPE_IDENTIFIER, "Char"))), AST.TYPE(val=AST.BASICTYPE( type_id=Token(None, TOKEN.TYPE_IDENTIFIER, "Char"))) ], to_type=AST.TYPE(val=AST.BASICTYPE( type_id=Token(None, TOKEN.TYPE_IDENTIFIER, "Char")))), vardecls=[], stmts=[]), AST.FUNDECL(kind=FunKind.INFIXL, fixity=Token(None, TOKEN.INT, 4), id=Token(None, TOKEN.OP_IDENTIFIER, "%%"), params=[ Token(None, TOKEN.IDENTIFIER, "x"), Token(None, TOKEN.IDENTIFIER, "y") ], type=None, vardecls=[], stmts=[]), AST.FUNDECL(kind=FunKind.INFIXR, fixity=Token(None, TOKEN.INT, 4), id=Token(None, TOKEN.OP_IDENTIFIER, "^^"), params=[ Token(None, TOKEN.IDENTIFIER, "x"), Token(None, TOKEN.IDENTIFIER, "y") ], type=None, vardecls=[], stmts=[ AST.STMT(val=AST.RETURN(expr=None)), AST.STMT(val=AST.RETURN(expr=None)) ]), AST.FUNDECL( kind=FunKind.FUNC, fixity=None, id=Token(None, TOKEN.OP_IDENTIFIER, "fib2"), params=[ Token(None, TOKEN.IDENTIFIER, "xtup"), Token(None, TOKEN.IDENTIFIER, "y"), Token(None, TOKEN.IDENTIFIER, "z") ], type=AST.FUNTYPE(from_types=[ AST.TUPLETYPE( a=AST.TYPE(val=AST.BASICTYPE(type_id=Token( None, TOKEN.TYPE_IDENTIFIER, "Char"))), b=AST.TYPE(val=AST.BASICTYPE(type_id=Token( None, TOKEN.TYPE_IDENTIFIER, "Char"))), ), AST.TYPE(val=AST.BASICTYPE( type_id=Token(None, TOKEN.TYPE_IDENTIFIER, "Char"))), AST.TYPE(val=AST.BASICTYPE( type_id=Token(None, TOKEN.TYPE_IDENTIFIER, "Char"))) ], to_type=AST.TYPE(val=AST.BASICTYPE( type_id=Token(None, TOKEN.TYPE_IDENTIFIER, "Char")))), vardecls=[], stmts=[ AST.STMT(val=AST.RETURN(expr=None)), AST.STMT(val=AST.RETURN(expr=None)) ]), AST.FUNDECL( kind=FunKind.PREFIX, fixity=None, id=Token(None, TOKEN.OP_IDENTIFIER, "!"), params=[Token(None, TOKEN.IDENTIFIER, "x")], type=AST.FUNTYPE( from_types=[ AST.TYPE(val=AST.BASICTYPE(type_id=Token( None, TOKEN.TYPE_IDENTIFIER, "Char"))) ], to_type=AST.TYPE(val=AST.BASICTYPE( type_id=Token(None, TOKEN.TYPE_IDENTIFIER, "Char")))), vardecls=[], stmts=[ AST.STMT(val=AST.RETURN(expr=None)), AST.STMT(val=AST.RETURN(expr=None)), AST.LOOP( init=AST.ACTSTMT(val=AST.ASSIGNMENT( varref=AST.VARREF(id=Token(None, TOKEN.IDENTIFIER, "x"), fields=[]), expr=AST.DEFERREDEXPR( contents=[Token(None, TOKEN.IDENTIFIER, "x") ]))), cond=AST.DEFERREDEXPR(contents=[ Token(None, TOKEN.IDENTIFIER, "x"), Token(None, TOKEN.OP_IDENTIFIER, "=="), Token(None, TOKEN.IDENTIFIER, "y") ]), update=AST.FUNCALL(id=Token(None, TOKEN.IDENTIFIER, "f"), kind=FunKind.FUNC, args=[]), stmts=[ AST.STMT( val=AST.RETURN(expr=None)), AST.STMT(val=AST.IFELSE(condbranches=[ AST.CONDBRANCH(expr=AST.DEFERREDEXPR(contents=[ Token(None, TOKEN.IDENTIFIER, "x"), Token(None, TOKEN.OP_IDENTIFIER, "=="), Token(None, TOKEN.IDENTIFIER, "y") ]), stmts=[ AST.STMT(val=AST.RETURN( expr=None)) ]), AST.CONDBRANCH(expr=AST.DEFERREDEXPR(contents=[ Token(None, TOKEN.IDENTIFIER, "x"), Token(None, TOKEN.OP_IDENTIFIER, "=="), Token(None, TOKEN.IDENTIFIER, "y") ]), stmts=[ AST.STMT(val=AST.RETURN( expr=None)) ]), AST.CONDBRANCH(expr=None, stmts=[ AST.STMT(val=AST.RETURN( expr=None)) ]) ])) ]) ]) ])