fix:support negative numbers
This commit is contained in:
parent
ea61627963
commit
902012759a
1 changed files with 10 additions and 6 deletions
|
|
@ -15,7 +15,7 @@ export class MondoParser {
|
||||||
close_cat: /^>/,
|
close_cat: /^>/,
|
||||||
open_seq: /^\[/,
|
open_seq: /^\[/,
|
||||||
close_seq: /^\]/,
|
close_seq: /^\]/,
|
||||||
number: /^[0-9]*\.?[0-9]+/, // before pipe!
|
number: /^-?[0-9]*\.?[0-9]+/, // before pipe!
|
||||||
pipe: /^\./,
|
pipe: /^\./,
|
||||||
stack: /^,/,
|
stack: /^,/,
|
||||||
op: /^[*/]/,
|
op: /^[*/]/,
|
||||||
|
|
@ -299,6 +299,13 @@ export class MondoRunner {
|
||||||
// console.log(printAst(ast));
|
// console.log(printAst(ast));
|
||||||
return this.call(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) {
|
call(ast) {
|
||||||
// for a node to be callable, it needs to be a list
|
// for a node to be callable, it needs to be a list
|
||||||
this.assert(ast.type === 'list', `function call: expected list, got ${ast.type}`);
|
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 callee = ast.children[1].value;
|
||||||
const innerFn = this.lib[callee];
|
const innerFn = this.lib[callee];
|
||||||
this.assert(innerFn, `function call: unknown function name "${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
|
// look up function in lib
|
||||||
const fn = this.lib[name];
|
const fn = this.lib[name];
|
||||||
this.assert(fn, `function call: unknown function name "${name}"`);
|
this.assert(fn, `function call: unknown function name "${name}"`);
|
||||||
if (this.lib.call) {
|
return this.libcall(fn, args, name);
|
||||||
return this.lib.call(fn, args, name);
|
|
||||||
}
|
|
||||||
return fn(...args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue