def InfixOpDecl(): side = yield (ps.token(TOKEN.INFIXL) ^ ps.token(TOKEN.INFIXR)) if side.typ is TOKEN.INFIXL: found_kind = FunKind.INFIXL elif side.typ is TOKEN.INFIXR: found_kind = FunKind.INFIXR else: raise Exception("Should never happen") found_fixity = yield ps.token(TOKEN.INT) operator = yield ps.token(TOKEN.OP_IDENTIFIER) yield ps.token(TOKEN.PAR_OPEN) a = yield ps.token(TOKEN.IDENTIFIER) yield ps.token(TOKEN.COMMA) b = yield ps.token(TOKEN.IDENTIFIER) yield ps.token(TOKEN.PAR_CLOSE) typesig = yield ps.times(InfFunTypeSig, 0, 1) typesig = typesig[0] if len(typesig) > 0 else None yield ps.token(TOKEN.CURL_OPEN) decls = yield ps.many(VarDecl) found_stmts = yield ps.many1(Stmt) yield ps.token(TOKEN.CURL_CLOSE) return AST.FUNDECL(kind=found_kind, fixity=found_fixity, id=operator, params=[a, b], type=typesig, vardecls=decls, stmts=found_stmts)
def PrefixOpDecl(): yield ps.token(TOKEN.PREFIX) operator = yield ps.token(TOKEN.OP_IDENTIFIER) yield ps.token(TOKEN.PAR_OPEN) varname = yield ps.token(TOKEN.IDENTIFIER) yield ps.token(TOKEN.PAR_CLOSE) typesig = yield ps.times(PreFunTypeSig, 0, 1) typesig = typesig[0] if len(typesig) > 0 else None yield ps.token(TOKEN.CURL_OPEN) decls = yield ps.many(VarDecl) found_stmts = yield ps.many1(Stmt) yield ps.token(TOKEN.CURL_CLOSE) return AST.FUNDECL(kind=FunKind.PREFIX, fixity=None, id=operator, params=[varname], type=typesig, vardecls=decls, stmts=found_stmts)
def FunDecl(): fname = yield ps.token(TOKEN.IDENTIFIER) yield ps.token(TOKEN.PAR_OPEN) args = yield ps.times(FArgs, 0, 1) args = args[0] if len(args) > 0 else args yield ps.token(TOKEN.PAR_CLOSE) typesig = yield ps.times(FunTypeSig, 0, 1) typesig = typesig[0] if len(typesig) > 0 else None yield ps.token(TOKEN.CURL_OPEN) decls = yield ps.many(VarDecl) found_stmts = yield ps.many1(Stmt) yield ps.token(TOKEN.CURL_CLOSE) return AST.FUNDECL(kind=FunKind.FUNC, fixity=None, id=fname, params=args, type=typesig, vardecls=decls, stmts=found_stmts)
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")