From f9dcfab167d3c459bd3c069e1ace7d05d1f7df61 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 21 May 2021 17:16:09 -0600 Subject: [PATCH] (the) can now specify a package and unquote package/type --- src/kiss/SpecialForms.hx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/kiss/SpecialForms.hx b/src/kiss/SpecialForms.hx index f403e9e..bbbda2d 100644 --- a/src/kiss/SpecialForms.hx +++ b/src/kiss/SpecialForms.hx @@ -265,11 +265,22 @@ class SpecialForms { // Type check syntax: map["the"] = (wholeExp:ReaderExp, args:Array, k:KissState) -> { - wholeExp.checkNumArgs(2, 2, '(the [type] [value])'); - ECheckType(k.convert(args[1]), switch (args[0].def) { - case Symbol(type): Helpers.parseComplexType(type, args[0]); - default: throw CompileError.fromExp(args[0], 'first argument to (the... ) should be a valid type'); - }).withMacroPosOf(wholeExp); + wholeExp.checkNumArgs(2, 3, '(the [optional: package] [type] [value])'); + var pkg = ""; + var whichArg = "first"; + if (args.length == 3) { + pkg = switch (args.shift().def) { + case Symbol(pkg): pkg; + default: throw CompileError.fromExp(args[0], '$whichArg argument to (the... ) should be a valid haxe package'); + }; + whichArg = "second"; + } + var type = switch (args[0].def) { + case Symbol(type): type; + default: throw CompileError.fromExp(args[0], '$whichArg argument to (the... ) should be a valid type'); + }; + if (pkg.length > 0) type = pkg + "." + type; + ECheckType(k.convert(args[1]), Helpers.parseComplexType(type, args[0])).withMacroPosOf(wholeExp); }; map["try"] = (wholeExp:ReaderExp, args:Array, k:KissState) -> {