Skip to content

Commit ea5ddf2

Browse files
committed
feat: support assignment expressions in solutions
1 parent f10367e commit ea5ddf2

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

src/evaluator/index.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,27 @@ export function evaluate(ctx: Context, node: Node, solution: Solution): number {
125125
`invalid operation: '${node.left!.value}' is a constant`
126126
);
127127
}
128-
result = evaluate(ctx, node.right!, solution);
129-
ctx.variables.set(node.left!.value, result);
128+
129+
// build solution like binary ops
130+
131+
let partial = `${node.left!.value} ${node.value} `
132+
133+
// compute node.right
134+
right = evaluate(ctx, node.right!, solution);
135+
136+
// build node.right solution
137+
const trackRight =
138+
node.right?.type === NODE.BINARY ||
139+
node.right?.type === NODE.CALL;
140+
if (trackRight) solution.advance();
141+
partial += `${trackRight ? '#' + solution.id : right}`;
142+
143+
solution.push(partial);
144+
145+
result = right
146+
ctx.variables.set(node.left!.value, right);
147+
148+
solution.push(result);
130149
break;
131150
}
132151

0 commit comments

Comments
 (0)