From 38773bc70050fdd416f40436bda6382e0943f7e5 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 11 Dec 2024 11:07:02 -0600 Subject: [PATCH] move bindingList() definition to Prelude --- src/kiss/Helpers.hx | 13 +------------ src/kiss/Prelude.hx | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/kiss/Helpers.hx b/src/kiss/Helpers.hx index 70c2ef3..cecaa8f 100644 --- a/src/kiss/Helpers.hx +++ b/src/kiss/Helpers.hx @@ -717,18 +717,7 @@ class Helpers { } public static function bindingList(exp:ReaderExp, forThis:String, allowEmpty = false):Array { - return switch (exp.def) { - // At macro-time, a list of exps could be passed instead of a ListExp. Handle - // that tricky case: - case null if (Std.isOfType(exp, Array)): - var expList = cast(exp, Array); - var expDynamic:Dynamic = exp; - bindingList({pos:expList[0].pos, def: ListExp(expDynamic)}, forThis, allowEmpty); - case ListExp(bindingExps) if ((allowEmpty || bindingExps.length > 0) && bindingExps.length % 2 == 0): - bindingExps; - default: - throw KissError.fromExp(exp, '$forThis bindings should be a list or list expression with an even number of sub expressions (at least 2)'); - }; + return Prelude.bindingList(exp, forThis, allowEmpty); } public static function compileTimeResolveToString(description:String, description2:String, exp:ReaderExp, k:KissState):String { diff --git a/src/kiss/Prelude.hx b/src/kiss/Prelude.hx index c8e8ce4..510698f 100644 --- a/src/kiss/Prelude.hx +++ b/src/kiss/Prelude.hx @@ -538,6 +538,21 @@ class Prelude { throw 'expected $s to be ${toBeWhat}'; #end } + + public static function bindingList(exp:ReaderExp, forThis:String, allowEmpty = false):Array { + return switch (exp.def) { + // At macro-time, a list of exps could be passed instead of a ListExp. Handle + // that tricky case: + case null if (Std.isOfType(exp, Array)): + var expList = cast(exp, Array); + var expDynamic:Dynamic = exp; + bindingList({pos:expList[0].pos, def: ListExp(expDynamic)}, forThis, allowEmpty); + case ListExp(bindingExps) if ((allowEmpty || bindingExps.length > 0) && bindingExps.length % 2 == 0): + bindingExps; + default: + throw KissError.fromExp(exp, '$forThis bindings should be a list or list expression with an even number of sub expressions (at least 2)'); + }; + } public static function symbolNameValue(s:ReaderExp, allowTyped:Null = false, allowMeta:Null = false):String { return switch (s.def) {