add special renderer for church booleans.

This commit is contained in:
trans_soup 2023-11-11 18:24:10 +01:00
parent 7979eb2f15
commit 1a6b0b9672
4 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1,16 @@
import { is_same } from "../serialize.mjs";
const T = [0, [0, 2]];
const F = [0, [0, 1]];
export default {
check: expr => {
if (is_same(expr, T)) return true;
if (is_same(expr, F)) return true;
return false;
},
render: (expr, prettify) => {
if (is_same(expr, T)) return "true";
if (is_same(expr, F)) return "false";
},
};

4
src/renderers/main.mjs Normal file
View File

@ -0,0 +1,4 @@
import { add_special_renderer } from "../prettify.mjs";
import church_boolean from "./church_boolean.mjs";
add_special_renderer(church_boolean);

View File

@ -7,6 +7,7 @@ import { transpile } from "./transpile.mjs";
import { reduce } from "./reduce.mjs";
import { prettify } from "./prettify.mjs";
import "./renderers/main.mjs";
import readline from "node:readline";

View File

@ -3,3 +3,7 @@ export function serialize (expr) {
? "(" + expr.map(serialize).join(",") + ")"
: expr;
}
export function is_same (a, b) {
return serialize(a) === serialize(b);
}