Skip to content

Commit b9a72ce

Browse files
osteeleclaude
andauthored
Fix #123: Add support for 'or' operator in case/when tags (#127)
This commit implements support for the 'or' operator in 'when' clauses of case statements, matching the official Shopify Liquid specification. Changes: - Modified expressions.y grammar to accept 'or' as an alternative separator to commas in the expr2 rule for when statements - Regenerated y.go parser from the updated grammar - Added comprehensive test cases for 'or' operator usage: * Integer values with 'or' operator * String values matching Shopify documentation examples * Multiple 'or' operators (e.g., 1 or 2 or 3) The implementation now supports both syntaxes as specified in the Shopify documentation: - Comma-separated: {% when 1, 2 %} - OR operator: {% when 1 or 2 %} - Multiple ORs: {% when 1 or 2 or 3 %} All existing tests continue to pass, confirming backward compatibility. Fixes #123 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 19586ab commit b9a72ce

File tree

4 files changed

+112
-92
lines changed

4 files changed

+112
-92
lines changed

expressions/expressions.y

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ exprs: expr expr2 { $$ = append([]Expression{&expression{$1}}, $2...) } ;
8484
expr2:
8585
/* empty */ { $$ = []Expression{} }
8686
| ',' expr expr2 { $$ = append([]Expression{&expression{$2}}, $3...) }
87+
| OR expr expr2 { $$ = append([]Expression{&expression{$2}}, $3...) }
8788
;
8889

8990
string: LITERAL {

expressions/statements_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ func TestParseStatement(t *testing.T) {
4242
stmt, err = ParseStatement(WhenStatementSelector, "a, b")
4343
require.NoError(t, err)
4444
require.Len(t, stmt.Exprs, 2)
45+
46+
stmt, err = ParseStatement(WhenStatementSelector, "a or b")
47+
require.NoError(t, err)
48+
require.Len(t, stmt.Exprs, 2)
4549
}

expressions/y.go

Lines changed: 98 additions & 91 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)