fix whitespace

This commit is contained in:
2024-03-08 11:26:52 +01:00
parent 771652b753
commit d051f19c65
3 changed files with 55 additions and 56 deletions

View File

@@ -268,7 +268,7 @@ class Macros {
addBodyIf("unless", "if", true);
addBodyIf("#when", "#if", false);
addBodyIf("#unless", "#if", true);
addCond(k, macros, "cond", "if");
addCond(k, macros, "#cond", "#if");
@@ -277,7 +277,7 @@ class Macros {
var b = wholeExp.expBuilder();
b.str(Context.definedValue(compileTimeResolveToString("The only argument to (#value...)", "a compiler flag's name", args[0], k)));
};
k.doc("#symbol", 1, 1, '(#symbol "<name>")');
macros["#symbol"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
var b = wholeExp.expBuilder();
@@ -302,7 +302,7 @@ class Macros {
return b.let([b.typed("Dynamic", uniqueVarSymbol), firstVal], body);
};
macros["or"] = _or;
@@ -349,7 +349,7 @@ class Macros {
macros["assert"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
var b = wholeExp.expBuilder();
var expression = exps[0];
var letVal = b.symbol();
b.callSymbol("let", [
b.list([
@@ -418,7 +418,7 @@ class Macros {
throw KissError.fromExp(exp, 'first argument to $formName should be a String or list of strings');
};
}
k.doc("defmacro", 3, null, '(defMacro <name> [<args...>] <body...>)');
macros["defmacro"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
k.stateChanged = true;
@@ -451,7 +451,7 @@ class Macros {
var builderName:String = null;
for (arg in argList) {
switch (arg.def) {
case MetaExp("builder", {pos: _, def: Symbol(name)}):
if (builderName == null) {
@@ -473,7 +473,7 @@ class Macros {
macroCallForm += ' <?$name>';
}
++maxArgs;
case MetaExp("opt", {pos: _, def: Symbol(name)}):
argNames.push(name);
macroCallForm += ' <?$name>';
@@ -798,7 +798,7 @@ class Macros {
switch (exps[1].def) {
case CallExp({pos: _, def: Symbol("catch")}, catchArgs):
exps.splice(1,1);
rejectionHandler = b.symbol();
rejectionHandler = b.symbol();
rejectionHandlerArgsAndBody = catchArgs;
default:
usingDefaultHandler = true;
@@ -833,7 +833,7 @@ class Macros {
]),
rejectionHandler
]);
if (rejectionHandlerArgsAndBody.length > 0) {
exp = b.callSymbol("withFunctions", [
b.list([b.call(b.typed("Dynamic", rejectionHandler),
@@ -844,9 +844,9 @@ class Macros {
return exp;
}
macros["awaitLet"] = awaitLet.bind(null);
k.doc("whileLet", 2, null, "(whileLet [<bindings...>] <body...>)");
macros["whileLet"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
var b = wholeExp.expBuilder();
@@ -1027,7 +1027,7 @@ class Macros {
k.stateChanged = true;
var name = exps[0].symbolName().withPosOf(exps[0]);
var b = wholeExp.expBuilder();
return b.callSymbol("_setMacroVar", [name, exps[1]]);
};
@@ -1073,7 +1073,6 @@ class Macros {
}
}
var b = wholeExp.expBuilder();
b.callSymbol("object", objectExps);
}
@@ -1353,14 +1352,14 @@ class Macros {
macros["printAllNulls"] = printAll.bind(false, true);
k.doc("printLocalNulls", 0, 0, "(printLocalNulls)");
macros["printLocalNulls"] = printAll.bind(true, true);
var savedVarFilename = null;
k.doc("savedVarFile", 1, 1, '(savedVarFilename "<path>")');
macros["savedVarFile"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
savedVarFilename = compileTimeResolveToString("The only argument to (savedVarFile...)", "a json filename", exps[0], k);
null;
};
k.doc("savedVar", 2, 2, "(savedVar <:Type> <name> <initial value>)");
macros["savedVar"] = (wholeExp:ReaderExp, exps:Array<ReaderExp>, k:KissState) -> {
var b = wholeExp.expBuilder();
@@ -1375,7 +1374,7 @@ class Macros {
} else {
b.str("." + k.className + ".json");
};
function ifLetFileJson(thenBlock:Array<ReaderExp>, elseBlock:Array<ReaderExp>) {
return b.callSymbol("if", [
b.callSymbol("and", [
@@ -1391,34 +1390,34 @@ class Macros {
b.begin(elseBlock)
]);
}
var setAndSave = [
b.callSymbol("dictSet", [b.symbol("json"), b.str(nameString), b.raw("tink.Json.stringify(v)")]),
b.callSymbol("sys.io.File.saveContent", [filename, b.raw("haxe.Json.stringify(json)")]),
b.raw("v;")
];
b.begin([
b.callSymbol("var", [name, b.callSymbol("property", [b.symbol("get"), b.symbol("set")])]),
b.callSymbol(
"function", [
b.typed(type, b.symbol('get_${nameString}')),
b.list([]),
b.typed(type, b.symbol('get_${nameString}')),
b.list([]),
ifLetFileJson([
b.callSymbol("if", [
b.callSymbol("json.exists", [b.str(nameString)]),
b.raw("{ var v:" + type + " = tink.Json.parse(json['" + nameString + "']); v;}"),
initialValue
])
],
],
[
initialValue
])
]),
b.callSymbol(
"function", [
b.typed(type, b.symbol('set_${nameString}')),
b.list([b.typed(type, b.symbol("v"))]),
b.typed(type, b.symbol('set_${nameString}')),
b.list([b.typed(type, b.symbol("v"))]),
ifLetFileJson(
setAndSave,
[
@@ -1481,7 +1480,7 @@ class Macros {
default:
throw KissError.fromExp(funcExp, "withFunctions function definition should follow this form: (<funcName> [<args...>] <body...>)");
}
} while (funcList.length > 0);
var exp = b.begin(localFunctions.concat(args.slice(1)));
@@ -1508,7 +1507,7 @@ class Macros {
};
null;
};
k.doc("typeCase", 2, null, "(typeCase [<values>] ([:<Type> <name> <more typed names...>] <body>) <more cases...> (otherwise <required default>))");
macros["typeCase"] = (wholeExp:ReaderExp, args:Array<ReaderExp>, k:KissState) -> {
var b = wholeExp.expBuilder();
@@ -1563,12 +1562,12 @@ class Macros {
default: c;
}
}];
b.let(outerLetBindings, [
b.callSymbol("case", [b.list(symbols)].concat(cases))
]);
}
return macros;
}
@@ -1599,7 +1598,7 @@ class Macros {
var patternTypePath = Prelude.symbolNameValue(type);
return switch (instance.def) {
case TypedExp(typePath, instanceExp) if (typePath == patternTypePath):
matchExpr(patternExp, instanceExp);
matchExpr(patternExp, instanceExp);
default:
false;
};

View File

@@ -374,15 +374,15 @@ class BasicTestCase extends Test {
function testQuickFractions() {
_testQuickFractions();
}
function testWhenLetGuards() {
_testWhenLetGuards();
}
function testImportAndUsingInBuildMacro() {
_testImportAndUsingInBuildMacro();
}
function testPureKissClasses() {
_testPureKissClasses();
}

View File

@@ -5,7 +5,7 @@
(catch [:String message]
(Assert.equals "src/test/cases/BasicTestCase.kiss:4:13: Assertion failed: false should have been true
From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" message)))
(assert true)
(assert ![])
(assertEquals 6 6 6))
@@ -25,7 +25,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
// #| ... |# parses and injects raw Haxe code.
// Order of operations will apply
(Assert.equals 23 #|5 + 6 * 3|#)
// #{ ... }# parses and injects a raw Haxe block. It is preferred over #| |#
// #{ ... }# parses and injects a raw Haxe block. It is preferred over #| |#
(let [&mut a 5 &mut b 6]
#{
a += 6; b += 5;
@@ -35,7 +35,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
// (function) declares static functions
(function myFloor [num]
(function myFloor [num]
// funcalls can use dot access
(Math.floor num))
@@ -64,7 +64,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(Assert.equals -2 (- 5 4 3))
(Assert.equals -2 (- 2)))
(function _testMultiplication []
(function _testMultiplication []
(Assert.equals 60 (* 2 5 6))
(Assert.equals 5522401584 (* 84 289 89 71 36))
(Assert.equals "heyheyhey" (* "hey" 3)))
@@ -86,7 +86,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(Assert.isTrue (< 1 2 3 4))
(Assert.isFalse (< 1 1 3 4))
(Assert.isFalse (< 1 12 12)))
(function _testLesserEqual []
(Assert.isTrue (<= 1 2 3 4))
(Assert.isTrue (<= 1 1 3 4))
@@ -178,13 +178,13 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(function _testCond []
(Assert.equals "this one"
(cond
(cond
((= 5 6) "not this")
((= 8 9) "not this either")
((= 1 1) "this one")
(true "not the default")))
(Assert.equals "the default"
(cond
(cond
((= 5 6) "not this")
((= 8 9) "not this either")
((= 2 1) "not the third one")
@@ -218,7 +218,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(var myNot1 (not 5))
(var myNot2 !5)
(var myFilteredList (begin
(var myFilteredList (begin
(localVar l [-1 -2 5 -3 6])
(l.filter (lambda [v] (< 0 v)))))
@@ -412,7 +412,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(Assert.equals 5 v)
(Assert.isTrue (Type.enumEq (Some 5) inner)))
(otherwise (Assert.fail)))
// Otherwise blocks should allow multiple expressions, too:
(case 5
(otherwise
@@ -478,7 +478,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(localVar message1 (ReaderExp.StrExp "Welcome "))
(localVar message2 (ReaderExp.StrExp " (Guest #"))
(localVar message3 (ReaderExp.StrExp ")"))
`(begin (set welcomeCount (+ welcomeCount 1))
(+ ,message1 ,name ,message2 (Std.string welcomeCount) ,message3)))
@@ -533,16 +533,16 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(unlessLet [(Some (or 5 6)) some5]
(print "something else went wrong!")
(Assert.fail))
// Don't double evaluate the expression:
// Don't double evaluate the expression:
(let [&mut v 1]
(unlessLet [2 (begin (+= v 1) v)]
(Assert.fail))
(Assert.equals 2 v))
(assertThrows (assertLet [(Some thing) none] thing))
(Assert.equals 5 (assertLet [(Some thing) some5] thing)))
// Issue #64 regression tests:
(whenLet [something null]
(Assert.fail))
@@ -598,7 +598,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(function _testLetThrow []
(try
{
(letThrow
(letThrow
(throw "the error we want")
(catch [e] (Assert.fail)))
(Assert.fail)}
@@ -742,7 +742,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(assertThrows (<= a))
(assertThrows (> a))
(assertThrows (>= a))
)
(Assert.pass))
@@ -812,7 +812,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(localFunction c [val] (+ (a val) (b val)))
(Assert.equals 5 (c 1))))
(function _testWithTempSet []
(function _testWithTempSet []
(let [&mut v 5
&mut v2 3]
(assertEquals 5 v)
@@ -844,13 +844,13 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(Assert.isTrue (savedPrints.contains "anotherStaticNullToPrint: null"))
(Assert.isTrue (savedPrints.contains "nullDefinedInHaxe: null"))
(Assert.isTrue (savedPrints.contains "staticNullDefinedInHaxe: null"))
// TODO This statement prints a warning at compile-time, which won't
// appear in savedPrints, so it's harder to test...
(prop tp "bad")
(let [u null]
// TODO this statement should print a warning at compile-time (#112)
// TODO this statement should print a warning at compile-time (#112)
(localVar v "bad")
(set savedPrints [])
@@ -870,21 +870,21 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(var ts "bad")
(let [u null]
// TODO this statement should print a warning at compile-time (#112)
// TODO this statement should print a warning at compile-time (#112)
(localVar v "bad")
(set savedPrints [])
(printLocalNulls)
(Assert.isFalse (savedPrints.contains "anotherStaticNullToPrint: null"))
(Assert.isTrue (savedPrints.contains "u: null")))
// Test for loop capture variables
(set savedPrints [])
(doFor a (for _ (range 5) null)
(printLocalNulls))
(Assert.isTrue (savedPrints.contains "a: null"))
(Assert.equals 5 savedPrints.length)
(set savedPrints [])
(let [:Map<String,String> m (for a (range 5) =>"$a" "a")]
(doFor =>k v m
@@ -899,7 +899,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(printLocalNulls)))
(Assert.isTrue (savedPrints.contains "v: null"))
(Assert.equals 5 savedPrints.length)
(set savedPrints [])
(doFor [a b c] (for _ (range 5) [1 null 5])
(printLocalNulls))
@@ -944,7 +944,7 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(never otherwise)))
(function _testQuickPrintOnSetVar []
(let [&mut v 5]