diff options
author | Yehuda Katz <tomhuda@Yehudas-iMac.local> | 2011-12-27 17:04:59 -0800 |
---|---|---|
committer | Yehuda Katz <tomhuda@Yehudas-iMac.local> | 2011-12-27 17:04:59 -0800 |
commit | c79c761460f7d08e3862c0c9992f65a799771851 (patch) | |
tree | eb2c1d67bdf7f37ea235e9e83620fc02a168a0c6 /src | |
parent | e474e56b804d55d294d7bd1ae6c37c4bc57eb1f0 (diff) | |
download | handlebars.js-c79c761460f7d08e3862c0c9992f65a799771851.zip handlebars.js-c79c761460f7d08e3862c0c9992f65a799771851.tar.gz handlebars.js-c79c761460f7d08e3862c0c9992f65a799771851.tar.bz2 |
Add support for escaping mustaches
Diffstat (limited to 'src')
-rw-r--r-- | src/handlebars.l | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/handlebars.l b/src/handlebars.l index dd92cbf..e47c5b1 100644 --- a/src/handlebars.l +++ b/src/handlebars.l @@ -1,11 +1,18 @@ -%x mu +%x mu emu %% -[^\x00]*?/("{{") { this.begin("mu"); if (yytext) return 'CONTENT'; } +[^\x00]*?/("{{") { + if(yytext.slice(-1) !== "\\") this.begin("mu"); + if(yytext.slice(-1) === "\\") yytext = yytext.substr(0,yyleng-1), this.begin("emu"); + if(yytext) return 'CONTENT'; + } + [^\x00]+ { return 'CONTENT'; } +<emu>[^\x00]{2,}?/("{{") { this.popState(); return 'CONTENT'; } + <mu>"{{>" { return 'OPEN_PARTIAL'; } <mu>"{{#" { return 'OPEN_BLOCK'; } <mu>"{{/" { return 'OPEN_ENDBLOCK'; } @@ -13,7 +20,7 @@ <mu>"{{"\s*"else" { return 'OPEN_INVERSE'; } <mu>"{{{" { return 'OPEN_UNESCAPED'; } <mu>"{{&" { return 'OPEN_UNESCAPED'; } -<mu>"{{!"[\s\S]*?"}}" { yytext = yytext.substr(3,yyleng-5); this.begin("INITIAL"); return 'COMMENT'; } +<mu>"{{!"[\s\S]*?"}}" { yytext = yytext.substr(3,yyleng-5); this.popState(); return 'COMMENT'; } <mu>"{{" { return 'OPEN'; } <mu>"=" { return 'EQUALS'; } @@ -21,8 +28,8 @@ <mu>".." { return 'ID'; } <mu>[\/.] { return 'SEP'; } <mu>\s+ { /*ignore whitespace*/ } -<mu>"}}}" { this.begin("INITIAL"); return 'CLOSE'; } -<mu>"}}" { this.begin("INITIAL"); return 'CLOSE'; } +<mu>"}}}" { this.popState(); return 'CLOSE'; } +<mu>"}}" { this.popState(); return 'CLOSE'; } <mu>'"'("\\"["]|[^"])*'"' { yytext = yytext.substr(1,yyleng-2).replace(/\\"/g,'"'); return 'STRING'; } <mu>"true"/[}\s] { return 'BOOLEAN'; } <mu>"false"/[}\s] { return 'BOOLEAN'; } |