Make aliases more flexible

This commit is contained in:
2020-12-02 14:19:15 -07:00
parent 4d2d18d797
commit ff4c7a34df
3 changed files with 7 additions and 13 deletions

View File

@@ -163,12 +163,12 @@ class Helpers {
}
// alias replacements are processed by the reader
public static function defAlias(k:KissState, whenItsThis:String, makeItThisInstead:String) {
public static function defAlias(k:KissState, whenItsThis:String, makeItThisInstead:ReaderExpDef) {
// The alias has to be followed by a terminator to count!
for (terminator in Reader.terminators) {
k.readTable[whenItsThis + terminator] = (s:Stream) -> {
s.putBackString(terminator);
Symbol(makeItThisInstead);
makeItThisInstead;
}
}
}

View File

@@ -48,10 +48,10 @@ class Kiss {
k.convert = readerExpToHaxeExpr.bind(_, k);
// Helpful aliases
k.defAlias("print", "Prelude.print");
k.defAlias("map", "Lambda.map");
k.defAlias("filter", "Lambda.filter");
k.defAlias("has", "Lambda.has");
k.defAlias("print", Symbol("Prelude.print"));
k.defAlias("map", Symbol("Lambda.map"));
k.defAlias("filter", Symbol("Lambda.filter"));
k.defAlias("has", Symbol("Lambda.has"));
while (true) {
stream.dropWhitespace();

View File

@@ -205,13 +205,7 @@ class Macros {
whenItsThis;
default:
throw CompileError.fromExp(exps[0], 'first argument to defalias should be a symbol for the alias');
}, switch (exps[1].def) {
case Symbol(makeItThis):
makeItThis;
default:
throw CompileError.fromExp(exps[1], 'second argument to defalias should be a symbol for what the alias becomes');
});
}, exps[1].def);
return null;
};