Browse Source

should error if an if-then-else expression has no else variant (must be that way due to the type system)

pull/2/head
nisstyre56 11 years ago
parent
commit
3b464b81cf
  1. 21
      parse.js

21
parse.js

@ -1,5 +1,4 @@
#! /usr/bin/node #! /usr/bin/node
var fs = require("fs"); var fs = require("fs");
var typ = require("./representation.js"); var typ = require("./representation.js");
var $ = require("./tools.js"); var $ = require("./tools.js");
@ -401,10 +400,11 @@ function parseIf(tokens) {
} }
else { else {
var ifC = parse(tokens); var ifC = parse(tokens);
if (!fst(tokens) || fst(tokens)[0] !== "thenexp") if (!fst(tokens) || fst(tokens)[0] !== "thenexp") {
throw error.JSyntaxError(fst(tokens)[3], throw error.JSyntaxError(fst(tokens)[3],
fst(tokens)[2], fst(tokens)[2],
"if ``exp'' must be folowed by ``then'' exp, not "+snd(tokens)[0]); "if ``exp'' must be folowed by ``then'' exp, not "+snd(tokens)[0]);
}
else { else {
tokens.pop(); tokens.pop();
var thenC = parse(tokens); var thenC = parse(tokens);
@ -416,15 +416,18 @@ function parseIf(tokens) {
charnum, charnum,
"Unexpected end of source"); "Unexpected end of source");
} }
else {
var elseC = parse(tokens); var elseC = parse(tokens);
return new typ.If(ifC, thenC, elseC); return new typ.If(ifC, thenC, elseC);
}
} }
else { else {
return new typ.If(ifC, thenC); throw error.JSyntaxError(linenum,
} charnum,
} "If expression must include an else variant");
} }
}
}
} }

Loading…
Cancel
Save