Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lines and columns to dust.pegjs #309

Merged
merged 7 commits into from
Jul 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ dust.optimizers = {
key: noop,
path: noop,
literal: noop,
comment: nullify
comment: nullify,
line: nullify,
col: nullify
};

dust.pragmas = {
Expand Down
40 changes: 20 additions & 20 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
{
"name": "Richard Ragan",
"email": "rragan@ebay.com"
},
{
"name": "Steven Foote",
"email": "sfoote@linkedin.com"
}
],
"scripts": {
Expand All @@ -32,10 +36,11 @@
"url": "https://github.com/linkedin/dustjs.git"
},
"keywords": ["templates", "views"],
"devDependencies": {
"jasmine-node" : "1.9.x",
"cover" : "0.2.x",
"uglify-js" : "1.3.3"
"devDependencies": {
"jasmine-node" : "1.9.x",
"cover" : "0.2.x",
"uglify-js" : "1.3.3",
"pegjs" : "0.7.0"
},
"license": "MIT",
"engine": {
Expand Down
34 changes: 17 additions & 17 deletions src/dust.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ start
body is defined as anything that matches with the part 0 or more times
---------------------------------------------------------------------------------------------------------------------------------------*/
body
= p:part* { return ["body"].concat(p) }
= p:part* { return ["body"].concat(p).concat([['line', line], ['col', column]]) }

/*-------------------------------------------------------------------------------------------------------------------------------------
part is defined as anything that matches with comment or section or partial or special or reference or buffer
Expand All @@ -19,9 +19,9 @@ part
---------------------------------------------------------------------------------------------------------------------------------------*/
section "section"
= 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;}
{ e.push(["param", ["literal", "block"], b]); t.push(e); return t }
{ e.push(["param", ["literal", "block"], b]); t.push(e); return t.concat([['line', line], ['col', column]]) }
/ t:sec_tag_start ws* "/" rd
{ t.push(["bodies"]); return t }
{ t.push(["bodies"]); return t.concat([['line', line], ['col', column]]) }

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

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

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

/*-------------------------------------------------------------------------------------------------------------------------------------
identifier is defined as matching a path or key
Expand All @@ -110,18 +110,18 @@ integer "integer"
---------------------------------------------------------------------------------------------------------------------------------------*/
path "path"
= k:key? d:(array_part / array)+ {
d = d[0];
d = d[0];
if (k && d) {
d.unshift(k);
return [false, d];
return [false, d].concat([['line', line], ['col', column]]);
}
return [true, d];
return [true, d].concat([['line', line], ['col', column]]);
}
/ "." d:(array_part / array)* {
if (d.length > 0) {
return [true, d[0]];
return [true, d[0]].concat([['line', line], ['col', column]]);
}
return [true, []]
return [true, []].concat([['line', line], ['col', column]]);
}

/*-------------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -142,9 +142,9 @@ array_part "array_part"
double quotes plus inline_part followed by the closing double quotes
---------------------------------------------------------------------------------------------------------------------------------------*/
inline "inline"
= '"' '"' { return ["literal", ""] }
/ '"' l:literal '"' { return ["literal", l] }
/ '"' p:inline_part+ '"' { return ["body"].concat(p) }
= '"' '"' { return ["literal", ""].concat([['line', line], ['col', column]]) }
/ '"' l:literal '"' { return ["literal", l].concat([['line', line], ['col', column]]) }
/ '"' p:inline_part+ '"' { return ["body"].concat(p).concat([['line', line], ['col', column]]) }

/*-------------------------------------------------------------------------------------------------------------------------------------
inline_part is defined as matching a special or reference or literal
Expand All @@ -154,9 +154,9 @@ inline_part

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

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

comment "comment"
= "{!" c:(!"!}" c:. {return c})* "!}"
{ return ["comment", c.join('')] }
{ return ["comment", c.join('')].concat([['line', line], ['col', column]]) }

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