|
@ -37,17 +37,17 @@ function isIrregularTypeOp(x) { |
|
|
return (x === "->"); |
|
|
return (x === "->"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function flattenTypeApp(stx) { |
|
|
function flattenTypeDecl(stx) { |
|
|
if (isTypeExpr(stx)) { |
|
|
if (isTypeExpr(stx)) { |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
if (stx.exprType === "Application") { |
|
|
if (stx.exprType === "Application") { |
|
|
/* it might be a type application so recursively check it */ |
|
|
/* it might be a type application so recursively check it */ |
|
|
if (stx.p !== undefined) { |
|
|
if (stx.p !== undefined) { |
|
|
return _.flatten([flattenTypeApp(stx.p), flattenTypeApp(stx.func)]); |
|
|
return _.flatten([flattenTypeDecl(stx.p), flattenTypeDecl(stx.func)]); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
return _.flatten([flattenTypeApp(stx.func)]); |
|
|
return _.flatten([flattenTypeDecl(stx.func)]); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if (stx.exprType === "Name") { |
|
|
if (stx.exprType === "Name") { |
|
@ -66,7 +66,7 @@ function flattenTypeApp(stx) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isTypeExprRec(stx) { |
|
|
function isTypeExprRec(stx) { |
|
|
var flattened = flattenTypeApp(stx); |
|
|
var flattened = flattenTypeDecl(stx); |
|
|
for(var i = 0; i < flattened.length; i++) { |
|
|
for(var i = 0; i < flattened.length; i++) { |
|
|
if (flattened[i].failed !== undefined && |
|
|
if (flattened[i].failed !== undefined && |
|
|
flattened[i].failed) { |
|
|
flattened[i].failed) { |
|
@ -266,30 +266,30 @@ function isTypeExpr(expr) { |
|
|
} |
|
|
} |
|
|
return ((expr.exprType === "TypeOperator") || |
|
|
return ((expr.exprType === "TypeOperator") || |
|
|
(expr.exprType === "TypeVar") || |
|
|
(expr.exprType === "TypeVar") || |
|
|
(expr.exprType === "TypeApplication")); |
|
|
(expr.exprType === "TypeDeclaration")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function TypeApp(expression, type) { |
|
|
function TypeDecl(expression, type) { |
|
|
if (isTypeExprRec(expression) && |
|
|
if (isTypeExprRec(expression) && |
|
|
expression.exprType !== "Name") { |
|
|
expression.exprType !== "Name") { |
|
|
throw errors.JSyntaxError( |
|
|
throw errors.JSyntaxError( |
|
|
expression.linenum, |
|
|
expression.linenum, |
|
|
expression.charnum, |
|
|
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)) { |
|
|
if (!isTypeExprRec(type)) { |
|
|
throw errors.JInternalError( |
|
|
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.expression = expression; |
|
|
this.type = type; |
|
|
this.type = type; |
|
|
this.exprType = "TypeApplication"; |
|
|
this.exprType = "TypeDeclaration"; |
|
|
return this; |
|
|
return this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
TypeApp.prototype = TypeExpression; |
|
|
TypeDecl.prototype = TypeExpression; |
|
|
|
|
|
|
|
|
function DefType(lhs, rhs) { |
|
|
function DefType(lhs, rhs) { |
|
|
/* Both rhs and lhs are expected |
|
|
/* Both rhs and lhs are expected |
|
@ -416,7 +416,7 @@ module.exports = |
|
|
gensym : gensym, |
|
|
gensym : gensym, |
|
|
TypeVar : TypeVar, |
|
|
TypeVar : TypeVar, |
|
|
TypeOp : TypeOp, |
|
|
TypeOp : TypeOp, |
|
|
TypeApp: TypeApp, |
|
|
TypeDecl : TypeDecl, |
|
|
Closure : Closure, |
|
|
Closure : Closure, |
|
|
isTypeExpr : isTypeExprRec, |
|
|
isTypeExpr : isTypeExprRec, |
|
|
DefType : DefType, |
|
|
DefType : DefType, |
|
|