diff options
author | Kevin Decker <kpdecker@gmail.com> | 2014-11-08 17:49:14 -0600 |
---|---|---|
committer | Kevin Decker <kpdecker@gmail.com> | 2014-11-08 17:49:14 -0600 |
commit | ea6b0be910d3fb0178d8e2d1fcc54c17b8d3a94f (patch) | |
tree | 5ba7d55fb42ab6f134075b5c5d75dbbb4670896d /src | |
parent | e779ecf12dade0aba530610b37dc28a57d946c9d (diff) | |
parent | 4282668d47b90da0d00cf4c4a86977f18fc8cde4 (diff) | |
download | handlebars.js-ea6b0be910d3fb0178d8e2d1fcc54c17b8d3a94f.zip handlebars.js-ea6b0be910d3fb0178d8e2d1fcc54c17b8d3a94f.tar.gz handlebars.js-ea6b0be910d3fb0178d8e2d1fcc54c17b8d3a94f.tar.bz2 |
Merge pull request #892 from wycats/else-if
Implement parser for else chaining of helpers
Diffstat (limited to 'src')
-rw-r--r-- | src/handlebars.l | 2 | ||||
-rw-r--r-- | src/handlebars.yy | 18 |
2 files changed, 18 insertions, 2 deletions
diff --git a/src/handlebars.l b/src/handlebars.l index fbeec34..f3c925c 100644 --- a/src/handlebars.l +++ b/src/handlebars.l @@ -76,7 +76,7 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/{LOOKAHEAD} <mu>"{{"{LEFT_STRIP}?"^"\s*{RIGHT_STRIP}?"}}" this.popState(); return 'INVERSE'; <mu>"{{"{LEFT_STRIP}?\s*"else"\s*{RIGHT_STRIP}?"}}" this.popState(); return 'INVERSE'; <mu>"{{"{LEFT_STRIP}?"^" return 'OPEN_INVERSE'; -<mu>"{{"{LEFT_STRIP}?\s*"else" return 'OPEN_INVERSE'; +<mu>"{{"{LEFT_STRIP}?\s*"else" return 'OPEN_INVERSE_CHAIN'; <mu>"{{"{LEFT_STRIP}?"{" return 'OPEN_UNESCAPED'; <mu>"{{"{LEFT_STRIP}?"&" return 'OPEN'; <mu>"{{"{LEFT_STRIP}?"!--" { diff --git a/src/handlebars.yy b/src/handlebars.yy index ccc0d22..3bd9abc 100644 --- a/src/handlebars.yy +++ b/src/handlebars.yy @@ -30,7 +30,7 @@ openRawBlock ; block - : openBlock program inverseAndProgram? closeBlock -> yy.prepareBlock($1, $2, $3, $4, false, @$) + : openBlock program inverseChain? closeBlock -> yy.prepareBlock($1, $2, $3, $4, false, @$) | openInverse program inverseAndProgram? closeBlock -> yy.prepareBlock($1, $2, $3, $4, true, @$) ; @@ -42,10 +42,26 @@ openInverse : OPEN_INVERSE sexpr CLOSE -> new yy.MustacheNode($2, null, $1, yy.stripFlags($1, $3), @$) ; +openInverseChain + : OPEN_INVERSE_CHAIN sexpr CLOSE -> new yy.MustacheNode($2, null, $1, yy.stripFlags($1, $3), @$) + ; + inverseAndProgram : INVERSE program -> { strip: yy.stripFlags($1, $1), program: $2 } ; +inverseChain + : openInverseChain program inverseChain? { + var inverse = yy.prepareBlock($1, $2, $3, $3, false, @$), + program = new yy.ProgramNode(yy.prepareProgram([inverse]), {}, @$); + + program.inverse = inverse; + + $$ = { strip: $1.strip, program: program, chain: true }; + } + | inverseAndProgram -> $1 + ; + closeBlock : OPEN_ENDBLOCK path CLOSE -> {path: $2, strip: yy.stripFlags($1, $3)} ; |