symbolName and symbolNameValue can parse meta exps now

This commit is contained in:
2022-07-27 17:35:48 +00:00
parent b60e60a8ed
commit 7f2db977de

View File

@@ -453,11 +453,12 @@ class Prelude {
return v; return v;
} }
public static function symbolNameValue(s:ReaderExp, allowTyped = false):String { public static function symbolNameValue(s:ReaderExp, allowTyped = false, allowMeta = 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); case TypedExp(_, innerExp) if (allowTyped): symbolNameValue(innerExp, false); // Meta must always precede type annotation
default: throw 'expected $s to be a plain symbol'; case MetaExp(_, innerExp) if (allowMeta): symbolNameValue(innerExp, allowTyped, false); // TODO will more than one meta on the same expression be necessary?
default: throw 'expected $s to be a plain symbol'; // TODO convert s def to print & modify this message to reflect allowTyped and allowMeta parameters
}; };
} }
@@ -472,11 +473,13 @@ class Prelude {
return Symbol(name); return Symbol(name);
} }
public static function symbolName(s:ReaderExp, allowTyped = false):ReaderExpDef { // TODO make this behavior DRY with symbolNameValue
public static function symbolName(s:ReaderExp, allowTyped = false, allowMeta = 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); case TypedExp(_, innerExp) if (allowTyped): symbolName(innerExp, false); // Meta must always precede type annotation
default: throw 'expected $s to be a plain symbol'; case MetaExp(_, innerExp) if (allowMeta): symbolName(innerExp, allowTyped, false); // TODO will more than one meta on the same expression be necessary?
default: throw 'expected $s to be a plain symbol'; // TODO convert s def to print & modify this message to reflect allowTyped and allowMeta parameters;
}; };
} }