interpreting record update, and > (func application pipe thing). cleaning up main.ts test code

This commit is contained in:
Dustin Swan 2026-02-01 16:46:18 -07:00
parent 59b718619c
commit c44a6858ff
No known key found for this signature in database
GPG key ID: 30D46587E2100467
3 changed files with 53 additions and 42 deletions

View file

@ -1,39 +1,21 @@
import { evaluate } from './interpreter'
// import type { AST } from './ast'
import type { Env } from './env'
import { tokenize } from './lexer'
import { Parser } from './parser'
import { prettyPrint } from './ast';
// const env: Env = new Map();
function e(str: string) {
const tokens = tokenize(str);
const p = new Parser(tokens);
const ast = p.parse();
const env: Env = new Map();
console.log(str, tokens, prettyPrint(ast), evaluate(ast, env));
}
// const res = evaluate(ast, env);
// console.log(res);
const str = `
# This is a comment
double = x \\ x * 2
read_line! : Unit \\ String
`;
console.log(tokenize(str));
// const tokens = tokenize("x");
// const p = new Parser(tokens);
// console.log(p.parse());
// const tokens2 = tokenize("let x = (y) => 5 + y in x(3)");
// const tokens2 = tokenize("let x = 5 in x * 4");
// const tokens2 = tokenize("(x, y) => x + y");
// const tokens2 = tokenize('point { x = 3 }');
// const tokens2 = tokenize('add1 = (x \\ x + 1); add1 3');
// const tokens2 = tokenize('sum = x y \\ x + y; sum 5 3');
// const tokens2 = tokenize('[1, 2, 3]');
// const tokens2 = tokenize('c = 5; { a = 3, b = c }');
const tokens2 = tokenize('rec = { a = 3, b = 5 }; rec.a');
const p2 = new Parser(tokens2);
const ast3 = p2.parse();
console.log(ast3);
console.log(prettyPrint(ast3));
const env3: Env = new Map();
console.log(evaluate(ast3, env3));
e('add1 = (x \\ x + 1); add1 3');
e('sum = x y \\ x + y; sum 5 3');
e('[1, 2, 3]');
e('c = 5; { a = 3, b = c }');
e('rec = { a = 3, b = 5 }; rec.a');
e('rec = { a = 3, b = 5 }; rec{ a = 10 }');
e('add1 = (x \\ x + 1); 3 > add1');