mondo: support $ tidal style

This commit is contained in:
Felix Roos
2025-03-22 23:28:57 +01:00
parent f71db4aeed
commit 492271d786
2 changed files with 18 additions and 4 deletions
+15 -4
View File
@@ -20,8 +20,9 @@ export class MondoParser {
close_curly: /^\}/,
number: /^-?[0-9]*\.?[0-9]+/, // before pipe!
op: /^[*/:!@%?]|^\.{2}/, // * / : ! @ % ? ..
dollar: /^\$/,
pipe: /^\./,
stack: /^[,$]/,
stack: /^[,]/,
or: /^[|]/,
plain: /^[a-zA-Z0-9-~_^]+/,
};
@@ -103,7 +104,7 @@ export class MondoParser {
}
desugar_children(children) {
children = this.resolve_ops(children);
children = this.resolve_pipes(children);
children = this.resolve_pipes(children, (children) => this.resolve_dollars(children));
return children;
}
// Token[] => Token[][], e.g. (x , y z) => [['x'],['y','z']]
@@ -173,7 +174,7 @@ export class MondoParser {
}
return children;
}
resolve_pipes(children) {
resolve_pipes(children, next) {
let chunks = this.split_children(children, 'pipe');
while (chunks.length > 1) {
let [left, right, ...rest] = chunks;
@@ -184,10 +185,20 @@ export class MondoParser {
chunks = [[...left.slice(0, -1), call, ...right.slice(1)], ...rest]; // jazz (fast 2 hh)
} else {
//s jazz hh.fast 2 => (fast 2 (s jazz hh))
const call = left.length > 1 ? { type: 'list', children: left } : left[0];
const call = left.length > 1 ? { type: 'list', children: next(left) } : left[0];
chunks = [[...right, call], ...rest];
}
}
return next(chunks[0]);
}
resolve_dollars(children) {
let chunks = this.split_children(children, 'dollar');
while (chunks.length > 1) {
let [left, right, ...rest] = chunks;
//fast 2 $ s jazz hh => (fast 2 (s jazz hh))
const call = right.length > 1 ? { type: 'list', children: right } : right[0];
chunks = [[...left, call], ...rest];
}
return chunks[0];
}
parse_pair(open_type, close_type) {
+3
View File
@@ -108,6 +108,9 @@ describe('mondo sugar', () => {
it('should desugar x:y:z', () => expect(desguar('x:y:z')).toEqual('(: z (: y x))'));
it('should desugar x:y*x', () => expect(desguar('bd:0*2')).toEqual('(* 2 (: 0 bd))'));
it('should desugar a..b', () => expect(desguar('0..2')).toEqual('(.. 2 0)'));
it('should desugar x $ y', () => expect(desguar('x $ y')).toEqual('(x y)'));
it('should desugar x $ y z', () => expect(desguar('x $ y z')).toEqual('(x (y z))'));
it('should desugar x $ y . z', () => expect(desguar('x $ y . z')).toEqual('(z (x y))'));
it('should desugar README example', () =>
expect(desguar('s [bd hh*2 cp.(crush 4) <mt ht lt>] . speed .8')).toEqual(