Browse Source

fix a few bugs, functionality for aliasing type operators now works

pull/15/head
nisstyre56 11 years ago
parent
commit
39403648ec
  1. 7
      parse.js
  2. 7
      pprint.js
  3. 11
      representation.js

7
parse.js

@ -374,7 +374,7 @@ function parseDefType(tokens, linenum, charnum) {
return parseDataType(tokens, linenum, charnum);
}
if (notFollowedBy(tokens, ["constructor"]. linenum, charnum)) {
if (notFollowedBy(tokens, ["constructor"], linenum, charnum)) {
throw error.JSyntaxError(linenum,
charnum,
"deftype must be followed by a single constructor" +
@ -400,6 +400,8 @@ function parseDefType(tokens, linenum, charnum) {
rhs.charnum,
"was expecting an application or type operator on the right-hand side of a type definition");
}
result = new typ.DefType(lhs, rhs);
return result;
}
}
@ -737,6 +739,9 @@ function parse(tokens) {
toktype === "let") {
return parseDef(tokens, linenum, charnum);
}
else if (toktype === "deftype") {
return parseDefType(tokens, linenum, charnum);
}
else if (toktype === "defop") {
return parseDefOp(tokens, linenum, charnum);
}

7
pprint.js

@ -26,6 +26,10 @@ function pprintIf(ifexp) {
" else " + pprint(ifexp.elseexp) + ")");
}
function pprintDefType(stx) {
return pprint(stx.lhs) + " = " + pprint(stx.rhs);
}
function pprint(expr) {
if (expr.exprType === "Name") {
return expr.val;
@ -56,6 +60,9 @@ function pprint(expr) {
else if (expr.exprType === "Definition") {
return pprintDef(expr);
}
else if (expr.exprType === "TypeDefinition") {
return pprintDefType(expr);
}
else if (expr.exprType === "If") {
return pprintIf(expr);
}

11
representation.js

@ -295,9 +295,9 @@ function DefType(rhs, lhs) {
/* Both rhs and lhs are expected
* to be fully desugared already
*/
if (!isExprType(rhs) ||
!isExprType(lhs)) {
throw erros.JSyntaxError(
if (!isTypeExpr(rhs) ||
!isTypeExpr(lhs)) {
throw errors.JSyntaxError(
rhs.linenum,
rhs.charnum,
"Illegal type definition, both sides must be valid type expressions");
@ -308,6 +308,8 @@ function DefType(rhs, lhs) {
return this;
}
DefType.prototype = Expression;
//Applies the function ``name'' to the list of parameters
function makeApp(name, parameters) {
@ -381,5 +383,6 @@ module.exports =
TypeOp : TypeOp,
TypeApp: TypeApp,
Closure : Closure,
isTypeExpr : isTypeExprRec
isTypeExpr : isTypeExprRec,
DefType : DefType
};

Loading…
Cancel
Save