Browse Source

pretty print debugging for data type defs, fixed another mistake

pull/16/head
nisstyre56 11 years ago
parent
commit
f33ee5ae70
  1. 2
      parse.js
  2. 7
      pprint.js
  3. 10
      representation.js

2
parse.js

@ -377,7 +377,7 @@ function parseDataType(tokens, linenum, charnum) {
} }
tokens.pop(); tokens.pop();
typeBody = parse(tokens); typeBody = parse(tokens);
result = addSrcPos(new typ.DataType(parameters, typeBody), tokens, typeBody.linenum, typeBody.charnum); result = addSrcPos(new typ.DataType(typeName, parameters, typeBody), tokens, typeBody.linenum, typeBody.charnum);
return result; return result;
} }

7
pprint.js

@ -30,6 +30,10 @@ function pprintDefType(stx) {
return pprint(stx.lhs) + " = " + pprint(stx.rhs); return pprint(stx.lhs) + " = " + pprint(stx.rhs);
} }
function pprintTypeFunc(stx) {
return "(" + stx.name.name + " " + stx.params.map(pprint).join(" ") + ") = " + pprint(stx.type);
}
function pprint(expr) { function pprint(expr) {
if (expr.exprType === "Name") { if (expr.exprType === "Name") {
return expr.val; return expr.val;
@ -63,6 +67,9 @@ function pprint(expr) {
else if (expr.exprType === "TypeDefinition") { else if (expr.exprType === "TypeDefinition") {
return pprintDefType(expr); return pprintDefType(expr);
} }
else if (expr.exprType === "TypeFuncDefinition") {
return pprintTypeFunc(expr);
}
else if (expr.exprType === "If") { else if (expr.exprType === "If") {
return pprintIf(expr); return pprintIf(expr);
} }

10
representation.js

@ -319,10 +319,17 @@ function checkName(exp) {
} }
} }
function DataType(params, type) { function DataType(name, params, type) {
/* Params is a list of type variables /* Params is a list of type variables
* type is a type expression * type is a type expression
*/ */
if (name.exprType !== "TypeOperator") {
throw errors.JSyntaxError(
name.linenum,
name.charnum,
"First element in a data type definition must be its name " +
"which is a type operator");
}
_.each(params, checkName); _.each(params, checkName);
if (!isTypeExprRec(type)) { if (!isTypeExprRec(type)) {
throw errors.JSyntaxError( throw errors.JSyntaxError(
@ -330,6 +337,7 @@ function DataType(params, type) {
type.charnum, type.charnum,
"Body of a type definition must be a valid type expression"); "Body of a type definition must be a valid type expression");
} }
this.name = name;
this.params = params; this.params = params;
this.type = type; this.type = type;
this.exprType = "TypeFuncDefinition"; this.exprType = "TypeFuncDefinition";

Loading…
Cancel
Save