cmark

My personal build of CMark ✏️

Commit
05c60132f4ba80f5d62d99e7d0be27715ade06e5
Parent
340ecdac6e34b37588a0f85e2576ff621d6818d9
Author
John MacFarlane <jgm@berkeley.edu>
Date

Replaced 'pos' with 'sourceloc', making it an array.

This is a more compact representation.

Diffstat

2 files changed, 7 insertions, 8 deletions

Status File Name N° Changes Insertions Deletions
Modified js/lib/blocks.js 9 4 5
Modified js/lib/node.js 6 3 3
diff --git a/js/lib/blocks.js b/js/lib/blocks.js
@@ -136,8 +136,7 @@ var addChild = function(tag, line_number, offset) {
     }
 
     var column_number = offset + 1; // offset 0 = column 1
-    var newBlock = new Node(tag, { start: [line_number, column_number],
-                                   end: [0, 0] });
+    var newBlock = new Node(tag, [[line_number, column_number], [0, 0]]);
     newBlock.strings = [];
     newBlock.string_content = undefined;
     this.tip.appendChild(newBlock);
@@ -483,7 +482,7 @@ var incorporateLine = function(ln, line_number) {
               container.t === 'FencedCode' ||
               (container.t === 'ListItem' &&
                !container.firstChild &&
-               container.pos.start[0] === line_number));
+               container.sourceloc[0][0] === line_number));
 
         var cont = container;
         while (cont.parent) {
@@ -549,7 +548,7 @@ var finalize = function(block, line_number) {
         return 0;
     }
     block.open = false;
-    block.pos.end = [line_number, this.lastLineLength + 1];
+    block.sourceloc[1] = [line_number, this.lastLineLength + 1];
 
     switch (block.t) {
     case 'Paragraph':
@@ -639,7 +638,7 @@ var processInlines = function(block) {
 };
 
 var Document = function() {
-    var doc = new Node('Document', { start: [1, 1], end: [0, 0] });
+    var doc = new Node('Document', [[1, 1], [0, 0]]);
     doc.string_content = undefined;
     doc.strings = [];
     return doc;
diff --git a/js/lib/node.js b/js/lib/node.js
@@ -60,14 +60,14 @@ NodeWalker.prototype.next = function(){
     return {entering: entering, node: cur};
 };
 
-function Node(nodeType, pos) {
+function Node(nodeType, sourceloc) {
     this.t = nodeType;
     this.parent = null;
     this.firstChild = null;
     this.lastChild = null;
     this.prev = null;
     this.next = null;
-    this.pos = pos || {};
+    this.sourceloc = sourceloc;
     this.last_line_blank = false;
     this.open = true;
     this.strings = undefined;
@@ -167,7 +167,7 @@ Node.prototype.toAST = function() {
     var cur;
     var result = { t: this.t };
 
-    var propsToShow = ['t', 'c', 'list_data', 'pos', 'info', 'level'];
+    var propsToShow = ['t', 'c', 'list_data', 'sourceloc', 'info', 'level'];
 
     for (var i = 0; i < propsToShow.length; i++) {
         var prop = propsToShow[i];