diff --git a/packages/mondo/mondo.mjs b/packages/mondo/mondo.mjs index 1a211e609..ce9e960a1 100644 --- a/packages/mondo/mondo.mjs +++ b/packages/mondo/mondo.mjs @@ -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) { diff --git a/packages/mondo/test/mondo.test.mjs b/packages/mondo/test/mondo.test.mjs index 342a3f9fd..0e859a8b2 100644 --- a/packages/mondo/test/mondo.test.mjs +++ b/packages/mondo/test/mondo.test.mjs @@ -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) ] . speed .8')).toEqual(