aboutsummaryrefslogtreecommitdiff
path: root/miniMAL/printer.json
diff options
context:
space:
mode:
Diffstat (limited to 'miniMAL/printer.json')
-rw-r--r--miniMAL/printer.json66
1 files changed, 66 insertions, 0 deletions
diff --git a/miniMAL/printer.json b/miniMAL/printer.json
new file mode 100644
index 0000000..7463c78
--- /dev/null
+++ b/miniMAL/printer.json
@@ -0,0 +1,66 @@
+["do",
+
+["def", "pr-str", ["fn", ["exp", "print_readably"],
+ ["if", ["list?", "exp"],
+ ["str",
+ ["`", "("],
+ [".", ["map", ["fn", ["x"], ["pr-str", "x", "print_readably"]], "exp"],
+ ["`", "join"], ["`", " "]],
+ ["`", ")"]],
+ ["if", ["vector?", "exp"],
+ ["str",
+ ["`", "["],
+ [".", ["map", ["fn", ["x"], ["pr-str", "x", "print_readably"]], "exp"],
+ ["`", "join"], ["`", " "]],
+ ["`", "]"]],
+ ["if", ["map?", "exp"],
+ ["str",
+ ["`", "{"],
+ [".", ["map", ["fn", ["k"],
+ ["str", ["pr-str", "k", "print_readably"],
+ ["`", " "],
+ ["pr-str", ["get", "exp", "k"], "print_readably"]]],
+ ["keys", "exp"]],
+ ["`", "join"], ["`", " "]],
+ ["`", "}"]],
+ ["if", ["=", ["`", "[object String]"], ["classOf", "exp"]],
+ ["if", ["=", ["`", "\u029e"], ["get", "exp", 0]],
+ ["str", ["`", ":"], ["slice", "exp", 1]],
+ ["if", "print_readably",
+ ["str", ["`", "\""],
+ [".",
+ [".",
+ [".", "exp",
+ ["`", "replace"], ["RegExp", ["`", "\\\\"], ["`", "g"]], ["`", "\\\\"]],
+ ["`", "replace"], ["RegExp", ["`", "\""], ["`", "g"]], ["`", "\\\""]],
+ ["`", "replace"], ["RegExp", ["`", "\n"], ["`", "g"]], ["`", "\\n"]],
+ ["`", "\""]],
+ "exp"]],
+ ["if", ["=", ["`", "[object Number]"], ["classOf", "exp"]],
+ "exp",
+ ["if", ["=", null, "exp"],
+ ["`", "nil"],
+ ["if", ["=", true, "exp"],
+ ["`", "true"],
+ ["if", ["=", false, "exp"],
+ ["`", "false"],
+ ["if", ["symbol?", "exp"],
+ ["get", "exp", ["`", "val"]],
+ ["if", ["malfunc?", "exp"],
+ ["str", ["`", "(fn* "],
+ ["pr-str", ["get", "exp", ["`", "params"]]],
+ ["`", " "],
+ ["pr-str", ["get", "exp", ["`", "ast"]]],
+ ["`", ")"]],
+ ["if", ["=", ["`", "[object Function]"], ["classOf", "exp"]],
+ ["str", ["`", "#<native function>"]],
+ ["if", ["atom?", "exp"],
+ ["str", ["`", "(atom "], ["get", "exp", ["`", "val"]], ["`", ")"]],
+ ["str", ["`", "#<unknown: "], "exp", ["`", ">"]]]]]]]]]]]]]]]],
+
+["def", "pr-list", ["fn", ["lst", "print_readably", "sep"],
+ [".", ["map", ["fn", ["s"], ["pr-str", "s", "print_readably"]], "lst"],
+ ["`", "join"], "sep"]]],
+
+null
+]