parsing pattern matching

This commit is contained in:
Dustin Swan 2026-02-01 18:42:50 -07:00
parent d81318333e
commit 7f94cfe8cd
No known key found for this signature in database
GPG key ID: 30D46587E2100467
4 changed files with 176 additions and 11 deletions

View file

@ -5,11 +5,15 @@ import { Parser } from './parser'
import { prettyPrint } from './ast';
function e(str: string) {
console.log(str);
const tokens = tokenize(str);
console.log(tokens);
const p = new Parser(tokens);
const ast = p.parse();
console.log(ast);
console.log(prettyPrint(ast));
const env: Env = new Map();
console.log(str, tokens, prettyPrint(ast), evaluate(ast, env));
// console.log(evaluate(ast, env));
}
e('add1 = (x \\ x + 1); add1 3');
@ -21,3 +25,6 @@ e('rec = { a = 3, b = 5 }; rec{ a = 10 }');
e('add1 = (x \\ x + 1); 3 > add1');
e('[1, 2] & [3, 4]');
e('"abc" & "def"');
// e('n | 0 \\ 1 | _ \\ 99');
e('m | Some x \\ 1 | None \\ 0');
e('head = list \\ list | [x, _] \\ Some x | [] \\ None; head');