use expBuilder for assert
This commit is contained in:
@@ -299,20 +299,20 @@ class Macros {
|
|||||||
arraySet(wholeExp, exps, k);
|
arraySet(wholeExp, exps, k);
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO use expBuilder()
|
|
||||||
macros["assert"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
macros["assert"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
|
||||||
wholeExp.checkNumArgs(1, 2, "(assert [expression] [message])");
|
wholeExp.checkNumArgs(1, 2, "(assert [expression] [message])");
|
||||||
|
var b = wholeExp.expBuilder();
|
||||||
var expression = exps[0];
|
var expression = exps[0];
|
||||||
var basicMessage = 'Assertion ${expression.def.toString()} failed';
|
var basicMessage = 'Assertion ${expression.def.toString()} failed';
|
||||||
var messageExp = if (exps.length > 1) {
|
var messageExp = if (exps.length > 1) {
|
||||||
CallExp(Symbol("+").withPosOf(wholeExp), [StrExp(basicMessage + ": ").withPosOf(wholeExp), exps[1]]);
|
b.callSymbol("+", [b.str(basicMessage + ": "), exps[1]]);
|
||||||
} else {
|
} else {
|
||||||
StrExp(basicMessage);
|
b.str(basicMessage);
|
||||||
};
|
};
|
||||||
CallExp(Symbol("unless").withPosOf(wholeExp), [
|
b.callSymbol("unless", [
|
||||||
expression,
|
expression,
|
||||||
CallExp(Symbol("throw").withPosOf(wholeExp), [messageExp.withPosOf(wholeExp)]).withPosOf(wholeExp)
|
b.callSymbol("throw", [messageExp])
|
||||||
]).withPosOf(wholeExp);
|
]);
|
||||||
};
|
};
|
||||||
|
|
||||||
function stringsThatMatch(exp:ReaderExp) {
|
function stringsThatMatch(exp:ReaderExp) {
|
||||||
|
|||||||
Reference in New Issue
Block a user