diff --git a/handlebars/src/com/dmarcotte/handlebars/parsing/HbParsing.java b/handlebars/src/com/dmarcotte/handlebars/parsing/HbParsing.java index 0169aa7f2b6..b5077c055b3 100644 --- a/handlebars/src/com/dmarcotte/handlebars/parsing/HbParsing.java +++ b/handlebars/src/com/dmarcotte/handlebars/parsing/HbParsing.java @@ -311,8 +311,8 @@ else if (builder.getTokenType() == OPEN_UNESCAPED) { /** * partial - * : OPEN_PARTIAL partialName CLOSE { $$ = new yy.PartialNode($2); } - * | OPEN_PARTIAL partialName path CLOSE { $$ = new yy.PartialNode($2, $3); } + * : OPEN_PARTIAL partialName param hash? CLOSE + * | OPEN_PARTIAL partialName hash? CLOSE * ; */ protected void parsePartial(PsiBuilder builder) { @@ -322,13 +322,22 @@ protected void parsePartial(PsiBuilder builder) { parsePartialName(builder); - // parse the optional path - PsiBuilder.Marker optionalPathMarker = builder.mark(); - if (parsePath(builder)) { - optionalPathMarker.drop(); + // parse the optional param + PsiBuilder.Marker optionalParamMarker = builder.mark(); + if (parseParam(builder)) { + optionalParamMarker.drop(); + } + else { + optionalParamMarker.rollbackTo(); + } + + // parse the optional hash + PsiBuilder.Marker optionalHashMarker = builder.mark(); + if (parseHash(builder)) { + optionalHashMarker.drop(); } else { - optionalPathMarker.rollbackTo(); + optionalHashMarker.rollbackTo(); } parseLeafTokenGreedy(builder, CLOSE); diff --git a/handlebars/test/data/parser/ParsesPartialWithContextAndHash.hbs b/handlebars/test/data/parser/ParsesPartialWithContextAndHash.hbs new file mode 100644 index 00000000000..4ebe45ff572 --- /dev/null +++ b/handlebars/test/data/parser/ParsesPartialWithContextAndHash.hbs @@ -0,0 +1 @@ +{{> foo bar bat=baz}} \ No newline at end of file diff --git a/handlebars/test/data/parser/ParsesPartialWithContextAndHash.txt b/handlebars/test/data/parser/ParsesPartialWithContextAndHash.txt new file mode 100644 index 00000000000..faa422ba0ef --- /dev/null +++ b/handlebars/test/data/parser/ParsesPartialWithContextAndHash.txt @@ -0,0 +1,26 @@ +HbFile:ParsesPartialWithContextAndHash.hbs + HbStatementsImpl(STATEMENTS) + HbPartialImpl(PARTIAL_STACHE) + HbPsiElementImpl([Hb] OPEN_PARTIAL) + PsiElement([Hb] OPEN_PARTIAL)('{{>') + PsiWhiteSpace(' ') + HbPartialNameImpl(PARTIAL_NAME) + HbPathImpl(PATH) + HbPsiElementImpl([Hb] ID) + PsiElement([Hb] ID)('foo') + PsiWhiteSpace(' ') + HbParamImpl(PARAM) + HbPathImpl(PATH) + HbPsiElementImpl([Hb] ID) + PsiElement([Hb] ID)('bar') + PsiWhiteSpace(' ') + HbPsiElementImpl([Hb] ID) + PsiElement([Hb] ID)('bat') + HbPsiElementImpl([Hb] EQUALS) + PsiElement([Hb] EQUALS)('=') + HbParamImpl(PARAM) + HbPathImpl(PATH) + HbPsiElementImpl([Hb] ID) + PsiElement([Hb] ID)('baz') + HbPsiElementImpl([Hb] CLOSE) + PsiElement([Hb] CLOSE)('}}') \ No newline at end of file diff --git a/handlebars/test/data/parser/ParsesPartialWithHash.hbs b/handlebars/test/data/parser/ParsesPartialWithHash.hbs new file mode 100644 index 00000000000..ec40297ef56 --- /dev/null +++ b/handlebars/test/data/parser/ParsesPartialWithHash.hbs @@ -0,0 +1 @@ +{{> foo bar=bat}} \ No newline at end of file diff --git a/handlebars/test/data/parser/ParsesPartialWithHash.txt b/handlebars/test/data/parser/ParsesPartialWithHash.txt new file mode 100644 index 00000000000..1db13a1fe50 --- /dev/null +++ b/handlebars/test/data/parser/ParsesPartialWithHash.txt @@ -0,0 +1,21 @@ +HbFile:ParsesPartialWithHash.hbs + HbStatementsImpl(STATEMENTS) + HbPartialImpl(PARTIAL_STACHE) + HbPsiElementImpl([Hb] OPEN_PARTIAL) + PsiElement([Hb] OPEN_PARTIAL)('{{>') + PsiWhiteSpace(' ') + HbPartialNameImpl(PARTIAL_NAME) + HbPathImpl(PATH) + HbPsiElementImpl([Hb] ID) + PsiElement([Hb] ID)('foo') + PsiWhiteSpace(' ') + HbPsiElementImpl([Hb] ID) + PsiElement([Hb] ID)('bar') + HbPsiElementImpl([Hb] EQUALS) + PsiElement([Hb] EQUALS)('=') + HbParamImpl(PARAM) + HbPathImpl(PATH) + HbPsiElementImpl([Hb] ID) + PsiElement([Hb] ID)('bat') + HbPsiElementImpl([Hb] CLOSE) + PsiElement([Hb] CLOSE)('}}') \ No newline at end of file diff --git a/handlebars/test/data/parser/PartialWithContext.txt b/handlebars/test/data/parser/PartialWithContext.txt index 2d0d7db864d..1281b1a927e 100644 --- a/handlebars/test/data/parser/PartialWithContext.txt +++ b/handlebars/test/data/parser/PartialWithContext.txt @@ -9,8 +9,9 @@ HbFile:PartialWithContext.hbs HbPsiElementImpl([Hb] ID) PsiElement([Hb] ID)('foo') PsiWhiteSpace(' ') - HbPathImpl(PATH) - HbPsiElementImpl([Hb] ID) - PsiElement([Hb] ID)('bar') + HbParamImpl(PARAM) + HbPathImpl(PATH) + HbPsiElementImpl([Hb] ID) + PsiElement([Hb] ID)('bar') HbPsiElementImpl([Hb] CLOSE) PsiElement([Hb] CLOSE)('}}') \ No newline at end of file diff --git a/handlebars/test/src/com/dmarcotte/handlebars/parsing/HbLexerFreeFormTest.java b/handlebars/test/src/com/dmarcotte/handlebars/parsing/HbLexerFreeFormTest.java index d6a737f49b3..86c18b680dc 100644 --- a/handlebars/test/src/com/dmarcotte/handlebars/parsing/HbLexerFreeFormTest.java +++ b/handlebars/test/src/com/dmarcotte/handlebars/parsing/HbLexerFreeFormTest.java @@ -256,4 +256,10 @@ public void testDecimalNumberAsMustacheHashParam() { result.shouldMatchTokenTypes(OPEN, ID, WHITE_SPACE, ID, EQUALS, NUMBER, CLOSE); result.shouldMatchTokenContent("{{", "name", " ", "paramValue", "=", "10.1", "}}"); } + + public void testDataParamsForPartials() { + TokenizerResult result = tokenize("{{>foo @bar.baz}}"); + result.shouldMatchTokenTypes(OPEN_PARTIAL, ID, WHITE_SPACE, DATA_PREFIX, ID, SEP, ID, CLOSE); + result.shouldMatchTokenContent("{{>", "foo", " ", "@", "bar", ".", "baz", "}}"); + } } diff --git a/handlebars/test/src/com/dmarcotte/handlebars/parsing/HbParserSpecTest.java b/handlebars/test/src/com/dmarcotte/handlebars/parsing/HbParserSpecTest.java index b5fea297ac8..2c200d30456 100644 --- a/handlebars/test/src/com/dmarcotte/handlebars/parsing/HbParserSpecTest.java +++ b/handlebars/test/src/com/dmarcotte/handlebars/parsing/HbParserSpecTest.java @@ -67,6 +67,14 @@ public void testPartialWithContext() { doTest(true); } + public void testParsesPartialWithHash() { + doTest(true); + } + + public void testParsesPartialWithContextAndHash() { + doTest(true); + } + public void testPartialWithComplexName() { doTest(true); }