How to convert JavaScript code to a xml representation of the ast?
I am building an XML serializer of JavaScript Abstract Syntax Trees with ANTLR. The generator is quite complete but I would like to know if there are any conventions about some issues such as:
- how handle angle brackets in strings or regular expressions?
- how to translate if-then-else (e.g. will the else node be inside the if one or not)?
More generally: does such a translator already exist? Is there any existing XSD for this XML-based language?
EDIT
I am currently interested in free开发者_如何转开发 tools only.
Parsers which perform code generation from XML and generate XML from code are readily available:
Custom PMD Rules - O'Reilly Media
estools/esvalid: confirm that a SpiderMonkey format AST represents an ECMAScript program
jantimon/handlebars-to-ecmascript: Convert handlebars to an ecmascript AST
estools/estemplate: Proper (AST-based) JavaScript code templating with source maps support.
estools/esrecurse: AST recursive visitor
estools/estraverse: ECMAScript JS AST traversal functions
estools/escope: Escope: ECMAScript scope analyzer
estools/esquery: ECMAScript AST query library.
You ask, "does such a translator exist?". If the question is, "does this exist in ANTLR?" then I suspect you'll find the answer at the ANTLR.org site. My company has exactly such a translator with all the issues resolved; if you'd like to see an output sample as an answer here I'll produce one for you specifically for JavaScript.
Here's a link to an XML output for Java: What would an AST (abstract syntax tree) for an object-oriented programming language look like?
References
Parsers, Part IV: A Java Cross-Reference Tool (pdf)
o:XML Development Tool Chain
Command line rendering | Highcharts
Parser API - Mozilla | MDN
精彩评论