Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty-printing --print ast/js-ast #99

Open
xkxx opened this issue May 8, 2014 · 0 comments
Open

Pretty-printing --print ast/js-ast #99

xkxx opened this issue May 8, 2014 · 0 comments

Comments

@xkxx
Copy link
Contributor

xkxx commented May 8, 2014

A minor thing I found previously: if you use pr-str instead of JSON.stringify to process the debug output, it looks much nicer:

> echo "(print x)" | ./bin/wisp.js --compile --print ast
[{"op" "invoke",
    "callee" {"start" {"line" 0,
                       "column" 0},
              "end" {"line" 0,
                     "column" 9},
              "op" "member-expression",
              "computed" false,
              "form" (aget console (quote log)),
              "target" {"start" {"line" 0,
                                 "column" 0},
                        "end" {"line" 0,
                               "column" 8},
                        "op" "var",
                        "type" "identifier",
                        "form" console,
                        "binding" {"op" "unresolved-binding",
                                   "type" "unresolved-binding",
                                   "identifier" {"type" "identifier",
                                                 "form" console},
                                   "start" {"line" 0,
                                            "column" 0},
                                   "end" {"line" 0,
                                          "column" 8}}},
              "property" {"start" {"line" 0,
                                   "column" 8},
                          "end" {"line" 0,
                                 "column" 9},
                          "op" "var",
                          "type" "identifier",
                          "form" log,
                          "binding" nil}},
    "params" [{"start" {"line" 0,
                        "column" 7},
               "end" {"line" 0,
                      "column" 8},
               "op" "var",
               "type" "identifier",
               "form" x,
               "binding" {"op" "unresolved-binding",
                          "type" "unresolved-binding",
                          "identifier" {"type" "identifier",
                                        "form" x},
                          "start" {"line" 0,
                                   "column" 7},
                          "end" {"line" 0,
                                 "column" 8}}}],
    "form" (console.log x)}]

vs.

> echo "(print x)" | ./bin/wisp.js --compile --print ast
[
  {
    "op": "invoke",
    "callee": {
      "start": {
        "line": 0,
        "column": 0
      },
      "end": {
        "line": 0,
        "column": 9
      },
      "op": "member-expression",
      "computed": false,
      "form": {
        "head": {
          "name": "aget"
        },
        "tail": {
          "head": {
            "name": "console"
          },
          "tail": {
            "head": {
              "head": {
                "name": "quote"
              },
              "tail": {
                "head": {
                  "name": "log"
                },
                "tail": {},
                "length": 1
              },
              "length": 2
            },
            "tail": {},
            "length": 1
          },
          "length": 2
        },
        "length": 3
      },
      "target": {
        "start": {
          "line": 0,
          "column": 0
        },
        "end": {
          "line": 0,
          "column": 8
        },
        "op": "var",
        "type": "identifier",
        "form": {
          "name": "console"
        },
        "binding": {
          "op": "unresolved-binding",
          "type": "unresolved-binding",
          "identifier": {
            "type": "identifier",
            "form": {
              "name": "console"
            }
          },
          "start": {
            "line": 0,
            "column": 0
          },
          "end": {
            "line": 0,
            "column": 8
          }
        }
      },
      "property": {
        "start": {
          "line": 0,
          "column": 8
        },
        "end": {
          "line": 0,
          "column": 9
        },
        "op": "var",
        "type": "identifier",
        "form": {
          "name": "log"
        }
      }
    },
    "params": [
      {
        "start": {
          "line": 0,
          "column": 7
        },
        "end": {
          "line": 0,
          "column": 8
        },
        "op": "var",
        "type": "identifier",
        "form": {
          "name": "x"
        },
        "binding": {
          "op": "unresolved-binding",
          "type": "unresolved-binding",
          "identifier": {
            "type": "identifier",
            "form": {
              "name": "x"
            }
          },
          "start": {
            "line": 0,
            "column": 7
          },
          "end": {
            "line": 0,
            "column": 8
          }
        }
      }
    ],
    "form": {
      "head": {
        "name": "console.log"
      },
      "tail": {
        "head": {
          "name": "x"
        },
        "tail": {},
        "length": 1
      },
      "length": 2
    }
  }
]

Coffeescript does something similar:

> coffee -cep -n "print x"
Block
  Call
    Value "print"
    Value "x"

I did talk about this in my last pull request, but that thread was too convoluted as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant