Permalink
Browse files

add stringify

  • Loading branch information...
1 parent 1ae2930 commit fb13885ecf05be54ede7bec4f3a03b28ee90f547 @zaach zaach committed Jul 23, 2011
Showing with 990 additions and 13 deletions.
  1. +1 −1 Makefile
  2. +26 −1 README.md
  3. +7 −2 lib/reflect.js
  4. +624 −0 lib/stringify.js
  5. +3 −2 package.json
  6. +1 −0 scripts/standalone.js
  7. +8 −7 standalone/reflect.js
  8. +3 −0 test/all-tests.js
  9. +317 −0 test/stringify-test.js
View
@@ -8,7 +8,7 @@ move: lib
cp lib/*.js dist/
test: move dist
- node test/reflect-parse.js
+ node test/all-tests.js
standalone: move dist
node scripts/standalone.js | uglifyjs > standalone/reflect.js
View
@@ -3,7 +3,7 @@
Reflect.js is a JavaScript (ES3 compatible) implementation of [Mozilla's Parser API](https://developer.mozilla.org/en/SpiderMonkey/Parser_API). It does not currently support some of Mozilla's extensions, such as generators, list comprehensions, `for each`, E4X, etc. but may eventually support ones that are, or become Harmony proposals.
Builders are also supported.
-Parsing large files can be slow, for reasons [articulated](http://www.andychu.net/ecmascript/RegExp-Enhancements.html) by Andy Chu.
+Parsing really large files can be slow, for reasons [articulated](http://www.andychu.net/ecmascript/RegExp-Enhancements.html) by Andy Chu.
Download
@@ -16,6 +16,31 @@ Reflect.js is available as a CommonJS module for Node.js. Simply install it with
npm install reflect
+Use
+=======
+
+ var Reflect = require('reflect');
+
+ var ast = Reflect.parse("var a = 4 + 7");
+
+ console.log(Reflect.stringify(ast, " "));
+
+Refer to [Mozilla's docs](https://developer.mozilla.org/en/SpiderMonkey/Parser_API) for details on the AST interface.
+
+Builders
+=======
+The optional [builder](https://developer.mozilla.org/en/SpiderMonkey/Parser_API#Builder_objects) parameter to Reflect.parse() makes it possible to construct user-specified data from the parser, rather than the default Node objects.
+
+The reflect.js module exports the [default builder](https://raw.github.com/zaach/reflect.js/master/lib/nodes.js) so you can redefine only the node constructors you care about and leave the rest default.
+
+ var Reflect = require('reflect');
+ var builder = Reflect.builder;
+
+ // redefine callback for variable declarations
+ builder["variableDeclaration"] = function (kind, declarators, loc) { ... };
+
+ var ast = Reflect.parse("var a = 4 + 7", builder);
+
License
=======
MIT X Licensed.
View
@@ -1,6 +1,7 @@
var parser = require("./parser").parser,
- nodes = require("./nodes");
+ nodes = require("./nodes"),
+ stringify = require("./stringify").stringify;
function JSParser (options) {
// Create a parser constructor and an instance
@@ -99,7 +100,11 @@ parser.parse = function (source) {
exports.Reflect = {
parse: function (src, options) {
return new JSParser(options).parse(src);
- }
+ },
+ stringify: stringify
};
exports.parse = exports.Reflect.parse;
+exports.stringify = stringify;
+exports.builder = builder;
+
Oops, something went wrong.

0 comments on commit fb13885

Please sign in to comment.