Skip to content
Browse files

Blank lines are much more permissible in Blade documents (fixes #81)

Added appropriate tests
  • Loading branch information...
1 parent 00c8af7 commit c06babbec96d9a068feee60dddb5417d4fb2e928 @bminer committed
Showing with 98 additions and 7 deletions.
  1. +3 −0 lib/compiler.js
  2. +10 −3 lib/parser/blade-grammer.pegjs
  3. +64 −4 lib/parser/index.js
  4. +4 −0 test/output/blank_lines.html
  5. +17 −0 test/templates/blank_lines.blade
View
3 lib/compiler.js
@@ -538,6 +538,9 @@ Compiler.prototype._compileNode = function(node) {
this._compileNode(node.children[i]);
this._pushOff("return this;}, " + ns + ");");
break;
+ case 'blank_line':
+ //Ignore these lines
+ break;
default:
var e = new Error("Unknown node type: " + node.type);
e.line = node.line, e.column = node.col;
View
13 lib/parser/blade-grammer.pegjs
@@ -42,6 +42,10 @@ doctype "doctype" =
/
"!!!" whitespace? type:text_until_eol {return type;}
+blank_line "blank line" =
+ whitespace* & (newline)
+ {return {"type": "blank_line"};}
+
/************** Node rules, which also handles indentation **************/
//Note: each node contains line and col for enhanced error reporting (YAY!)
node =
@@ -90,6 +94,8 @@ node =
comment.line = line, comment.col = column;
return comment;
}
+ /
+ blank_line
/* Any node that might have children
Each parent node must contain the following properties:
@@ -124,7 +130,7 @@ parent_node_types =
code
child_node "child node" =
- newline child_indent:indents & {
+ newline+ child_indent:indents & {
return child_indent == currentParentNode._indent + 1;
} child:node
{return child;}
@@ -465,18 +471,19 @@ text_until_eol "some text before the end of the line" =
{return text.join("");}
//Will reset the `indent` global variable
+//Note: Only Linux and Windows line feeds are supported; Old Mac-style "\r" is not a newline
newline "newline" =
"\r" ? "\n" {indent = 0;}
//Will update `indent` global variable and return the # of indents
indents "indents" =
- data: "\t"+ & {
+ tabs: "\t"+ & {
//Predicate accepts \t token if it matches `indentToken`
if(indentToken == undefined)
indentToken = "\t";
return indentToken == "\t";
} {
- return indent = data.length; //Return the indent value
+ return indent = tabs.length; //Return the indent value
}
/
spaces: " "+ & {
View
68 lib/parser/index.js
@@ -40,6 +40,7 @@ module.exports = (function(){
"start": parse_start,
"nodes": parse_nodes,
"doctype": parse_doctype,
+ "blank_line": parse_blank_line,
"node": parse_node,
"parent_node": parse_parent_node,
"parent_node_types": parse_parent_node_types,
@@ -395,6 +396,53 @@ module.exports = (function(){
return result0;
}
+ function parse_blank_line() {
+ var result0, result1;
+ var pos0, pos1, pos2;
+
+ reportFailures++;
+ pos0 = clone(pos);
+ pos1 = clone(pos);
+ result0 = [];
+ result1 = parse_whitespace();
+ while (result1 !== null) {
+ result0.push(result1);
+ result1 = parse_whitespace();
+ }
+ if (result0 !== null) {
+ pos2 = clone(pos);
+ reportFailures++;
+ result1 = parse_newline();
+ reportFailures--;
+ if (result1 !== null) {
+ result1 = "";
+ pos = clone(pos2);
+ } else {
+ result1 = null;
+ }
+ if (result1 !== null) {
+ result0 = [result0, result1];
+ } else {
+ result0 = null;
+ pos = clone(pos1);
+ }
+ } else {
+ result0 = null;
+ pos = clone(pos1);
+ }
+ if (result0 !== null) {
+ result0 = (function(offset, line, column) {return {"type": "blank_line"};})(pos0.offset, pos0.line, pos0.column);
+ }
+ if (result0 === null) {
+ pos = clone(pos0);
+ }
+ reportFailures--;
+ if (reportFailures === 0 && result0 === null) {
+ matchFailed("blank line");
+ }
+ return result0;
+ }
+
function parse_node() {
var result0, result1, result2;
var pos0, pos1;
@@ -516,6 +564,9 @@ module.exports = (function(){
if (result0 === null) {
pos = clone(pos0);
}
+ if (result0 === null) {
+ result0 = parse_blank_line();
+ }
}
}
}
@@ -578,7 +629,16 @@ module.exports = (function(){
reportFailures++;
pos0 = clone(pos);
pos1 = clone(pos);
- result0 = parse_newline();
+ result1 = parse_newline();
+ if (result1 !== null) {
+ result0 = [];
+ while (result1 !== null) {
+ result0.push(result1);
+ result1 = parse_newline();
+ }
+ } else {
+ result0 = null;
+ }
if (result0 !== null) {
result1 = parse_indents();
if (result1 !== null) {
@@ -4488,7 +4548,7 @@ module.exports = (function(){
result0 = null;
}
if (result0 !== null) {
- result1 = (function(offset, line, column, data) {
+ result1 = (function(offset, line, column, tabs) {
//Predicate accepts \t token if it matches `indentToken`
if(indentToken == undefined)
indentToken = "\t";
@@ -4505,8 +4565,8 @@ module.exports = (function(){
pos = clone(pos1);
}
if (result0 !== null) {
- result0 = (function(offset, line, column, data) {
- return indent = data.length; //Return the indent value
+ result0 = (function(offset, line, column, tabs) {
+ return indent = tabs.length; //Return the indent value
})(pos0.offset, pos0.line, pos0.column, result0[0]);
}
if (result0 === null) {
View
4 test/output/blank_lines.html
@@ -0,0 +1,4 @@
+<!DOCTYPE html><html><head></head><body><h1>Hello</h1><h3>This is a test
+of blank lines, which
+
+is super awesome</h3></body></html>
View
17 test/templates/blank_lines.blade
@@ -0,0 +1,17 @@
+!!! 5
+html
+
+ head
+
+ body
+ h1 Hello
+
+
+
+ h3 This is a test
+
+
+ |
+ of blank lines, which
+
+ is super awesome

0 comments on commit c06babb

Please sign in to comment.
Something went wrong with that request. Please try again.