exprCase match :Typed exps
This commit is contained in:
@@ -1167,6 +1167,13 @@ class Macros {
|
|||||||
default:
|
default:
|
||||||
false;
|
false;
|
||||||
};
|
};
|
||||||
|
case TypedExp(patternTypePath, patternExp):
|
||||||
|
return switch (instance.def) {
|
||||||
|
case TypedExp(typePath, instanceExp) if (typePath == patternTypePath):
|
||||||
|
matchExpr(patternExp, instanceExp);
|
||||||
|
default:
|
||||||
|
false;
|
||||||
|
};
|
||||||
case ListExp(patternExps):
|
case ListExp(patternExps):
|
||||||
switch (instance.def) {
|
switch (instance.def) {
|
||||||
case ListExp(instanceExps) if (patternExps.length == instanceExps.length):
|
case ListExp(instanceExps) if (patternExps.length == instanceExps.length):
|
||||||
|
|||||||
@@ -392,9 +392,10 @@ class Prelude {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function symbolNameValue(s:ReaderExp):String {
|
public static function symbolNameValue(s:ReaderExp, allowTyped = false):String {
|
||||||
return switch (s.def) {
|
return switch (s.def) {
|
||||||
case Symbol(name): name;
|
case Symbol(name): name;
|
||||||
|
case TypedExp(_, innerExp) if (allowTyped): symbolNameValue(innerExp, false);
|
||||||
default: throw 'expected $s to be a plain symbol';
|
default: throw 'expected $s to be a plain symbol';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -402,13 +403,14 @@ class Prelude {
|
|||||||
// ReaderExp helpers for macros:
|
// ReaderExp helpers for macros:
|
||||||
public static function symbol(?name:String):ReaderExpDef {
|
public static function symbol(?name:String):ReaderExpDef {
|
||||||
if (name == null)
|
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);
|
return Symbol(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function symbolName(s:ReaderExp):ReaderExpDef {
|
public static function symbolName(s:ReaderExp, allowTyped = false):ReaderExpDef {
|
||||||
return switch (s.def) {
|
return switch (s.def) {
|
||||||
case Symbol(name): StrExp(name);
|
case Symbol(name): StrExp(name);
|
||||||
|
case TypedExp(_, innerExp) if (allowTyped): symbolName(innerExp, false);
|
||||||
default: throw 'expected $s to be a plain symbol';
|
default: throw 'expected $s to be a plain symbol';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ enum ReaderExpDef {
|
|||||||
StrExp(s:String); // "literal"
|
StrExp(s:String); // "literal"
|
||||||
Symbol(name:String); // s
|
Symbol(name:String); // s
|
||||||
RawHaxe(code:String); // #| haxeCode() |#
|
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]
|
MetaExp(meta:String, exp:ReaderExp); // &meta [exp]
|
||||||
FieldExp(field:String, exp:ReaderExp); // .field [exp]
|
FieldExp(field:String, exp:ReaderExp); // .field [exp]
|
||||||
KeyValueExp(key:ReaderExp, value:ReaderExp); // =>key value
|
KeyValueExp(key:ReaderExp, value:ReaderExp); // =>key value
|
||||||
|
|||||||
Reference in New Issue
Block a user