AST in JSON format

Kevin Curtis kevinc1846 at googlemail.com
Mon Dec 7 03:52:39 PST 2009


No spec as yet - more a speculative prototype.

The patch creates a subdir 'ast-test' in the V8 dir which contain a
range of JS source examples covering the ECMAScript grammar. These
examples (and any other JS scripts) can be parsed to JsonML using the
ast-parse.sh shell script (which calls JSON.AST.Parse()):
./ast-parse.sh ast-test/forin.js

The project is an attempt to use the (already pretty generic) JsonML
output feature offered by the V8 deug shell as a starting point for a
generic standarized JSON AST format. Thus, output from from an
unpatched V8 debug shell can also give a good feel of what the JsonML
looks like. (Note: this output is incomplete - it prints only the node
name for some AST constructs):
./shell_g file.js --print-json-ast

It would be useful to get a feel whether the general idea is a starter
- or non-starter. Maybe it merits a wiki straw man entry.

> more ast-test/forin.js
x = [4,5,6];
for (i in x) print(x[i]);
> ./ast-parse.sh ast-test/forin.js
["Program",
  ["ExprStmt",
    ["Assign",
      {"op":"="},
      ["Id",
        {"name":"x"}
      ],
      ["ArrayLiteral",
        ["Literal",
          {"handle":4}
        ],
        ["Literal",
          {"handle":5}
        ],
        ["Literal",
          {"handle":6}
        ]
      ]
    ]
  ],
  ["ForIn",
    ["Id",
      {"name":"i"}
    ],
    ["Id",
      {"name":"x"}
    ],
    ["ExprStmt",
      ["Call",
        ["Id",
          {"name":"print"}
        ],
        ["Property",
          {"type":"NORMAL"},
          ["Id",
            {"name":"x"}
          ],
          ["Id",
            {"name":"i"}
          ]
        ]
      ]
    ]
  ]
]


> I am eager to see such a proposal. However, on your pages, I could not
> find any documentation, other than small examples, showing what your
> proposed encoding of JS ASTs in JSON is. Are you writing a draft spec?
>


More information about the es-discuss mailing list