exprCase match :Typed exps

This commit is contained in:
2021-11-27 18:57:49 -07:00
parent aad68c66ef
commit b08f5e830d
3 changed files with 13 additions and 4 deletions

View File

@@ -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):

View File

@@ -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';
};
}

View File

@@ -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