Skip to content

Commit

Permalink
fix #312 Update peg dependency?
Browse files Browse the repository at this point in the history
Close #313
  • Loading branch information
marclaval committed Sep 30, 2014
1 parent 089caa1 commit b6e3776
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
62 changes: 31 additions & 31 deletions hsp/compiler/parser/hspblocks.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TemplateBlock "template block"
= start:TemplateStart content:TemplateContent? end:TemplateEnd?
{
start.content=content;
if (end) {start.closed=true;start.endLine=end.line;};
if (end) {start.closed=true;start.endLine=end.line};
return start;
}

Expand All @@ -56,18 +56,18 @@ TemplateStart "template statement"
if (mod) {
mod+=" ";
}
return {type:"invalidtemplate", line:line, column:column, code: d1+p+mod+"template "+name+" "+args.invalidTplArg+d2}
return {type:"invalidtemplate", line:line(), column:column(), code: d1+p+mod+"template "+name+" "+args.invalidTplArg}
} else {
if ((d1 === "<" && d2 !==">")) {
// inconsistant delimiters
return {type:"invalidtemplate", line:line, column:column, code: d1+p+mod+"template "+name+" "+args.invalidTplArg+d2}
return {type:"invalidtemplate", line:line(), column:column(), code: d1+p+mod+"template "+name+" "+args.invalidTplArg}
}

if (args && args.ctl && args.constructor!==Array) {
// this template uses a controller
return {type:"template", name:name, mod:mod, controller:args.ctl, controllerRef: args.ctlref, line:line, column:column}
return {type:"template", name:name, mod:mod, controller:args.ctl, controllerRef: args.ctlref, line:line(), column:column()}
}
return {type:"template", name:name, mod:mod, args:(args==='')? []:args, line:line, column:column}
return {type:"template", name:name, mod:mod, args:(args== null)? []:args, line:line(), column:column()}
}
}

Expand All @@ -85,7 +85,7 @@ InvalidTplArgs

TemplateEnd "template end statement"
= _ "</template" _ ">" _ (EOL / EOF)
{return {type:"/template",line:line,column:column}}
{return {type:"/template",line:line(),column:column()}}

TemplateContent "template content"
= _ blocks:( TplTextBlock
Expand All @@ -104,7 +104,7 @@ TemplateContent "template content"

TplTextBlock "text"
= chars:(TplTextChar)+
{return {type:"text", value:chars.join(''), line:line, column:column}}
{return {type:"text", value:chars.join(''), line:line(), column:column()}}

TplTextChar "text character"
= "\\{" {return "\u007B"} // { = \u007B
Expand All @@ -121,26 +121,26 @@ TplTextChar "text character"

InvalidBlock
= "{" chars:[^{}#]* "}"
{return {type:"invalidblock", code:chars.join(''), line:line, column:column}}
{return {type:"invalidblock", code:chars.join(''), line:line(), column:column()}}

IfBlock "if statement"
= "{" _ "if " _ expr:(IfCondWithBrackets / CoreExpText) _ "}" EOS?
{return {type:"if", condition:expr, line:line, column:column}}
{return {type:"if", condition:expr, line:line(), column:column()}}

IfCondWithBrackets
= "(" expr:CoreExpText ")" {return expr}

ElseIfBlock "elseif statement"
= "{" _ "else " _ "if" _ expr:(IfCondWithBrackets / CoreExpText) _ "}" EOS?
{return {type:"elseif", condition:expr, line:line, column:column}}
{return {type:"elseif", condition:expr, line:line(), column:column()}}

ElseBlock
= "{" _ "else" _ "}" EOS?
{return {type:"else", line:line, column:column}}
{return {type:"else", line:line(), column:column()}}

EndIfBlock
= "{" _ "/if" _ "}" EOS?
{return {type:"endif", line:line, column:column}}
{return {type:"endif", line:line(), column:column()}}

CommentBlock
= _ "\/\/" chars:[^\r\n]* &EOL
Expand All @@ -158,7 +158,7 @@ HTMLCommentChar

ForeachBlock
= "{" _ "foreach " _ args:( ForeachArgs / ("(" _ a:ForeachArgs _ ")") {return a}) _ "}" EOS?
{return {type:"foreach", item:args.item, key:args.key, colref:args.colref, line:line, column:column}}
{return {type:"foreach", item:args.item, key:args.key, colref:args.colref, line:line(), column:column()}}

ForeachArgs
= ForeachArgs1 / ForeachArgs2
Expand All @@ -173,38 +173,38 @@ ForeachArgs2

EndForeachBlock
= "{" _ "/foreach" _ "}"
{return {type:"endforeach", line:line, column:column}}
{return {type:"endforeach", line:line(), column:column()}}

HTMLElement
= "<" !(_ "template") name:HTMLName atts:HTMLElementAttributes? S? end:"/"? ">" EOS?
{return {type:"element", name:name, closed:(end!==""), attributes:atts, line:line, column:column}}
{return {type:"element", name:name, closed:(end!=null), attributes:atts, line:line(), column:column()}}

HTMLElementAttributes
= atts:((S att:(HTMLAttribute)) {return att})*

EndHTMLElement // TODO support comments inside Element
= "</" !(_ "template") name:HTMLName S? ">" EOS?
{return {type:"endelement", name:name, line:line, column:column}}
{return {type:"endelement", name:name, line:line(), column:column()}}

HspComponent
= "<#" ref:JSObjectRef atts:HTMLElementAttributes? S? end:"/"? ">" EOS?
{return {type:"component", ref:ref, closed:(end!==""), attributes:atts, line:line, column:column}}
{return {type:"component", ref:ref, closed:(end!=null), attributes:atts, line:line(), column:column()}}

EndHspComponent
= "</#" ref:JSObjectRef S? ">" EOS?
{return {type:"endcomponent", ref:ref, line:line, column:column}}
{return {type:"endcomponent", ref:ref, line:line(), column:column()}}

HspCptAttribute
= "<@" ref:VarIdentifier atts:HTMLElementAttributes? S? end:"/"? ">" EOS?
{return {type:"cptattribute", name:ref, closed:(end!==""), attributes:atts, line:line, column:column}}
{return {type:"cptattribute", name:ref, closed:(end!=null), attributes:atts, line:line(), column:column()}}

EndHspCptAttribute
= "</@" ref:VarIdentifier S? ">" EOS?
{return {type:"endcptattribute", name:ref, line:line, column:column}}
{return {type:"endcptattribute", name:ref, line:line(), column:column()}}

InvalidHTMLElement
= "<" !(_ "/template" _ ">") code:[^\r\n]* EOL
{return {type:"invalidelement", code:'<'+code.join(''), line:line, column:column}}
{return {type:"invalidelement", code:'<'+code.join(''), line:line(), column:column()}}

HTMLName
= first:[a-z] next:([a-z] / [0-9] / "-")*
Expand All @@ -213,12 +213,12 @@ HTMLName
HTMLAttName
= first:[a-zA-Z#] next:([a-zA-Z] / [0-9] / "-")* endString:(":" end:([a-zA-Z] / [0-9] / "-")+ {return ":" + end.join("")})?
// uppercase chars are considered as error in the parse post-processor
{return first + next.join("") + endString;}
{return first + next.join("") + (endString?endString:"");}

HTMLAttribute
= name:HTMLAttName v:(_ "=" _ "\"" value:HTMLAttributeValue "\"" {return value;})?
{
return {type:"attribute", name:name, value:v, line:line, column:column}
return {type:"attribute", name:name, value:v, line:line(), column:column()}
}

HTMLAttributeValue
Expand All @@ -243,7 +243,7 @@ LogBlock
exprs.push(next[i][2]);
}
}
return {type:"log", exprs:exprs, line:line, column:column};
return {type:"log", exprs:exprs, line:line(), column:column()};
}

LetBlock
Expand All @@ -255,7 +255,7 @@ LetBlock
asn.push(next[i][2]);
}
}
return {type:"let",assignments:asn, line:line, column:column}
return {type:"let",assignments:asn, line:line(), column:column()}
}

CoreExpText
Expand All @@ -268,8 +268,8 @@ CoreExpText
return {
"category": "jsexptext",
"value": c.join(''),
"line": line,
"column": column
"line": line(),
"column": column()
};
}

Expand All @@ -289,9 +289,9 @@ ExpressionTextBlock
= "{" ubflag:":"? __ e:CoreExpText "}"
{
var r={};
r.bound=(ubflag.length==0);
r.line=line;
r.column=column;
r.bound=(ubflag == null);
r.line=line();
r.column=column();
r.type="expression";
r.category="jsexptext";
r.value = e.value;
Expand All @@ -300,7 +300,7 @@ ExpressionTextBlock

InvalidExpressionValue
= !("/template" _) chars:[^}]+
{return {type:"invalidexpression", code:chars.join(''), line:line, column:column}}
{return {type:"invalidexpression", code:chars.join(''), line:line(), column:column()}}

// White spaces
// mandatory padding including line breaks
Expand Down
4 changes: 2 additions & 2 deletions hsp/compiler/treebuilder/syntaxTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,11 @@ var SyntaxTree = klass({

for (var i = 0; i < attributes.length; i++) {
attribute = attributes[i];
var length = attribute.value.length;
var length = attribute.value? attribute.value.length: 0;

if (length === 0) {
// this case arises when the attribute is empty - so let's create an empty text node
if (attribute.value === '') {
if (attribute.value == null) {
// attribute has no value - e.g. autocomplete in an input element
outAttribute = {
name : attribute.name,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"grunt-leading-indent": "~0.1.0",
"grunt-mocha-test": "~0.7.0",
"grunt-browserify": "~2.0.0",
"grunt-peg": "~1.0.0",
"grunt-peg": "~1.5.0",
"grunt-karma": "~0.8.0",
"grunt-jscs-checker": "~0.4.0",
"grunt-markdown": "0.5.0",
Expand Down

0 comments on commit b6e3776

Please sign in to comment.