Add block comment syntax:

{{!-- can contain
      {{handlebars expressions}} --}}
This commit is contained in:
Yehuda Katz
2012-10-15 13:51:53 -04:00
parent 8ed7a1e4e6
commit a927a9b0ad
2 changed files with 16 additions and 1 deletions
+12
View File
@@ -158,6 +158,18 @@ describe "Tokenizer" do
result[1].should be_token("COMMENT", " this is a comment ")
end
it "tokenizes a block comment as 'COMMENT'" do
result = tokenize("foo {{!-- this is a {{comment}} --}} bar {{ baz }}")
result.should match_tokens(%w(CONTENT COMMENT CONTENT OPEN ID CLOSE))
result[1].should be_token("COMMENT", " this is a {{comment}} ")
end
it "tokenizes a block comment with whitespace as 'COMMENT'" do
result = tokenize("foo {{!-- this is a\n{{comment}}\n--}} bar {{ baz }}")
result.should match_tokens(%w(CONTENT COMMENT CONTENT OPEN ID CLOSE))
result[1].should be_token("COMMENT", " this is a\n{{comment}}\n")
end
it "tokenizes open and closing blocks as 'OPEN_BLOCK ID CLOSE ... OPEN_ENDBLOCK ID CLOSE'" do
result = tokenize("{{#foo}}content{{/foo}}")
result.should match_tokens(%w(OPEN_BLOCK ID CLOSE CONTENT OPEN_ENDBLOCK ID CLOSE))
+4 -1
View File
@@ -1,5 +1,5 @@
%x mu emu
%x mu emu com
%%
@@ -17,6 +17,8 @@
return 'CONTENT';
}
<com>[\s\S]*?"--}}" { yytext = yytext.substr(0, yyleng-4); this.popState(); return 'COMMENT'; }
<mu>"{{>" { return 'OPEN_PARTIAL'; }
<mu>"{{#" { return 'OPEN_BLOCK'; }
<mu>"{{/" { return 'OPEN_ENDBLOCK'; }
@@ -24,6 +26,7 @@
<mu>"{{"\s*"else" { return 'OPEN_INVERSE'; }
<mu>"{{{" { return 'OPEN_UNESCAPED'; }
<mu>"{{&" { return 'OPEN_UNESCAPED'; }
<mu>"{{!--" { this.popState(); this.begin('com'); }
<mu>"{{!"[\s\S]*?"}}" { yytext = yytext.substr(3,yyleng-5); this.popState(); return 'COMMENT'; }
<mu>"{{" { return 'OPEN'; }