Skip to content
Open
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
8 changes: 6 additions & 2 deletions hsp/compiler/parser/hspblocks.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ TemplateEnd "template end statement"

TemplateContent "template content" // TODO: CSSClassExpression
= _ blocks:( TplTextBlock
/ CommentBlock / HTMLCommentBlock
/ CommentBlock / MultiCommentBlock / HTMLCommentBlock
/ IfBlock / ElseIfBlock / ElseBlock / EndIfBlock
/ ForeachBlock / EndForeachBlock
/ HTMLElement / EndHTMLElement
Expand All @@ -88,7 +88,7 @@ TplTextChar "text character"
/ EOL &TemplateEnd {return ""} // ignore last EOL
/ EOL _ {return " "}
/ "#" !(_ "\/template") {return "#"}
/ "\/" !"/" {return "/"}
/ "\/" c:[^/\*] {return "/"+c}
/ "\\/" {return "/"}
/ "\\//" {return "//"}
/ "\\<" {return "<"}
Expand Down Expand Up @@ -118,6 +118,10 @@ CommentBlock
= _ "\/\/" chars:[^\r\n]* &EOL
{return {type:"comment", value:chars.join('')}}

MultiCommentBlock
= "/*" chars:((!"*/" c:.) {return c})* "*/"
{return {type:"comment", value:chars.join('')}}

HTMLCommentBlock
= "<!--" chars:HTMLCommentChar* "-->"
{return {type:"comment", value:chars.join('')}}
Expand Down
24 changes: 14 additions & 10 deletions test/compiler/samples/comment.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
##### Template:
# template hello(world)
Hello // comment 1
World!
Hel / lo // comment 1
World! /* this is a
multi line
comment */
{if (world)} // comment 2
<!-- another comment
on multiple
lines
# /template
-->
...
... Escaping \/* works *\/
{/if}
# /template

Expand All @@ -20,15 +22,17 @@
"name": "hello",
"args": ["world"],
"content": [
{"type": "text","value": "Hello "},
{"type": "text","value": "Hel / lo "},
{"type": "comment","value": " comment 1"},
{"type": "text","value": " World! "},
{"type": "comment","value": " this is a\n\tmulti line\n\tcomment "},
{"type": "text","value": " "},
{"type": "if", "condition": {type:"Variable", category:"jsexpression", name:"world"}},
{"type": "text","value": " "},
{"type": "comment","value": " comment 2"},
{"type": "text","value": " "},
{"type": "comment","value": " another comment\n\t on multiple \n\t lines \n\t # /template\n\t "},
{"type": "text","value": " ... "},
{"type": "text","value": " ... Escaping /* works */ "},
{"type": "endif"}
]
}
Expand All @@ -43,7 +47,7 @@
"content": [
{
"type": "text",
"value": "Hello World! "
"value": "Hel / lo World! "
},
{
"type": "if",
Expand All @@ -54,13 +58,13 @@
"path": [
"world"
],
"line": 4,
"line": 6,
"column": 6
},
"content1": [
{
"type": "text",
"value": " ... "
"value": " ... Escaping /* works */ "
}
]
}
Expand All @@ -70,8 +74,8 @@

##### Template Code
hello=[
n.$text(0,["Hello World!"]),
n.$text(0,["Hel / lo World!"]),
n.$if( {e1:[1,1,"world"]}, 1, [
n.$text(0,[" ... "])
n.$text(0,[" ... Escaping /* works */ "])
])
]