mondo: add | and ?
This commit is contained in:
parent
cf1f4ec35c
commit
6fd89ddee7
2 changed files with 23 additions and 6 deletions
|
|
@ -19,9 +19,10 @@ 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!
|
||||||
op: /^[*/:!@%]|^\.{2}/, // * / : ! @ % ..
|
op: /^[*/:!@%?]|^\.{2}/, // * / : ! @ % ? ..
|
||||||
pipe: /^\./,
|
pipe: /^\./,
|
||||||
stack: /^[,$]/,
|
stack: /^[,$]/,
|
||||||
|
or: /^[|]/,
|
||||||
plain: /^[a-zA-Z0-9-~_^]+/,
|
plain: /^[a-zA-Z0-9-~_^]+/,
|
||||||
};
|
};
|
||||||
// matches next token
|
// matches next token
|
||||||
|
|
@ -125,9 +126,9 @@ export class MondoParser {
|
||||||
chunks.push(children);
|
chunks.push(children);
|
||||||
return chunks;
|
return chunks;
|
||||||
}
|
}
|
||||||
desugar_stack(children, sequence_type) {
|
desugar_split(children, split_type, sequence_type) {
|
||||||
// children is expected to contain square or angle as first item
|
// children is expected to contain square or angle as first item
|
||||||
const chunks = this.split_children(children, 'stack', sequence_type);
|
const chunks = this.split_children(children, split_type, sequence_type);
|
||||||
if (!chunks.length) {
|
if (!chunks.length) {
|
||||||
return this.desugar_children(children);
|
return this.desugar_children(children);
|
||||||
}
|
}
|
||||||
|
|
@ -147,7 +148,7 @@ export class MondoParser {
|
||||||
return { type: 'list', children: chunk };
|
return { type: 'list', children: chunk };
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return [{ type: 'plain', value: 'stack' }, ...args];
|
return [{ type: 'plain', value: split_type }, ...args];
|
||||||
}
|
}
|
||||||
// prevents to get a list, e.g. ((x y)) => (x y)
|
// prevents to get a list, e.g. ((x y)) => (x y)
|
||||||
unwrap_children(children) {
|
unwrap_children(children) {
|
||||||
|
|
@ -241,7 +242,8 @@ export class MondoParser {
|
||||||
}
|
}
|
||||||
desugar(children, type) {
|
desugar(children, type) {
|
||||||
// not really needed but more readable and might be extended in the future
|
// not really needed but more readable and might be extended in the future
|
||||||
children = this.desugar_stack(children, type);
|
children = this.desugar_split(children, 'or', type);
|
||||||
|
children = this.desugar_split(children, 'stack', type);
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
parse_list() {
|
parse_list() {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,16 @@
|
||||||
import { strudelScope, reify, fast, slow, seq, stepcat, extend, expand, pace } from '@strudel/core';
|
import {
|
||||||
|
strudelScope,
|
||||||
|
reify,
|
||||||
|
fast,
|
||||||
|
slow,
|
||||||
|
seq,
|
||||||
|
stepcat,
|
||||||
|
extend,
|
||||||
|
expand,
|
||||||
|
pace,
|
||||||
|
chooseIn,
|
||||||
|
degradeBy,
|
||||||
|
} from '@strudel/core';
|
||||||
import { registerLanguage } from '@strudel/transpiler';
|
import { registerLanguage } from '@strudel/transpiler';
|
||||||
import { MondoRunner } from '../mondo/mondo.mjs';
|
import { MondoRunner } from '../mondo/mondo.mjs';
|
||||||
|
|
||||||
|
|
@ -19,8 +31,11 @@ lib['/'] = slow;
|
||||||
lib['!'] = extend;
|
lib['!'] = extend;
|
||||||
lib['@'] = expand;
|
lib['@'] = expand;
|
||||||
lib['%'] = pace;
|
lib['%'] = pace;
|
||||||
|
lib['?'] = degradeBy; // todo: default 0.5 not working..
|
||||||
lib[':'] = tail;
|
lib[':'] = tail;
|
||||||
lib['..'] = range;
|
lib['..'] = range;
|
||||||
|
lib['or'] = (...children) => chooseIn(...children); // always has structure but is cyclewise.. e.g. "s oh*8.dec[.04 | .5]"
|
||||||
|
//lib['or'] = (...children) => chooseOut(...children); // "s oh*8.dec[.04 | .5]" is better but "dec[.04 | .5].s oh*8" has no struct
|
||||||
|
|
||||||
let runner = new MondoRunner({
|
let runner = new MondoRunner({
|
||||||
call(name, args, scope) {
|
call(name, args, scope) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue