Shopify / Shopify/liquid

Unified syntax for tag arguments [RFC]

Open
#560 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Parser Question
Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

Tags are currently implemented as an arbitrary syntax defined in their #initialize or #parse method. Some of them use a combination of Liquid's regexes to do parsing, but not in a consistent way. This makes updating the language difficult – in particular, phasing out the lax parser.

Filters, on the other hand, are simply passed an array (positional arguments) and hash (keyword arguments), and have no say in how they were parsed. This decoupling is a huge advantage, allowing fixes and improvements to affect all filters without breaking them.

So, the idea is automatically parse tags in a certain format, for example:

arg = id colon expr | expr
tag = id (arg (comma arg)*)?

Then, the tag can access the resulting arguments (i.e. values returned from Expression.parse).

Since we do still want certain tags to have custom syntax, we can't 100% separate parsing from the tag definition. Some kind of way to extend the default will be necessary. However, since most tags don't need this (maybe none outside of the core tags?), it still allows most of the parsing logic to be decoupled.

Tags that need partially custom syntax could still take advantage of the argument parsing, e.g. the for tag:

for foo in bar reversed, limit: 4, offset: 5

Does this make sense? @Shopify/liquid @parkr

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by comparing how tags parse arguments in their #initialize or #parse methods with how filters receive positional and keyword arguments. Define the default tag argument format and how tags with custom syntax extend it; done means common tag parsing is decoupled while custom cases remain supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.