1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-20 01:57:09 +03:00
mal/ts/step1_read_print.ts
2017-02-25 11:44:45 +09:00

42 lines
740 B
TypeScript

import { readline } from "./node_readline";
import { MalType } from "./types";
import { readStr } from "./reader";
import { prStr } from "./printer";
// READ
function read(str: string): MalType {
return readStr(str);
}
// EVAL
function evalMal(ast: any, _env?: any): any {
// TODO
return ast;
}
// PRINT
function print(exp: MalType): string {
return prStr(exp);
}
function rep(str: string): string {
return print(evalMal(read(str)));
}
while (true) {
const line = readline("user> ");
if (line == null) {
break;
}
if (line === "") {
continue;
}
try {
console.log(rep(line));
} catch (e) {
const err: Error = e;
console.error(err.message);
}
}