From b1b1b84b3ebedddf686295e43f74291d4cae910b Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Thu, 5 Jan 2012 10:00:21 +0000 Subject: [PATCH] Cleaning up the JavaScript parser --- js/JavaScriptParseTree.js | 13 +++++++++---- js/JavaScriptParser.js | 7 +++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/js/JavaScriptParseTree.js b/js/JavaScriptParseTree.js index 3fa65a273..bdb5dd260 100644 --- a/js/JavaScriptParseTree.js +++ b/js/JavaScriptParseTree.js @@ -1,7 +1,12 @@ /*\ title: js/JavaScriptParseTree.js -JavaScript parse tree +This object stores a JavaScript parse tree in the format produced by the pegjs JavaScript parser. + +The parse tree represents the syntactical structure of a JavaScript program, represented as a tree +structure built from JavaScript arrays and objects. The nodes of the tree are objects with a "type" +field that indicates the type of the node (see the function renderNode() for a list of the types). +Depending on the type, other fields provide further details about the node. \*/ (function(){ @@ -12,9 +17,8 @@ JavaScript parse tree var utils = require("./Utils.js"); // Create a new JavaScript tree object -var JavaScriptParseTree = function(tree,processor) { +var JavaScriptParseTree = function(tree) { this.tree = tree; - this.processor = processor; }; // Render the entire JavaScript tree object to JavaScript source code @@ -24,6 +28,7 @@ JavaScriptParseTree.prototype.render = function() { return this.output.join(""); }; +// Render a subtree of the parse tree to an array of fragments of JavaScript source code JavaScriptParseTree.prototype.renderSubTree = function(tree) { for(var t=0; t