|
@ -207,7 +207,7 @@ function parseDefFunction(tokens, linenum, charnum) { |
|
|
fst(tokens)[2], |
|
|
fst(tokens)[2], |
|
|
fst(tokens)[3]); |
|
|
fst(tokens)[3]); |
|
|
} |
|
|
} |
|
|
if ((fst(tokens)[0]) !== "right_paren") { |
|
|
if (!tokens || (fst(tokens)[0]) !== "right_paren") { |
|
|
throw error.JSyntaxError(fst(tokens)[3], |
|
|
throw error.JSyntaxError(fst(tokens)[3], |
|
|
fst(tokens)[2], |
|
|
fst(tokens)[2], |
|
|
"Formal parameters must be followed by )"); |
|
|
"Formal parameters must be followed by )"); |
|
@ -353,6 +353,34 @@ function parseLetItem(tokens) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function parseDataType(tokens, linenum, charnum) { |
|
|
|
|
|
var typeName = parse(tokens, linenum, charnum); |
|
|
|
|
|
var typeParams; |
|
|
|
|
|
var typeBody; |
|
|
|
|
|
|
|
|
|
|
|
if (typeName.exprType !== "TypeOperator") { |
|
|
|
|
|
throw error.JSyntaxError(typeName.linenum, |
|
|
|
|
|
typeName.charnum, |
|
|
|
|
|
"Expected a type operator in data type definition"); |
|
|
|
|
|
} |
|
|
|
|
|
parameters = parseMany(parse, |
|
|
|
|
|
validName, |
|
|
|
|
|
validFormPar, |
|
|
|
|
|
tokens, |
|
|
|
|
|
charnum, |
|
|
|
|
|
linenum); |
|
|
|
|
|
if (!tokens || (fst(tokens)[0]) !== "right_paren") { |
|
|
|
|
|
throw error.JSyntaxError(fst(tokens)[3], |
|
|
|
|
|
fst(tokens)[2], |
|
|
|
|
|
"Data type parameters must be followed by )"); |
|
|
|
|
|
} |
|
|
|
|
|
tokens.pop(); |
|
|
|
|
|
typeBody = parse(tokens); |
|
|
|
|
|
return addSrcPos(new typ.DataType, tokens, typeBody.linenum, typeBody.charnum); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function parseDefType(tokens, linenum, charnum) { |
|
|
function parseDefType(tokens, linenum, charnum) { |
|
|
var result; |
|
|
var result; |
|
|
var rhs; |
|
|
var rhs; |
|
@ -464,7 +492,7 @@ function parseDef(tokens, linenum, charnum) { |
|
|
charnum, |
|
|
charnum, |
|
|
"A definition cannot be the value of a binding"); |
|
|
"A definition cannot be the value of a binding"); |
|
|
} |
|
|
} |
|
|
result = addSrcPos(new typ.Def(identifier, bound), tokens, linenum, charnum); |
|
|
result = addSrcPos(new typ.Def(identifier, bound), tokens, bound.linenum, bound.charnum); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -562,7 +590,7 @@ function parseIf(tokens) { |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
var elseC = parse(tokens); |
|
|
var elseC = parse(tokens); |
|
|
result = addSrcPos(new typ.If(ifC, thenC, elseC), tokens, linenum, charnum); |
|
|
result = addSrcPos(new typ.If(ifC, thenC, elseC), tokens, elseC.linenum, elseC.charnum); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -599,7 +627,7 @@ function parseLambda(tokens) { |
|
|
} |
|
|
} |
|
|
tokens.pop(); |
|
|
tokens.pop(); |
|
|
var body = parse(tokens); |
|
|
var body = parse(tokens); |
|
|
result = addSrcPos(new typ.FuncT(parameters, body), tokens, linenum, charnum); |
|
|
result = addSrcPos(new typ.FuncT(parameters, body), tokens, body.linenum, body.charnum); |
|
|
return result; |
|
|
return result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -687,7 +715,7 @@ function parseInfix(tokens, minPrec, lhs, linenum, charnum) { |
|
|
tokens.pop(); |
|
|
tokens.pop(); |
|
|
/*remove the operator token*/ |
|
|
/*remove the operator token*/ |
|
|
var rhs = parseInfix(tokens, nextMinPrec); |
|
|
var rhs = parseInfix(tokens, nextMinPrec); |
|
|
lhs = addSrcPos(typ.makeApp(op, [lhs, rhs]), tokens, linenum, charnum); |
|
|
lhs = addSrcPos(typ.makeApp(op, [lhs, rhs]), tokens, rhs.linenum, rhs.charnum); |
|
|
} |
|
|
} |
|
|
return lhs; |
|
|
return lhs; |
|
|
} |
|
|
} |
|
|