From 3ff1d9a76c5e72a7e607a274c37d5da95a3792aa Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Wed, 4 Jan 2012 18:31:19 +0000 Subject: [PATCH] Cleaned up JavaScript processing I'm slowly trying to make the JavaScript processing and the WikiText processing use the same conventions --- js/App.js | 8 +- js/JavaScriptParseTree.js | 135 +++++++++++++++++++++++++++++++ js/JavaScriptParser.js | 29 +++++++ js/Sandbox.js | 24 ------ js/WikiStore.js | 22 +++--- js/WikiTextCompiler.js | 140 +++------------------------------ js/WikiTextParser.js | 8 +- js/WikiTextRenderer.js | 2 +- tiddlywiki5/tiddlywiki5.recipe | 3 +- 9 files changed, 196 insertions(+), 175 deletions(-) create mode 100644 js/JavaScriptParseTree.js create mode 100644 js/JavaScriptParser.js delete mode 100644 js/Sandbox.js 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