Skip to content

Commit

Permalink
Merge 23e21f5 into fcab2c5
Browse files Browse the repository at this point in the history
  • Loading branch information
olaf-k committed Sep 29, 2014
2 parents fcab2c5 + 23e21f5 commit 0d72458
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
34 changes: 23 additions & 11 deletions hsp/compiler/parser/hspblocks.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -216,23 +216,35 @@ HTMLAttName
{return first + next.join("") + endString;}

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

HTMLAttributeValue
= (HTMLAttributeText / ExpressionTextBlock)*

HTMLAttributeText
= chars:HTMLAttributeChar+
HTMLAttributeQuoted
= '"' value:(HTMLAttributeTextDoubleQuoted / ExpressionTextBlock)* '"'
{return value;}
/ "'" value:(HTMLAttributeTextSingleQuoted / ExpressionTextBlock)* "'"
{return value;}

HTMLAttributeTextDoubleQuoted
= chars:(
"\\{" {return "\u007B"} // { = \u007B
/ "\\\"" {return "\""}
/ EOL {return "\\n"}
/ [^{\"]
)+
{return {type:"text", value:chars.join('')}}

HTMLAttributeChar // TODO look at W3C specs
= "\\{" {return "\u007B"} // { = \u007B
/ "\\\"" {return "\""}
/ EOL {return "\\n"}
/ [^{\"]
HTMLAttributeTextSingleQuoted
= chars:(
"\\{" {return "\u007B"} // { = \u007B
/ "\\\'" {return "\'"}
/ '"' {return '\\"'}
/ EOL {return "\\n"}
/ [^{\']
)+
{return {type:"text", value:chars.join("")}}

LogBlock
= "{" _ "log " _ first:CoreExpText _ next:("," _ CoreExpText)* _"}" EOS?
Expand Down
8 changes: 4 additions & 4 deletions test/compiler/samples/element1.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
##### Template:
<template test(person)>
<div title="Some text" id="{person.id}" class="{person.gender} {person.category}">
<div title='Some "nice" text' id="{person.id}" class="{person.gender} {person.category}">
Hello {person.name}!
</div>
</template>
Expand All @@ -14,7 +14,7 @@
"args": ["person"],
"content": [
{type:"element", name:"div", closed:false, attributes:[
{type:"attribute", name:"title", value:[{type:"text", value:"Some text"}]},
{type:"attribute", name:"title", value:[{type:"text", value:"Some \\\"nice\\\" text"}]},
{type:"attribute", name:"id", value:[{type:"expression", "category": "jsexptext", "bound": true,
value:"person.id"}]},
{type:"attribute", name:"class", value:[
Expand All @@ -40,7 +40,7 @@
"args": ["person"],
"content": [
{type:"element", name:"div", closed:false, attributes:[
{name:"title", type:"text", value:"Some text"},
{name:"title", type:"text", value:"Some \\\"nice\\\" text"},
{name:"id", type:"expression", "category": "jsexptext", "bound": true, "value": "person.id"},
{name:"class", type:"textblock", content:[
{type:"expression", "category": "jsexptext", "bound": true, "value": "person.gender"},
Expand All @@ -62,7 +62,7 @@
test=[__s,
n.elt( "div",
{e1:[9,"person.id"],e2:[9,"person.gender"],e3:[9,"person.category"]} ,
{"title":"Some text","id":["",1],"class":["",2," ",3]},
{"title":"Some \"nice\" text","id":["",1],"class":["",2," ",3]},
0,[
n.$text({e1:[9,"person.name"]},["Hello ",1,"! "])
]
Expand Down

0 comments on commit 0d72458

Please sign in to comment.