use + and - as late / early
+ add some extra error handling
This commit is contained in:
parent
9412bf60bf
commit
10ac7c353c
2 changed files with 16 additions and 3 deletions
|
|
@ -20,8 +20,8 @@ export class MondoParser {
|
||||||
open_curly: /^\{/,
|
open_curly: /^\{/,
|
||||||
close_curly: /^\}/,
|
close_curly: /^\}/,
|
||||||
number: /^-?[0-9]*\.?[0-9]+/, // before pipe!
|
number: /^-?[0-9]*\.?[0-9]+/, // before pipe!
|
||||||
// "+" and "-" might be added here, but then "-" won't work as silence anymore..
|
// TODO: better error handling when "-" is used as rest, e.g "s [- bd]"
|
||||||
op: /^[*/:!@%?]|^\.{2}/, // * / : ! @ % ? ..
|
op: /^[*/:!@%?+-]|^\.{2}/, // * / : ! @ % ? ..
|
||||||
// dollar: /^\$/,
|
// dollar: /^\$/,
|
||||||
pipe: /^#/,
|
pipe: /^#/,
|
||||||
stack: /^[,$]/,
|
stack: /^[,$]/,
|
||||||
|
|
@ -173,6 +173,18 @@ export class MondoParser {
|
||||||
children[opIndex] = op;
|
children[opIndex] = op;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// some careful error handling
|
||||||
|
if (left.type === 'op') {
|
||||||
|
throw new Error(`got 2 ops in a row: "${left.value}${op.value}"`);
|
||||||
|
}
|
||||||
|
if (right.type === 'op') {
|
||||||
|
let err = `got 2 ops in a row: "${op.value}${right.value}"`;
|
||||||
|
if (op.value === '-') {
|
||||||
|
// yes i know this file is not supposed to know about rests x.X
|
||||||
|
err += '. you probably want a rest, which is "_" in mondo!';
|
||||||
|
}
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
const call = { type: 'list', children: [op, right, left] };
|
const call = { type: 'list', children: [op, right, left] };
|
||||||
// insert call while keeping other siblings
|
// insert call while keeping other siblings
|
||||||
children = [...children.slice(0, opIndex - 1), call, ...children.slice(opIndex + 2)];
|
children = [...children.slice(0, opIndex - 1), call, ...children.slice(opIndex + 2)];
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@ let nope = (...args) => args[args.length - 1];
|
||||||
|
|
||||||
let lib = {};
|
let lib = {};
|
||||||
lib['nope'] = nope;
|
lib['nope'] = nope;
|
||||||
lib['-'] = silence;
|
lib['-'] = (a, b) => b.early(a);
|
||||||
|
lib['+'] = (a, b) => b.late(a);
|
||||||
lib['_'] = silence;
|
lib['_'] = silence;
|
||||||
lib['~'] = silence;
|
lib['~'] = silence;
|
||||||
lib.curly = stepcat;
|
lib.curly = stepcat;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue