Skip to content

Commit

Permalink
place location provided by peg 0.9 onto the AST
Browse files Browse the repository at this point in the history
We are removing line and col from the AST so this is a breaking change
  • Loading branch information
jimmyhchan authored and sethkinast committed Sep 12, 2016
1 parent 07b73b3 commit 43c0831
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 4 additions & 6 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@
path: noop,
literal: noop,
raw: noop,
comment: nullify,
line: nullify,
col: nullify
comment: nullify
};

compiler.pragmas = {
Expand Down Expand Up @@ -109,7 +107,7 @@
if (res[0] === 'buffer' || res[0] === 'format') {
if (memo) {
memo[0] = (res[0] === 'buffer') ? 'buffer' : memo[0];
memo[1] += res.slice(1, -2).join('');
memo[1] += res.slice(1).join('');
} else {
memo = res;
out.push(res);
Expand Down Expand Up @@ -143,10 +141,10 @@

function format(context, node) {
if(dust.config.whitespace) {
// Format nodes are in the form ['format', eol, whitespace, line, col],
// Format nodes are in the form ['format', eol, whitespace],
// which is unlike other nodes in that there are two pieces of content
// Join eol and whitespace together to normalize the node format
node.splice(1, 2, node.slice(1, -2).join(''));
node.splice(1, 2, node.slice(1).join(''));
return node;
}
return null;
Expand Down
5 changes: 3 additions & 2 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
peg$c40 = { type: "other", description: "identifier" },
peg$c41 = function(p) {
var arr = ["path"].concat(p);
arr.text = p[1].join('.').replace(/,line,\d+,col,\d+/g,'');
arr.text = p[1].join('.');
return arr;
},
peg$c42 = function(k) {
Expand Down Expand Up @@ -2719,7 +2719,8 @@
return parseInt(arr.join(''), 10);
}
function withPosition(arr) {
return arr.concat([['line', location().start.line], ['col', location().start.column]]);
arr.location = location();
return arr;
}


Expand Down
5 changes: 3 additions & 2 deletions src/dust.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
return parseInt(arr.join(''), 10);
}
function withPosition(arr) {
return arr.concat([['line', location().start.line], ['col', location().start.column]]);
arr.location = location();
return arr;
}
}

Expand Down Expand Up @@ -126,7 +127,7 @@ identifier "identifier"
= p:path
{
var arr = ["path"].concat(p);
arr.text = p[1].join('.').replace(/,line,\d+,col,\d+/g,'');
arr.text = p[1].join('.');
return arr;
}
/ k:key
Expand Down

0 comments on commit 43c0831

Please sign in to comment.