move isEmpty() into Kiss class
This commit is contained in:
@@ -10,6 +10,7 @@ using kiss.Helpers;
|
|||||||
#end
|
#end
|
||||||
|
|
||||||
import kiss.Kiss;
|
import kiss.Kiss;
|
||||||
|
import kiss.ReaderExp;
|
||||||
import kiss.Prelude;
|
import kiss.Prelude;
|
||||||
import kiss.cloner.Cloner;
|
import kiss.cloner.Cloner;
|
||||||
|
|
||||||
@@ -178,7 +179,8 @@ class AsyncEmbeddedScript {
|
|||||||
Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> {
|
Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> {
|
||||||
var exprString = Reader.toString(nextExp.def);
|
var exprString = Reader.toString(nextExp.def);
|
||||||
var expr = Kiss.readerExpToHaxeExpr(nextExp, k);
|
var expr = Kiss.readerExpToHaxeExpr(nextExp, k);
|
||||||
|
if (Kiss.isEmpty(expr))
|
||||||
|
return;
|
||||||
#if debug
|
#if debug
|
||||||
expr = macro { Prelude.print($v{exprString}); $expr; };
|
expr = macro { Prelude.print($v{exprString}); $expr; };
|
||||||
expr = expr.expr.withMacroPosOf(nextExp);
|
expr = expr.expr.withMacroPosOf(nextExp);
|
||||||
|
|||||||
@@ -404,19 +404,7 @@ class Kiss {
|
|||||||
// file that loaded them at the position (load) was called.
|
// file that loaded them at the position (load) was called.
|
||||||
// conditional compiler macros like (#when) tend to return empty blocks, or blocks containing empty blocks
|
// conditional compiler macros like (#when) tend to return empty blocks, or blocks containing empty blocks
|
||||||
// when they contain field forms, so this should also be ignored
|
// when they contain field forms, so this should also be ignored
|
||||||
function isEmpty(expr) {
|
|
||||||
switch (expr.expr) {
|
|
||||||
case EBlock([]):
|
|
||||||
case EBlock(blockExps):
|
|
||||||
for (exp in blockExps) {
|
|
||||||
if (!isEmpty(exp))
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// When calling from build(), we can't add all expressions to the (begin) returned by (load), because that will
|
// When calling from build(), we can't add all expressions to the (begin) returned by (load), because that will
|
||||||
// cause double-evaluation of field forms
|
// cause double-evaluation of field forms
|
||||||
if (loadAllExps) {
|
if (loadAllExps) {
|
||||||
@@ -786,5 +774,19 @@ class Kiss {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function isEmpty(expr:Expr) {
|
||||||
|
switch (expr.expr) {
|
||||||
|
case EBlock([]):
|
||||||
|
case EBlock(blockExps):
|
||||||
|
for (exp in blockExps) {
|
||||||
|
if (!isEmpty(exp))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user