diff --git a/js/App.js b/js/App.js index d9372e285..066bc2aad 100644 --- a/js/App.js +++ b/js/App.js @@ -14,7 +14,7 @@ var WikiStore = require("./WikiStore.js").WikiStore, tiddlerInput = require("./TiddlerInput.js"), tiddlerOutput = require("./TiddlerOutput.js"), WikiTextProcessor = require("./WikiTextProcessor.js").WikiTextProcessor, - Sandbox = require("./Sandbox.js").Sandbox, + JavaScriptParser = require("./JavaScriptParser.js").JavaScriptParser, Navigators = require("./Navigators.js").Navigators, StoryNavigator = require("./StoryNavigator.js").StoryNavigator; @@ -73,11 +73,11 @@ var App = function() { this.store.addTiddler(new Tiddler(tiddlers[t])); } } - // Set up the sandbox for JavaScript parsing + // Set up the JavaScript parser if(this.isBrowser) { - this.store.sandbox = new Sandbox(this.store.getTiddlerText("javascript.pegjs")); + this.store.jsParser = new JavaScriptParser(this.store.getTiddlerText("javascript.pegjs")); } else { - this.store.sandbox = new Sandbox(require("fs").readFileSync("parsers/javascript.pegjs","utf8")); + this.store.jsParser = new JavaScriptParser(require("fs").readFileSync("parsers/javascript.pegjs","utf8")); } // Hack to install standard macros this.store.installMacros(); diff --git a/js/JavaScriptParseTree.js b/js/JavaScriptParseTree.js new file mode 100644 index 000000000..3fa65a273 --- /dev/null +++ b/js/JavaScriptParseTree.js @@ -0,0 +1,135 @@ +/*\ +title: js/JavaScriptParseTree.js + +JavaScript parse tree + +\*/ +(function(){ + +/*jslint node: true */ +"use strict"; + +var utils = require("./Utils.js"); + +// Create a new JavaScript tree object +var JavaScriptParseTree = function(tree,processor) { + this.tree = tree; + this.processor = processor; +}; + +// Render the entire JavaScript tree object to JavaScript source code +JavaScriptParseTree.prototype.render = function() { + this.output = []; + this.renderSubTree(this.tree); + return this.output.join(""); +}; + +JavaScriptParseTree.prototype.renderSubTree = function(tree) { + for(var t=0; t