Fix repeated delimiter escaping

This commit is contained in:
tomhuda
2012-09-12 20:44:48 -07:00
parent f55ca6c489
commit 5a6e4f1ddd
2 changed files with 14 additions and 1 deletions
+9
View File
@@ -51,6 +51,15 @@ describe "Tokenizer" do
result[4].should be_token("CONTENT", "{{bar}} ")
end
it "supports escaping multiple delimiters" do
result = tokenize("{{foo}} \\{{bar}} \\{{baz}}")
result.should match_tokens(%w(OPEN ID CLOSE CONTENT CONTENT CONTENT))
result[3].should be_token("CONTENT", " ")
result[4].should be_token("CONTENT", "{{bar}} ")
result[5].should be_token("CONTENT", "{{baz}}")
end
it "supports escaping a triple stash" do
result = tokenize("{{foo}} \\{{{bar}}} {{baz}}")
result.should match_tokens(%w(OPEN ID CLOSE CONTENT CONTENT OPEN ID CLOSE))
+5 -1
View File
@@ -11,7 +11,11 @@
[^\x00]+ { return 'CONTENT'; }
<emu>[^\x00]{2,}?/("{{") { this.popState(); return 'CONTENT'; }
<emu>[^\x00]{2,}?/("{{"|<<EOF>>) {
if(yytext.slice(-1) !== "\\") this.popState();
if(yytext.slice(-1) === "\\") yytext = yytext.substr(0,yyleng-1);
return 'CONTENT';
}
<mu>"{{>" { return 'OPEN_PARTIAL'; }
<mu>"{{#" { return 'OPEN_BLOCK'; }