|
@ -291,13 +291,13 @@ function TypeApp(expression, type) { |
|
|
|
|
|
|
|
|
TypeApp.prototype = TypeExpression; |
|
|
TypeApp.prototype = TypeExpression; |
|
|
|
|
|
|
|
|
function DefType(rhs, lhs) { |
|
|
function DefType(lhs, rhs) { |
|
|
/* Both rhs and lhs are expected |
|
|
/* Both rhs and lhs are expected |
|
|
* to be fully desugared already |
|
|
* to be fully desugared already |
|
|
*/ |
|
|
*/ |
|
|
if (!isExprType(rhs) || |
|
|
if (!isTypeExprRec(rhs) || |
|
|
!isExprType(lhs)) { |
|
|
!isTypeExpr(lhs)) { |
|
|
throw erros.JSyntaxError( |
|
|
throw errors.JSyntaxError( |
|
|
rhs.linenum, |
|
|
rhs.linenum, |
|
|
rhs.charnum, |
|
|
rhs.charnum, |
|
|
"Illegal type definition, both sides must be valid type expressions"); |
|
|
"Illegal type definition, both sides must be valid type expressions"); |
|
@ -308,6 +308,34 @@ function DefType(rhs, lhs) { |
|
|
return this; |
|
|
return this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DefType.prototype = Expression; |
|
|
|
|
|
|
|
|
|
|
|
function checkName(exp) { |
|
|
|
|
|
if (exp.exprType !== "Name") { |
|
|
|
|
|
throw errors.JSyntaxError( |
|
|
|
|
|
exp.linenum, |
|
|
|
|
|
exp.charnum, |
|
|
|
|
|
"Expected a type variable (an identifier starting with a lowercase character), got " + exp.val); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function DataType(params, type) { |
|
|
|
|
|
/* Params is a list of type variables |
|
|
|
|
|
* type is a type expression |
|
|
|
|
|
*/ |
|
|
|
|
|
_.each(params, checkName); |
|
|
|
|
|
if (!isTypeExprRec(type)) { |
|
|
|
|
|
throw errors.JSyntaxError( |
|
|
|
|
|
type.linenum, |
|
|
|
|
|
type.charnum, |
|
|
|
|
|
"Body of a type definition must be a valid type expression"); |
|
|
|
|
|
} |
|
|
|
|
|
this.params = params; |
|
|
|
|
|
this.type = type; |
|
|
|
|
|
this.exprType = "TypeFuncDefinition"; |
|
|
|
|
|
return this; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Applies the function ``name'' to the list of parameters
|
|
|
//Applies the function ``name'' to the list of parameters
|
|
|
function makeApp(name, parameters) { |
|
|
function makeApp(name, parameters) { |
|
@ -381,5 +409,6 @@ module.exports = |
|
|
TypeOp : TypeOp, |
|
|
TypeOp : TypeOp, |
|
|
TypeApp: TypeApp, |
|
|
TypeApp: TypeApp, |
|
|
Closure : Closure, |
|
|
Closure : Closure, |
|
|
isTypeExpr : isTypeExprRec |
|
|
isTypeExpr : isTypeExprRec, |
|
|
|
|
|
DefType : DefType |
|
|
}; |
|
|
}; |
|
|