Implement evaluateAsync for expressions

This commit is contained in:
Zaid Abdulla committed 2019-06-05 00:17:36 -07:00
1 parent ae3779c484
commit 7e78336141
2 files changed
+183 -111

No files matched your search

+15
View File
@@ -36,6 +36,21 @@ export function map(exp, callback): Expression {
return callback(clone || exp);
}
export async function mapAsync(exp, callback): Promise<Expression> {
if (!Array.isArray(exp)) return callback(exp);
let clone;
for (let i = 1; i < exp.length; ++i) {
const sub = await mapAsync(exp[i], callback);
if (sub !== exp[i]) {
clone = clone || exp.slice();
clone[i] = sub;
}
}
return callback(clone || exp);
}
function binaryLeft(operatorsParser, nextParser): parsimmon.Parser<{}> {
return parsimmon.seqMap(
nextParser,