Skip to content

Commit

Permalink
Allow filters after assign directives
Browse files Browse the repository at this point in the history
FIX: Support filter syntax after assign directives.
  • Loading branch information
marijnh committed Nov 14, 2024
1 parent 8288ba4 commit eba4abd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/liquid.grammar
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ directive {
echoTag |
renderTag |
kwTag1<"include"> |
kwTag1<"assign"> |
assignTag |
CaptureDirective { kwTag1<"capture"> element* kwTagEnd<"endcapture"> } |
kwTag1<"increment"> |
kwTag1<"decrement"> |
Expand Down Expand Up @@ -58,17 +58,19 @@ directive {
NumberLiteral
}

Interpolation { interpolationStart expression (Filter*) interpolationEnd }
Interpolation { interpolationStart expression Filter* interpolationEnd }

Tag { tagStart (TagName expression?)? tagEnd }
Tag { tagStart (TagName expression? Filter*)? tagEnd }

forTag[@name=Tag] { tagStart tagName<"for"> VariableName kw<"in"> expression Parameter* tagEnd }
tablerowTag[@name=Tag] { tagStart tagName<"tablerow"> VariableName kw<"in"> expression Parameter* tagEnd }

cycleTag[@name=Tag] { tagStart tagName<"cycle"> (StringLiteral ":")? StringLiteral ("," StringLiteral)* tagEnd }

echoTag[@name=Tag] { tagStart tagName<"echo"> expression (Filter*) tagEnd }
echoTag[@name=Tag] { tagStart tagName<"echo"> expression Filter* tagEnd }

assignTag[@name=Tag] { tagStart tagName<"assign"> expression Filter* tagEnd }

renderTag[@name=Tag] { tagStart tagName<"render"> expression RenderParameter* tagEnd }

liquidTag[@name=Tag] { tagStart tagName<"liquid"> liquidDirective* tagEnd }
Expand Down Expand Up @@ -100,10 +102,10 @@ directive {
kwStat<"break"> |
kwStat<"continue"> |
Tag { kw<"cycle"> (StringLiteral ":")? StringLiteral ("," StringLiteral)* } |
Tag { kw<"echo"> expression (Filter*) } |
Tag { kw<"echo"> expression Filter* } |
Tag { kw<"render"> expression RenderParameter { "," VariableName ":" expression }* } |
kwStat1<"include"> |
kwStat1<"assign"> |
Tag { kw<"assign"> expression Filter* } |
CaptureDirective { kwStat1<"capture"> liquidDirective* kwStatEnd<"endcapture"> } |
kwStat1<"increment"> |
kwStat1<"decrement">
Expand Down
3 changes: 3 additions & 0 deletions test/test-liquid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,7 @@ Template(Tag(liquid,
Tag(assign,AssignmentExpression(VariableName,AssignOp,StringLiteral)),
EndTag(endcase))))
`)

test("Assign with filter", `{% assign zeroFillSize = zeroFill | size %}`,
`Template(Tag(assign,AssignmentExpression(VariableName,AssignOp,VariableName),Filter(FilterName)))`)
})

0 comments on commit eba4abd

Please sign in to comment.