Skip to content

WIP5 - #2134

Closed
charlespwd wants to merge 2 commits into
liquid-factory-shared-expressions-in-forfrom
liquid-factory-array-literals
Closed

WIP5#2134
charlespwd wants to merge 2 commits into
liquid-factory-shared-expressions-in-forfrom
liquid-factory-array-literals

Conversation

@charlespwd

@charlespwd charlespwd commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Research / WIP
Experimental output from liquid-factory, shared for design and code feedback. This is a research draft for the WIP3 stack, not a merge-ready language change.

In this PR

Add array literals to the native shared expression grammar, including nested arrays and trailing commas.

Problem

Templates build fixed lists with 'top,bottom' | split: ',' and empty lists with '' | split: ','.

Solution

Templates can write {% assign rows = ['top', 'bottom'] %} or use literals directly in filters, conditions, loops and render arguments.

ArrayLiteral evaluates its elements in the current context and returns a fresh container. Tags reuse the shared parser, so no tag-specific array implementation is needed. A leading [ constructs an array in every shared-parser call, with no reject_bare_brackets option or legacy unnamed-bracket branch.

Paired specs: Shopify/liquid-spec#169, adding specs/liquid_ruby/array_literals.yml.

Ruby API migration

Remove reject_bare_brackets: from Parser.new calls. The shared parser now has one leading-bracket grammar, including in Context#[]:

  • context['[key]'] evaluates an array containing the value of key.
  • Use context['self[key]'] for the indirect variable lookup previously expressed by bare brackets.

Existing native-template results stay unchanged. Typed legacy lookup-string APIs remain separate; this change does not add a replacement parser mode.

Feature boundary

Outcome

Construct an Array directly with [] or [expression, ...] wherever the native parser accepts an expression.

Scope

  • Empty, nested and expression-valued arrays, whitespace and one optional trailing comma at each level.
  • Ordinary Array behavior in output, filters, conditions, case/when, loops, cycle, assignment and lookups on assigned variables.
  • Existing expression-taking tag positions, including render/include arguments, use the shared grammar.
  • Literal-owned containers are fresh on each evaluation. Element values retain their existing semantics.
  • Existing native-template output stays unchanged. The shared Parser and Context#[] now use the same array grammar for leading brackets; self[...] remains explicit lookup.

Acceptance boundary

  • The paired specs/liquid_ruby/array_literals.yml contains the approved preservation, constructor and malformed-input cases.
  • Existing native-template indexed/dotted/self lookup results, WIP3 expression semantics and shared-for metadata/modifiers remain unchanged.
  • The exact render/include examples and inherited assignment-score/resource limits are covered in test/integration/array_literal_test.rb.
  • Malformed arrays, key-value elements and direct postfix access such as [1, 2][0] remain syntax errors.

Non-goals

Hash literals, mixed array/hash literal nesting, arithmetic, filtered parentheses, interpolation, new postfix grammar and changes to for-argument separators.

Dependencies

  • Parent implementation: Shopify/liquid#2133, liquid-factory-shared-expressions-in-for at 372f77cbebd9c9c5319d967a1a988d7c5878b225.
  • Parent specs: Shopify/liquid-spec#168, the same branch name at 736ebca7b4377dbd8bf59232649fa00c69b21ea3.
  • These dependencies are present at the pinned bases. This pair is stacked on those branches, not on main or the independent hash-literal feature.

The cases are examples, not proof that every possible template preserves its output.

@isaacbowen

Copy link
Copy Markdown

@charlespwd platform-grade prior art over in Mechanic: https://learn.mechanic.dev/platform/liquid/keyword-literals/array

@charlespwd
charlespwd added this pull request to stack #2135 October 27, 2026 18:07
@charlespwd charlespwd changed the title WIP: Array literals WIP5 Oct 27, 2026
@charlespwd charlespwd closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants