From b08f5e830d3a175d629d53bf160e0769a01a47d8 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 27 Nov 2021 18:57:49 -0700 Subject: [PATCH] exprCase match :Typed exps --- kiss/src/kiss/Macros.hx | 7 +++++++ kiss/src/kiss/Prelude.hx | 8 +++++--- kiss/src/kiss/ReaderExp.hx | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/kiss/src/kiss/Macros.hx b/kiss/src/kiss/Macros.hx index 842a5108..2ae610db 100644 --- a/kiss/src/kiss/Macros.hx +++ b/kiss/src/kiss/Macros.hx @@ -1167,6 +1167,13 @@ class Macros { default: false; }; + case TypedExp(patternTypePath, patternExp): + return switch (instance.def) { + case TypedExp(typePath, instanceExp) if (typePath == patternTypePath): + matchExpr(patternExp, instanceExp); + default: + false; + }; case ListExp(patternExps): switch (instance.def) { case ListExp(instanceExps) if (patternExps.length == instanceExps.length): diff --git a/kiss/src/kiss/Prelude.hx b/kiss/src/kiss/Prelude.hx index ab16ea65..6e49997c 100644 --- a/kiss/src/kiss/Prelude.hx +++ b/kiss/src/kiss/Prelude.hx @@ -392,9 +392,10 @@ class Prelude { return v; } - public static function symbolNameValue(s:ReaderExp):String { + public static function symbolNameValue(s:ReaderExp, allowTyped = false):String { return switch (s.def) { case Symbol(name): name; + case TypedExp(_, innerExp) if (allowTyped): symbolNameValue(innerExp, false); default: throw 'expected $s to be a plain symbol'; }; } @@ -402,13 +403,14 @@ class Prelude { // ReaderExp helpers for macros: public static function symbol(?name:String):ReaderExpDef { if (name == null) - name = '_${Uuid.v4().toShort()}'; + name = '_${Uuid.v4().toShort()}'; // TODO the underscore will make fields defined with gensym names all PRIVATE! return Symbol(name); } - public static function symbolName(s:ReaderExp):ReaderExpDef { + public static function symbolName(s:ReaderExp, allowTyped = false):ReaderExpDef { return switch (s.def) { case Symbol(name): StrExp(name); + case TypedExp(_, innerExp) if (allowTyped): symbolName(innerExp, false); default: throw 'expected $s to be a plain symbol'; }; } diff --git a/kiss/src/kiss/ReaderExp.hx b/kiss/src/kiss/ReaderExp.hx index 5a7a9d1f..19515956 100644 --- a/kiss/src/kiss/ReaderExp.hx +++ b/kiss/src/kiss/ReaderExp.hx @@ -13,7 +13,7 @@ enum ReaderExpDef { StrExp(s:String); // "literal" Symbol(name:String); // s RawHaxe(code:String); // #| haxeCode() |# - TypedExp(path:String, exp:ReaderExp); // :type [exp] + TypedExp(path:String, exp:ReaderExp); // :Type [exp] MetaExp(meta:String, exp:ReaderExp); // &meta [exp] FieldExp(field:String, exp:ReaderExp); // .field [exp] KeyValueExp(key:ReaderExp, value:ReaderExp); // =>key value