diff --git a/desugar.js b/desugar.js index eb5f998..9da5d4e 100644 --- a/desugar.js +++ b/desugar.js @@ -47,14 +47,14 @@ function desugarLet(stx) { return new typ.LetExp(values, desugar(stx.body)); } -function sugarTypeApp(stx) { +function sugarTypeDecl(stx) { var type; var expression; type = stx.p; expression = desugar(stx.func.p); expression.linenum = stx.linenum; expression.charnum = stx.charnum; - return new typ.TypeApp(expression, type); + return new typ.TypeDecl(expression, type); } function desugarDefType(stx) { @@ -86,19 +86,19 @@ function desugar(stx) { case "Application": if ((stx.func.func !== undefined ) && (stx.func.func.ident === "::")) { - /* It's a type application probably (will be verified later) - * In this case we actually *add* syntax here to differentiate type applications - * from normal applications + /* It's a type declaration probably (will be verified later) + * In this case we actually *add* syntax here to differentiate type declarations + * from normal function application */ typeExpTest = typ.isTypeExpr(stx.p); if (typeExpTest.failed !== undefined && typeExpTest.failed) { throw errors.JInternalError( - "Type application error near line " + stx.linenum + " at character #"+stx.charnum + + "Type declaration error near line " + stx.linenum + " at character #"+stx.charnum + "\n"+typeExpTest.stx.exprType+" (" + typeExpTest.stx.val + ") found where a type operator or type application was expected"); } - return sugarTypeApp(stx); + return sugarTypeDecl(stx); } if ((stx.func.ident === "-" || diff --git a/parse.js b/parse.js index 780f9d7..d56d73d 100755 --- a/parse.js +++ b/parse.js @@ -801,8 +801,7 @@ function parseFull(tokenized) { var ast = []; try { while (tokenized.length > 0) { - var parsed = desugarer.desugar(parse(tokenized)); - ast.push(parsed); + ast.push(desugarer.desugar(parse(tokenized))); } return ast; } catch (e) { diff --git a/pprint.js b/pprint.js index 6986b0c..addfd76 100644 --- a/pprint.js +++ b/pprint.js @@ -94,7 +94,7 @@ function pprint(expr) { else if (expr.exprType === "TypeVar") { return "("+expr.name+")"; } - else if (expr.exprType === "TypeApplication") { + else if (expr.exprType === "TypeDeclaration") { return "( " + pprint(expr.expression) + " :: " + pprint(expr.type) + " )"; } } diff --git a/representation.js b/representation.js index 9db580d..be07c08 100644 --- a/representation.js +++ b/representation.js @@ -37,17 +37,17 @@ function isIrregularTypeOp(x) { return (x === "->"); } -function flattenTypeApp(stx) { +function flattenTypeDecl(stx) { if (isTypeExpr(stx)) { return true; } if (stx.exprType === "Application") { /* it might be a type application so recursively check it */ if (stx.p !== undefined) { - return _.flatten([flattenTypeApp(stx.p), flattenTypeApp(stx.func)]); + return _.flatten([flattenTypeDecl(stx.p), flattenTypeDecl(stx.func)]); } else { - return _.flatten([flattenTypeApp(stx.func)]); + return _.flatten([flattenTypeDecl(stx.func)]); } } if (stx.exprType === "Name") { @@ -66,7 +66,7 @@ function flattenTypeApp(stx) { function isTypeExprRec(stx) { - var flattened = flattenTypeApp(stx); + var flattened = flattenTypeDecl(stx); for(var i = 0; i < flattened.length; i++) { if (flattened[i].failed !== undefined && flattened[i].failed) { @@ -266,30 +266,30 @@ function isTypeExpr(expr) { } return ((expr.exprType === "TypeOperator") || (expr.exprType === "TypeVar") || - (expr.exprType === "TypeApplication")); + (expr.exprType === "TypeDeclaration")); } -function TypeApp(expression, type) { +function TypeDecl(expression, type) { if (isTypeExprRec(expression) && expression.exprType !== "Name") { throw errors.JSyntaxError( expression.linenum, expression.charnum, - "Left-hand-side of type application must not be in the type language" + "Left-hand-side of type declaration must not be in the type language" ); } if (!isTypeExprRec(type)) { throw errors.JInternalError( - "Right-hand-side of type application must be a type expression" + "Right-hand-side of type declaration must be a type expression" ); } this.expression = expression; this.type = type; - this.exprType = "TypeApplication"; + this.exprType = "TypeDeclaration"; return this; } -TypeApp.prototype = TypeExpression; +TypeDecl.prototype = TypeExpression; function DefType(lhs, rhs) { /* Both rhs and lhs are expected @@ -416,7 +416,7 @@ module.exports = gensym : gensym, TypeVar : TypeVar, TypeOp : TypeOp, - TypeApp: TypeApp, + TypeDecl : TypeDecl, Closure : Closure, isTypeExpr : isTypeExprRec, DefType : DefType,