Skip to content

Unified syntax for tag arguments [RFC] #560

Open
@pushrax

Description

@pushrax

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions