Make aliases more flexible
This commit is contained in:
@@ -163,12 +163,12 @@ class Helpers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// alias replacements are processed by the reader
|
// 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!
|
// The alias has to be followed by a terminator to count!
|
||||||
for (terminator in Reader.terminators) {
|
for (terminator in Reader.terminators) {
|
||||||
k.readTable[whenItsThis + terminator] = (s:Stream) -> {
|
k.readTable[whenItsThis + terminator] = (s:Stream) -> {
|
||||||
s.putBackString(terminator);
|
s.putBackString(terminator);
|
||||||
Symbol(makeItThisInstead);
|
makeItThisInstead;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -48,10 +48,10 @@ class Kiss {
|
|||||||
k.convert = readerExpToHaxeExpr.bind(_, k);
|
k.convert = readerExpToHaxeExpr.bind(_, k);
|
||||||
|
|
||||||
// Helpful aliases
|
// Helpful aliases
|
||||||
k.defAlias("print", "Prelude.print");
|
k.defAlias("print", Symbol("Prelude.print"));
|
||||||
k.defAlias("map", "Lambda.map");
|
k.defAlias("map", Symbol("Lambda.map"));
|
||||||
k.defAlias("filter", "Lambda.filter");
|
k.defAlias("filter", Symbol("Lambda.filter"));
|
||||||
k.defAlias("has", "Lambda.has");
|
k.defAlias("has", Symbol("Lambda.has"));
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
stream.dropWhitespace();
|
stream.dropWhitespace();
|
||||||
|
@@ -205,13 +205,7 @@ class Macros {
|
|||||||
whenItsThis;
|
whenItsThis;
|
||||||
default:
|
default:
|
||||||
throw CompileError.fromExp(exps[0], 'first argument to defalias should be a symbol for the alias');
|
throw CompileError.fromExp(exps[0], 'first argument to defalias should be a symbol for the alias');
|
||||||
}, switch (exps[1].def) {
|
}, 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');
|
|
||||||
});
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user