From 4e856bc4a7c7238bcb32636d03a84794b0fd534c Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 17 Nov 2021 17:33:29 -0700 Subject: [PATCH] EmbeddedScript and AsyncEmbeddedScript use _try() when building --- kiss/src/kiss/AsyncEmbeddedScript.hx | 29 +++++++++++++++------------- kiss/src/kiss/EmbeddedScript.hx | 29 +++++++++++++++------------- kiss/src/kiss/Kiss.hx | 2 +- 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/kiss/src/kiss/AsyncEmbeddedScript.hx b/kiss/src/kiss/AsyncEmbeddedScript.hx index 0def7434..5aa2352b 100644 --- a/kiss/src/kiss/AsyncEmbeddedScript.hx +++ b/kiss/src/kiss/AsyncEmbeddedScript.hx @@ -61,22 +61,25 @@ class AsyncEmbeddedScript { scriptFile = Path.join([loadingDirectory, scriptFile]); k.fieldList = []; - Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> { - var exprString = Reader.toString(nextExp.def); - var expr = Kiss.readerExpToHaxeExpr(nextExp, k); + Kiss._try(() -> { + Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> { + var exprString = Reader.toString(nextExp.def); + var expr = Kiss.readerExpToHaxeExpr(nextExp, k); - #if debug - expr = macro { trace($v{exprString}); $expr; }; - #end + #if debug + expr = macro { trace($v{exprString}); $expr; }; + #end - if (expr != null) { - commandList.push(macro function(self, cc) { - $expr; - }); - } + if (expr != null) { + commandList.push(macro function(self, cc) { + $expr; + }); + } - // This return is essential for type unification of concat() and push() above... ugh. - return; + // This return is essential for type unification of concat() and push() above... ugh. + return; + }); + null; }); classFields = classFields.concat(k.fieldList); diff --git a/kiss/src/kiss/EmbeddedScript.hx b/kiss/src/kiss/EmbeddedScript.hx index 1953a223..83d49b95 100644 --- a/kiss/src/kiss/EmbeddedScript.hx +++ b/kiss/src/kiss/EmbeddedScript.hx @@ -62,21 +62,24 @@ class EmbeddedScript { classFields = classFields.concat(Kiss.build(dslFile, k)); scriptFile = Path.join([loadingDirectory, scriptFile]); - Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> { - var expr = Kiss.readerExpToHaxeExpr(nextExp, k); + Kiss._try(() -> { + Reader.readAndProcess(Stream.fromFile(scriptFile), k, (nextExp) -> { + var expr = Kiss.readerExpToHaxeExpr(nextExp, k); - if (expr != null) { - commandList.push(macro function(self) { - $expr; - }); - } + if (expr != null) { + commandList.push(macro function(self) { + $expr; + }); + } - // This return is essential for type unification of concat() and push() above... ugh. - return; - // TODO also allow label setting and multiple commands coming from the same expr? - // Multiple things could come from the same expr by returning begin, or a call to a function that does more stuff - // i.e. knot declarations need to end the previous knot, and BELOW that set a label for the new one, then increment the read count - // TODO test await + // This return is essential for type unification of concat() and push() above... ugh. + return; + // TODO also allow label setting and multiple commands coming from the same expr? + // Multiple things could come from the same expr by returning begin, or a call to a function that does more stuff + // i.e. knot declarations need to end the previous knot, and BELOW that set a label for the new one, then increment the read count + // TODO test await + }); + null; }); classFields.push({ diff --git a/kiss/src/kiss/Kiss.hx b/kiss/src/kiss/Kiss.hx index 8fc9d548..f9103940 100644 --- a/kiss/src/kiss/Kiss.hx +++ b/kiss/src/kiss/Kiss.hx @@ -121,7 +121,7 @@ class Kiss { return k; } - static function _try(operation:() -> T):Null { + public static function _try(operation:() -> T):Null { #if !macrotest try { #end