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

literal params relaxed to allow eol #65

Merged
merged 2 commits into from
Jul 2, 2012
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
19 changes: 15 additions & 4 deletions dist/dust-core-0.6.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,16 @@ if (typeof exports !== "undefined") {
}
(function(dust){

/* make a safe version of console if it is not available
* currently supporting:
* _console.log
* */
var _console = (typeof console !== 'undefined')? console: {
log: function(){
/* a noop*/
}
};

function isSelect(context) {
var value = context.current();
return typeof value === "object" && value.isSelect === true;
Expand Down Expand Up @@ -600,7 +610,10 @@ var helpers = {
idx: function(chunk, context, bodies) {
return bodies.block(chunk, context.push(context.stack.index));
},

contextDump: function(chunk, context, bodies) {
_console.log(JSON.stringify(context.stack));
return chunk;
},
"if": function( chunk, context, bodies, params ){
if( params && params.cond ){
var cond = params.cond;
Expand All @@ -626,9 +639,7 @@ var helpers = {
}
// no condition
else {
if( typeof window !== 'undefined' && window.console ){
window.console.log( "No expression given!" );
}
_console.log( "No expression given!" );
}
return chunk;
},
Expand Down
99 changes: 40 additions & 59 deletions dist/dust-full-0.6.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,16 @@ if (typeof exports !== "undefined") {
}
(function(dust){

/* make a safe version of console if it is not available
* currently supporting:
* _console.log
* */
var _console = (typeof console !== 'undefined')? console: {
log: function(){
/* a noop*/
}
};

function isSelect(context) {
var value = context.current();
return typeof value === "object" && value.isSelect === true;
Expand Down Expand Up @@ -600,7 +610,10 @@ var helpers = {
idx: function(chunk, context, bodies) {
return bodies.block(chunk, context.push(context.stack.index));
},

contextDump: function(chunk, context, bodies) {
_console.log(JSON.stringify(context.stack));
return chunk;
},
"if": function( chunk, context, bodies, params ){
if( params && params.cond ){
var cond = params.cond;
Expand All @@ -626,9 +639,7 @@ var helpers = {
}
// no condition
else {
if( typeof window !== 'undefined' && window.console ){
window.console.log( "No expression given!" );
}
_console.log( "No expression given!" );
}
return chunk;
},
Expand Down Expand Up @@ -2867,7 +2878,7 @@ var parser = (function(){
}

function parse_literal() {
var result0, result1, result2, result3;
var result0, result1, result2;
var pos0, pos1, pos2, pos3;

reportFailures++;
Expand All @@ -2885,35 +2896,20 @@ var parser = (function(){
pos = clone(pos3);
}
if (result1 !== null) {
pos3 = clone(pos);
reportFailures++;
result2 = parse_eol();
reportFailures--;
result2 = parse_esc();
if (result2 === null) {
result2 = "";
} else {
result2 = null;
pos = clone(pos3);
}
if (result2 !== null) {
result3 = parse_esc();
if (result3 === null) {
if (/^[^"]/.test(input.charAt(pos.offset))) {
result3 = input.charAt(pos.offset);
advance(pos, 1);
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[^\"]");
}
}
}
if (result3 !== null) {
result1 = [result1, result2, result3];
if (/^[^"]/.test(input.charAt(pos.offset))) {
result2 = input.charAt(pos.offset);
advance(pos, 1);
} else {
result1 = null;
pos = clone(pos2);
result2 = null;
if (reportFailures === 0) {
matchFailed("[^\"]");
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = clone(pos2);
Expand All @@ -2923,7 +2919,7 @@ var parser = (function(){
pos = clone(pos2);
}
if (result1 !== null) {
result1 = (function(offset, line, column, c) {return c})(pos1.offset, pos1.line, pos1.column, result1[2]);
result1 = (function(offset, line, column, c) {return c})(pos1.offset, pos1.line, pos1.column, result1[1]);
}
if (result1 === null) {
pos = clone(pos1);
Expand All @@ -2945,35 +2941,20 @@ var parser = (function(){
pos = clone(pos3);
}
if (result1 !== null) {
pos3 = clone(pos);
reportFailures++;
result2 = parse_eol();
reportFailures--;
result2 = parse_esc();
if (result2 === null) {
result2 = "";
} else {
result2 = null;
pos = clone(pos3);
}
if (result2 !== null) {
result3 = parse_esc();
if (result3 === null) {
if (/^[^"]/.test(input.charAt(pos.offset))) {
result3 = input.charAt(pos.offset);
advance(pos, 1);
} else {
result3 = null;
if (reportFailures === 0) {
matchFailed("[^\"]");
}
}
}
if (result3 !== null) {
result1 = [result1, result2, result3];
if (/^[^"]/.test(input.charAt(pos.offset))) {
result2 = input.charAt(pos.offset);
advance(pos, 1);
} else {
result1 = null;
pos = clone(pos2);
result2 = null;
if (reportFailures === 0) {
matchFailed("[^\"]");
}
}
}
if (result2 !== null) {
result1 = [result1, result2];
} else {
result1 = null;
pos = clone(pos2);
Expand All @@ -2983,7 +2964,7 @@ var parser = (function(){
pos = clone(pos2);
}
if (result1 !== null) {
result1 = (function(offset, line, column, c) {return c})(pos1.offset, pos1.line, pos1.column, result1[2]);
result1 = (function(offset, line, column, c) {return c})(pos1.offset, pos1.line, pos1.column, result1[1]);
}
if (result1 === null) {
pos = clone(pos1);
Expand Down
80 changes: 25 additions & 55 deletions lib/parser.js

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

4 changes: 2 additions & 2 deletions src/dust.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,10 @@ buffer "buffer"
{ return ["buffer", b.join('')] }

/*-------------------------------------------------------------------------------------------------------------------------------------
Match anything that match with esc or any of this characters ^" and doesn't match with tag or eol
Match anything that match with esc or any character but double quotes or tag.
---------------------------------------------------------------------------------------------------------------------------------------*/
literal "literal"
= b:(!tag !eol c:(esc / [^"]) {return c})+
= b:(!tag c:(esc / [^"]) {return c})+
{ return b.join('') }

/*-------------------------------------------------------------------------------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions test/jasmine-test/spec/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,15 @@ var dustExamples = [
context: {},
expected: "",
message: "Should ignore carriage return or tab"
},
{
name: "literal params relaxed to allow eol",
source: ['{#helper name="Dialog" config="{',
'\'name\' : \'index\' }',
' "} {/helper}'].join("\n"),
context: {},
expected: "",
message: "Should ignore carriage return or tab inside literal params"
}
];

Expand Down