bkiers / Liqp

An ANTLR based 'Liquid Template' parser and rendering engine.
MIT License
165 stars 94 forks source link

LiquidParser: Fix antlr warning about matching an empty string #277

Closed kohlschuetter closed 1 year ago

kohlschuetter commented 1 year ago

antlr rightfully complains: "rule output contains an optional block with at least one alternative that can match an empty string" (which hints at a potential performance problem).

This is due to "not_out_end" matching with "*" (which can yield an empty string), even though we already specify "?" at "unparsed=not_out_end?".

Fix the parser grammar, and adjust two test cases where we actually tested for that undesired behavior.

Also see https://stackoverflow.com/questions/26041293/antlr-4-warning-rule-contains-an-optional-block-with-at-least-one-alternative for an explanation.

msangel commented 1 year ago

I merged this into the branch I already merged into the master.
Thanks!