From 0eafd96a7f217d91f2767fb7f4caf8704eeb7246 Mon Sep 17 00:00:00 2001 From: nisstyre56 Date: Sun, 18 May 2014 17:20:40 -0400 Subject: [PATCH] representation for type definitions with parameters --- representation.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/representation.js b/representation.js index 95ca437..bea8317 100644 --- a/representation.js +++ b/representation.js @@ -310,10 +310,30 @@ function DefType(lhs, rhs) { 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; }