From 7f136dd8983c16285e1c20fa10e829453788745b Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Sat, 3 Mar 2012 18:33:16 +0000 Subject: [PATCH] Get rid of the old WikiTextParseTree class And replace it with a new root Renderer() class --- js/ImageParser.js | 5 ++--- js/JSONParser.js | 5 ++--- js/JavaScriptParser.js | 7 +++---- js/PlainTextParser.js | 5 ++--- js/Renderer.js | 25 +++++++++++++++---------- js/WikiTextParseTree.js | 25 ------------------------- js/WikiTextParser.js | 3 +-- 7 files changed, 25 insertions(+), 50 deletions(-) delete mode 100644 js/WikiTextParseTree.js diff --git a/js/ImageParser.js b/js/ImageParser.js index 0cecd4055..e633ee2c7 100644 --- a/js/ImageParser.js +++ b/js/ImageParser.js @@ -9,8 +9,7 @@ Compiles images into JavaScript functions that render them in HTML /*jslint node: true */ "use strict"; -var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree, - Renderer = require("./Renderer.js").Renderer, +var Renderer = require("./Renderer.js").Renderer, Dependencies = require("./Dependencies.js").Dependencies, utils = require("./Utils.js"); @@ -25,7 +24,7 @@ ImageParser.prototype.parse = function(type,text) { } else { src = "data:" + type + ";base64," + text; } - return new WikiTextParseTree([Renderer.ElementNode("img",{src: src})],new Dependencies(),this.store); + return new Renderer([Renderer.ElementNode("img",{src: src})],new Dependencies(),this.store); }; exports.ImageParser = ImageParser; diff --git a/js/JSONParser.js b/js/JSONParser.js index 95f078fb9..46afa18f8 100644 --- a/js/JSONParser.js +++ b/js/JSONParser.js @@ -9,8 +9,7 @@ Compiles JSON objects into JavaScript functions that render them in HTML and pla /*jslint node: true */ "use strict"; -var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree, - Renderer = require("./Renderer.js").Renderer, +var Renderer = require("./Renderer.js").Renderer, Dependencies = require("./Dependencies.js").Dependencies, utils = require("./Utils.js"); @@ -44,7 +43,7 @@ var JSONParser = function(options) { }; JSONParser.prototype.parse = function(type,text) { - return new WikiTextParseTree([renderObject(JSON.parse(text))],new Dependencies(),this.store); + return new Renderer([renderObject(JSON.parse(text))],new Dependencies(),this.store); }; exports.JSONParser = JSONParser; diff --git a/js/JavaScriptParser.js b/js/JavaScriptParser.js index 5cba72eea..2347f800f 100644 --- a/js/JavaScriptParser.js +++ b/js/JavaScriptParser.js @@ -9,8 +9,7 @@ Parses JavaScript source code into a parse tree using Esprima /*jslint node: true */ "use strict"; -var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree, - Renderer = require("./Renderer.js").Renderer, +var Renderer = require("./Renderer.js").Renderer, Dependencies = require("./Dependencies.js").Dependencies, esprima = require("esprima"); @@ -27,7 +26,7 @@ JavaScriptParser.prototype.parse = function(type,code) { parseTree = esprima.parse(code,{comment: true,tokens: true,range: true}); } catch(ex) { // Return a helpful error if the parse failed - return new WikiTextParseTree([ + return new Renderer([ Renderer.ElementNode("pre",{"class": "javascript-source"},[ Renderer.TextNode(code.substring(0,ex.index)), Renderer.ErrorNode(ex), @@ -95,7 +94,7 @@ JavaScriptParser.prototype.parse = function(type,code) { } renderWhitespace(code.length); // Wrap the whole lot in a `
`
-	return new WikiTextParseTree([
+	return new Renderer([
 			Renderer.ElementNode("pre",{"class": "javascript-source"},result)
 		],new Dependencies(),this.store);
 };
diff --git a/js/PlainTextParser.js b/js/PlainTextParser.js
index acf09d8d6..69040a2e6 100644
--- a/js/PlainTextParser.js
+++ b/js/PlainTextParser.js
@@ -9,8 +9,7 @@ Renders plain text tiddlers
 /*jslint node: true */
 "use strict";
 
-var WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
-    Renderer = require("./Renderer.js").Renderer,
+var Renderer = require("./Renderer.js").Renderer,
     Dependencies = require("./Dependencies.js").Dependencies,
     utils = require("./Utils.js");
 
@@ -19,7 +18,7 @@ var PlainTextParser = function(options) {
 };
 
 PlainTextParser.prototype.parse = function(type,text) {
-	return new WikiTextParseTree([Renderer.ElementNode("pre",{},[Renderer.TextNode(text)])],new Dependencies(),this.store);
+	return new Renderer([Renderer.ElementNode("pre",{},[Renderer.TextNode(text)])],new Dependencies(),this.store);
 };
 
 exports.PlainTextParser = PlainTextParser;
diff --git a/js/Renderer.js b/js/Renderer.js
index 62e18c8c9..3b8c52e39 100644
--- a/js/Renderer.js
+++ b/js/Renderer.js
@@ -14,6 +14,13 @@ var utils = require("./Utils.js"),
 	Dependencies = require("./Dependencies.js").Dependencies,
 	esprima = require("esprima");
 
+// Intialise the renderer object
+var Renderer = function(tree,dependencies,store) {
+	this.tree = tree;
+	this.dependencies = dependencies;
+	this.store = store;
+};
+
 var Node = function(children) {
 	if(this instanceof Node) {
 		this.children = children;
@@ -498,16 +505,14 @@ var SliderNode = function(type,label,tooltip,isOpen,children) {
 	);
 };
 
-var Renderer = {
-	MacroNode: MacroNode,
-	ElementNode: ElementNode,
-	TextNode: TextNode,
-	EntityNode: EntityNode,
-	ErrorNode: ErrorNode,
-	LabelNode: LabelNode,
-	SplitLabelNode: SplitLabelNode,
-	SliderNode: SliderNode
-};
+Renderer.MacroNode = MacroNode;
+Renderer.ElementNode = ElementNode;
+Renderer.TextNode = TextNode;
+Renderer.EntityNode = EntityNode;
+Renderer.ErrorNode = ErrorNode;
+Renderer.LabelNode = LabelNode;
+Renderer.SplitLabelNode = SplitLabelNode;
+Renderer.SliderNode = SliderNode;
 
 exports.Renderer = Renderer;
 
diff --git a/js/WikiTextParseTree.js b/js/WikiTextParseTree.js
deleted file mode 100644
index c07685c87..000000000
--- a/js/WikiTextParseTree.js
+++ /dev/null
@@ -1,25 +0,0 @@
-/*\
-title: js/WikiTextParseTree.js
-
-A container for the parse tree generated by parsing wikitext
-
-\*/
-(function(){
-
-/*jslint node: true */
-"use strict";
-
-var Renderer = require("./Renderer.js").Renderer,
-	ArgParser = require("./ArgParser.js").ArgParser,
-	utils = require("./Utils.js");
-
-// Intialise the parse tree object
-var WikiTextParseTree = function(tree,dependencies,store) {
-	this.tree = tree;
-	this.dependencies = dependencies;
-	this.store = store;
-};
-
-exports.WikiTextParseTree = WikiTextParseTree;
-
-})();
diff --git a/js/WikiTextParser.js b/js/WikiTextParser.js
index b9952ef24..77e471adc 100644
--- a/js/WikiTextParser.js
+++ b/js/WikiTextParser.js
@@ -32,7 +32,6 @@ HTML nodes look like this:
 "use strict";
 
 var WikiTextRules = require("./WikiTextRules.js"),
-	WikiTextParseTree = require("./WikiTextParseTree.js").WikiTextParseTree,
 	Dependencies = require("./Dependencies.js").Dependencies,
 	Renderer = require("./Renderer.js").Renderer,
 	utils = require("./Utils.js"),
@@ -71,7 +70,7 @@ WikiTextParser.prototype.parse = function(type,text) {
 	this.dependencies = new Dependencies();
 	this.output = null;
 	this.subWikify(this.children);
-	var tree = new WikiTextParseTree(this.children,this.dependencies,this.store);
+	var tree = new Renderer(this.children,this.dependencies,this.store);
 	this.source = null;
 	this.children = null;
 	return tree;