Skip to content

Commit

Permalink
move bindingList() definition to Prelude
Browse files Browse the repository at this point in the history
  • Loading branch information
NQNStudios committed Dec 11, 2024
1 parent 8e3bb78 commit 38773bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
13 changes: 1 addition & 12 deletions src/kiss/Helpers.hx
Original file line number Diff line number Diff line change
Expand Up @@ -717,18 +717,7 @@ class Helpers {
}

public static function bindingList(exp:ReaderExp, forThis:String, allowEmpty = false):Array<ReaderExp> {
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<Dynamic>);
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 {
Expand Down
15 changes: 15 additions & 0 deletions src/kiss/Prelude.hx
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,21 @@ class Prelude {
throw 'expected $s to be ${toBeWhat}';
#end
}

public static function bindingList(exp:ReaderExp, forThis:String, allowEmpty = false):Array<ReaderExp> {
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<Dynamic>);
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<Bool> = false, allowMeta:Null<Bool> = false):String {
return switch (s.def) {
Expand Down

0 comments on commit 38773bc

Please sign in to comment.