diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-01-09 12:45:37 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-01-09 12:45:37 -0800 |
commit | 1446dc2c02a73abeeafbb431fea2cabda444a1cb (patch) | |
tree | 2ddca31c61bcc506153b0bf8599a35d53c6e8d10 /js/lib | |
parent | 4b52529eb964fd1e949ae60e2da70ac3a0db6a9c (diff) |
Removed makeBlock. Use new Node directly. Initialize more fields.
Diffstat (limited to 'js/lib')
-rw-r--r-- | js/lib/blocks.js | 18 | ||||
-rw-r--r-- | js/lib/node.js | 8 |
2 files changed, 9 insertions, 17 deletions
diff --git a/js/lib/blocks.js b/js/lib/blocks.js index 8f4776c..aa09b23 100644 --- a/js/lib/blocks.js +++ b/js/lib/blocks.js @@ -56,18 +56,6 @@ var reHrule = /^(?:(?:\* *){3,}|(?:_ *){3,}|(?:- *){3,}) *$/; // These are methods of a DocParser object, defined below. -var makeBlock = function(tag, start_line, start_column) { - "use strict"; - var b = new Node(tag); - b.pos.start = [start_line, start_column]; - b.pos.end = []; // assigned in finalization step - b.open = true; - b.last_line_blank = false; - b.string_content = ""; - b.strings = []; - return b; -}; - // Returns true if parent block can contain child block. var canContain = function(parent_type, child_type) { "use strict"; @@ -148,7 +136,7 @@ var addChild = function(tag, line_number, offset) { } var column_number = offset + 1; // offset 0 = column 1 - var newBlock = makeBlock(tag, line_number, column_number); + var newBlock = new Node(tag, { start: [line_number, column_number], end: [] }); this.tip.appendChild(newBlock); this.tip = newBlock; return newBlock; @@ -645,7 +633,7 @@ var processInlines = function(block) { // The main parsing function. Returns a parsed document AST. var parse = function(input) { "use strict"; - this.doc = makeBlock('Document', 1, 1); + this.doc = new Node('Document', { start: [1, 1], end: [] }); this.tip = this.doc; this.refmap = {}; var lines = input.replace(/\n$/, '').split(/\r\n|\n|\r/); @@ -665,7 +653,7 @@ var parse = function(input) { function DocParser(){ "use strict"; return { - doc: makeBlock('Document', 1, 1), + doc: new Node('Document', { start: [1, 1], end: [] }), tip: this.doc, refmap: {}, inlineParser: new InlineParser(), diff --git a/js/lib/node.js b/js/lib/node.js index f88dff5..befa93f 100644 --- a/js/lib/node.js +++ b/js/lib/node.js @@ -60,14 +60,18 @@ NodeWalker.prototype.next = function(){ return {entering: entering, node: cur}; }; -function Node(nodeType) { +function Node(nodeType, pos) { this.t = nodeType; this.parent = null; this.firstChild = null; this.lastChild = null; this.prev = null; this.next = null; - this.pos = {}; + this.pos = pos || {}; + this.last_line_blank = false; + this.open = true; + this.strings = []; + this.string_content = ""; } Node.prototype.isContainer = function() { |