Skip to content

Commit 60d123d

Browse files
committed
Merge pull request #309 from smfoote/lines-and-columns
Add lines and columns to dust.pegjs
2 parents 2dc3706 + 2b31725 commit 60d123d

File tree

4 files changed

+49
-42
lines changed

4 files changed

+49
-42
lines changed

lib/compiler.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ dust.optimizers = {
4343
key: noop,
4444
path: noop,
4545
literal: noop,
46-
comment: nullify
46+
comment: nullify,
47+
line: nullify,
48+
col: nullify
4749
};
4850

4951
dust.pragmas = {

lib/parser.js

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
{
2020
"name": "Richard Ragan",
2121
"email": "[email protected]"
22+
},
23+
{
24+
"name": "Steven Foote",
25+
"email": "[email protected]"
2226
}
2327
],
2428
"scripts": {
@@ -32,10 +36,11 @@
3236
"url": "https://github.com/linkedin/dustjs.git"
3337
},
3438
"keywords": ["templates", "views"],
35-
"devDependencies": {
36-
"jasmine-node" : "1.9.x",
37-
"cover" : "0.2.x",
38-
"uglify-js" : "1.3.3"
39+
"devDependencies": {
40+
"jasmine-node" : "1.9.x",
41+
"cover" : "0.2.x",
42+
"uglify-js" : "1.3.3",
43+
"pegjs" : "0.7.0"
3944
},
4045
"license": "MIT",
4146
"engine": {

src/dust.pegjs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ start
55
body is defined as anything that matches with the part 0 or more times
66
---------------------------------------------------------------------------------------------------------------------------------------*/
77
body
8-
= p:part* { return ["body"].concat(p) }
8+
= p:part* { return ["body"].concat(p).concat([['line', line], ['col', column]]) }
99

1010
/*-------------------------------------------------------------------------------------------------------------------------------------
1111
part is defined as anything that matches with comment or section or partial or special or reference or buffer
@@ -19,9 +19,9 @@ part
1919
---------------------------------------------------------------------------------------------------------------------------------------*/
2020
section "section"
2121
= t:sec_tag_start ws* rd b:body e:bodies n:end_tag? &{if( (!n) || (t[1].text !== n.text) ) { throw new Error("Expected end tag for "+t[1].text+" but it was not found. At line : "+line+", column : " + column)} return true;}
22-
{ e.push(["param", ["literal", "block"], b]); t.push(e); return t }
22+
{ e.push(["param", ["literal", "block"], b]); t.push(e); return t.concat([['line', line], ['col', column]]) }
2323
/ t:sec_tag_start ws* "/" rd
24-
{ t.push(["bodies"]); return t }
24+
{ t.push(["bodies"]); return t.concat([['line', line], ['col', column]]) }
2525

2626
/*-------------------------------------------------------------------------------------------------------------------------------------
2727
sec_tag_start is defined as matching an opening brace followed by one of #?^<+@% plus identifier plus context plus param
@@ -65,15 +65,15 @@ bodies "bodies"
6565
---------------------------------------------------------------------------------------------------------------------------------------*/
6666
reference "reference"
6767
= ld n:identifier f:filters rd
68-
{ return ["reference", n, f] }
68+
{ return ["reference", n, f].concat([['line', line], ['col', column]]) }
6969

7070
/*-------------------------------------------------------------------------------------------------------------------------------------
7171
partial is defined as matching a opening brace followed by a > plus anything that matches with key or inline plus
7272
context followed by slash and closing brace
7373
---------------------------------------------------------------------------------------------------------------------------------------*/
7474
partial "partial"
7575
= ld s:(">"/"+") ws* n:(k:key {return ["literal", k]} / inline) c:context p:params ws* "/" rd
76-
{ var key = (s ===">")? "partial" : s; return [key, n, c, p] }
76+
{ var key = (s ===">")? "partial" : s; return [key, n, c, p].concat([['line', line], ['col', column]]) }
7777

7878
/*-------------------------------------------------------------------------------------------------------------------------------------
7979
filters is defined as matching a pipe character followed by anything that matches the key
@@ -87,7 +87,7 @@ filters "filters"
8787
---------------------------------------------------------------------------------------------------------------------------------------*/
8888
special "special"
8989
= ld "~" k:key rd
90-
{ return ["special", k] }
90+
{ return ["special", k].concat([['line', line], ['col', column]]) }
9191

9292
/*-------------------------------------------------------------------------------------------------------------------------------------
9393
identifier is defined as matching a path or key
@@ -110,18 +110,18 @@ integer "integer"
110110
---------------------------------------------------------------------------------------------------------------------------------------*/
111111
path "path"
112112
= k:key? d:(array_part / array)+ {
113-
d = d[0];
113+
d = d[0];
114114
if (k && d) {
115115
d.unshift(k);
116-
return [false, d];
116+
return [false, d].concat([['line', line], ['col', column]]);
117117
}
118-
return [true, d];
118+
return [true, d].concat([['line', line], ['col', column]]);
119119
}
120120
/ "." d:(array_part / array)* {
121121
if (d.length > 0) {
122-
return [true, d[0]];
122+
return [true, d[0]].concat([['line', line], ['col', column]]);
123123
}
124-
return [true, []]
124+
return [true, []].concat([['line', line], ['col', column]]);
125125
}
126126

127127
/*-------------------------------------------------------------------------------------------------------------------------------------
@@ -142,9 +142,9 @@ array_part "array_part"
142142
double quotes plus inline_part followed by the closing double quotes
143143
---------------------------------------------------------------------------------------------------------------------------------------*/
144144
inline "inline"
145-
= '"' '"' { return ["literal", ""] }
146-
/ '"' l:literal '"' { return ["literal", l] }
147-
/ '"' p:inline_part+ '"' { return ["body"].concat(p) }
145+
= '"' '"' { return ["literal", ""].concat([['line', line], ['col', column]]) }
146+
/ '"' l:literal '"' { return ["literal", l].concat([['line', line], ['col', column]]) }
147+
/ '"' p:inline_part+ '"' { return ["body"].concat(p).concat([['line', line], ['col', column]]) }
148148

149149
/*-------------------------------------------------------------------------------------------------------------------------------------
150150
inline_part is defined as matching a special or reference or literal
@@ -154,9 +154,9 @@ inline_part
154154

155155
buffer "buffer"
156156
= e:eol w:ws*
157-
{ return ["format", e, w.join('')] }
157+
{ return ["format", e, w.join('')].concat([['line', line], ['col', column]]) }
158158
/ b:(!tag !comment !eol c:. {return c})+
159-
{ return ["buffer", b.join('')] }
159+
{ return ["buffer", b.join('')].concat([['line', line], ['col', column]]) }
160160

161161
/*-------------------------------------------------------------------------------------------------------------------------------------
162162
literal is defined as matching esc or any character except the double quotes and it cannot be a tag
@@ -170,7 +170,7 @@ esc
170170

171171
comment "comment"
172172
= "{!" c:(!"!}" c:. {return c})* "!}"
173-
{ return ["comment", c.join('')] }
173+
{ return ["comment", c.join('')].concat([['line', line], ['col', column]]) }
174174

175175
/*-------------------------------------------------------------------------------------------------------------------------------------
176176
tag is defined as matching an opening brace plus any of #?^><+%:@/~% plus 0 or more whitespaces plus any character or characters that

0 commit comments

Comments
 (0)