aboutsummaryrefslogtreecommitdiff
path: root/miniMAL/printer.json
blob: 7463c78009e54a64d1c8d4f8329bd0740b5cd9c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
]