mondo: rename resolve_ -> desugar_

This commit is contained in:
Felix Roos
2025-03-22 23:51:23 +01:00
parent 492271d786
commit bca16cdf99
2 changed files with 7 additions and 9 deletions
+6 -9
View File
@@ -102,11 +102,6 @@ export class MondoParser {
}
return this.consume(next);
}
desugar_children(children) {
children = this.resolve_ops(children);
children = this.resolve_pipes(children, (children) => this.resolve_dollars(children));
return children;
}
// Token[] => Token[][], e.g. (x , y z) => [['x'],['y','z']]
split_children(children, split_type) {
const chunks = [];
@@ -145,7 +140,7 @@ export class MondoParser {
}
return children;
}
resolve_ops(children) {
desugar_ops(children) {
while (true) {
let opIndex = children.findIndex((child) => child.type === 'op');
if (opIndex === -1) break;
@@ -174,7 +169,7 @@ export class MondoParser {
}
return children;
}
resolve_pipes(children, next) {
desugar_pipes(children, next) {
let chunks = this.split_children(children, 'pipe');
while (chunks.length > 1) {
let [left, right, ...rest] = chunks;
@@ -191,7 +186,7 @@ export class MondoParser {
}
return next(chunks[0]);
}
resolve_dollars(children) {
desugar_dollars(children) {
let chunks = this.split_children(children, 'dollar');
while (chunks.length > 1) {
let [left, right, ...rest] = chunks;
@@ -221,7 +216,9 @@ export class MondoParser {
// the type we've removed before splitting needs to be added back
children = [{ type: 'plain', value: type }, ...children];
}
return this.desugar_children(children);
children = this.desugar_ops(children);
children = this.desugar_pipes(children, (children) => this.desugar_dollars(children));
return children;
}),
);
return children;
+1
View File
@@ -104,6 +104,7 @@ describe('mondo sugar', () => {
it('should desugar , ()', () => expect(desguar('(s bd, s cp)')).toEqual('(stack (s bd) (s cp))'));
it('should desugar * /', () => expect(desguar('[a b*2 c d/3 e]')).toEqual('(square a (* 2 b) c (/ 3 d) e)'));
it('should desugar []*x', () => expect(desguar('[a [b c]*3]')).toEqual('(square a (* 3 (square b c)))'));
it('should desugar []*<x y>', () => expect(desguar('[a b*<2 3> c]')).toEqual('(square a (* (angle 2 3) b) c)'));
it('should desugar x:y', () => expect(desguar('x:y')).toEqual('(: y x)'));
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))'));