From 902012759ae16d9cd4ff29243751c767b63724d9 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 16 Mar 2025 21:24:22 +0100 Subject: [PATCH] fix:support negative numbers --- packages/mondo/mondo.mjs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/mondo/mondo.mjs b/packages/mondo/mondo.mjs index da8c31ecd..5ca3a0f81 100644 --- a/packages/mondo/mondo.mjs +++ b/packages/mondo/mondo.mjs @@ -15,7 +15,7 @@ export class MondoParser { close_cat: /^>/, open_seq: /^\[/, close_seq: /^\]/, - number: /^[0-9]*\.?[0-9]+/, // before pipe! + number: /^-?[0-9]*\.?[0-9]+/, // before pipe! pipe: /^\./, stack: /^,/, op: /^[*/]/, @@ -299,6 +299,13 @@ export class MondoRunner { // console.log(printAst(ast)); return this.call(ast); } + // todo: always use lib.call? + libcall(fn, args, name) { + if (this.lib.call) { + return this.lib.call(fn, args, name); + } + return fn(...args); + } call(ast) { // for a node to be callable, it needs to be a list this.assert(ast.type === 'list', `function call: expected list, got ${ast.type}`); @@ -325,15 +332,12 @@ export class MondoRunner { const callee = ast.children[1].value; const innerFn = this.lib[callee]; this.assert(innerFn, `function call: unknown function name "${callee}"`); - return (pat) => innerFn(pat, args.slice(1)); + return (pat) => this.libcall(innerFn, [pat, ...args.slice(1)], callee); } // look up function in lib const fn = this.lib[name]; this.assert(fn, `function call: unknown function name "${name}"`); - if (this.lib.call) { - return this.lib.call(fn, args, name); - } - return fn(...args); + return this.libcall(fn, args, name); } }