(load [file])

This commit is contained in:
2020-12-09 19:04:11 -07:00
parent a980f879e7
commit 046798768f

View File

@@ -4,6 +4,7 @@ package kiss;
import haxe.Exception; import haxe.Exception;
import haxe.macro.Context; import haxe.macro.Context;
import haxe.macro.Expr; import haxe.macro.Expr;
import haxe.io.Path;
import kiss.Stream; import kiss.Stream;
import kiss.Reader; import kiss.Reader;
import kiss.FieldForms; import kiss.FieldForms;
@@ -58,6 +59,8 @@ class Kiss {
try { try {
var classFields = Context.getBuildFields(); var classFields = Context.getBuildFields();
var stream = new Stream(kissFile); var stream = new Stream(kissFile);
// (load... ) relative to the original file
var loadingDirectory = Path.directory(kissFile);
if (k == null) if (k == null)
k = defaultKissState(); k = defaultKissState();
@@ -66,6 +69,15 @@ class Kiss {
#if test #if test
Sys.println(nextExp.def.toString()); Sys.println(nextExp.def.toString());
#end #end
switch (nextExp.def) {
// (load... ) is the specialest of forms because it calls build() again and those fields need to be merged
case CallExp({pos: _, def: Symbol("load")}, [{pos: _, def: StrExp(otherKissFile)}]):
var filePath = Path.join([loadingDirectory, otherKissFile]);
var loadedFields = Kiss.build(filePath, k);
for (field in loadedFields) {
classFields.push(field);
}
default:
var field = readerExpToField(nextExp, k); var field = readerExpToField(nextExp, k);
if (field != null) { if (field != null) {
#if test #if test
@@ -78,6 +90,7 @@ class Kiss {
#end #end
classFields.push(field); classFields.push(field);
} }
}
}); });
return classFields; return classFields;
@@ -128,12 +141,6 @@ class Kiss {
specialForms[specialForm](exp, args, k); specialForms[specialForm](exp, args, k);
case CallExp(func, args): case CallExp(func, args):
ECall(convert(func), [for (argExp in args) convert(argExp)]).withMacroPosOf(exp); ECall(convert(func), [for (argExp in args) convert(argExp)]).withMacroPosOf(exp);
/*
// Typed expressions in the wild become casts:
case TypedExp(type, innerExp):
ECast(convert(innerExp), if (type.length > 0) Helpers.parseComplexType(type, exp) else null).withMacroPosOf(wholeExp);
*/
case ListExp(elements): case ListExp(elements):
var isMap = false; var isMap = false;
var arrayDecl = EArrayDecl([ var arrayDecl = EArrayDecl([