Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use a variable or value index for object in assign tag #207

Closed
chippers opened this issue Oct 4, 2018 · 3 comments · Fixed by #208
Closed

Unable to use a variable or value index for object in assign tag #207

chippers opened this issue Oct 4, 2018 · 3 comments · Fixed by #208

Comments

@chippers
Copy link

chippers commented Oct 4, 2018

liquid-rust version: 0.16.0
rust version: 1.29.1
OS: Xubuntu 18.04

Hi again, and thanks for such a rapid fix yesterday.

Here, we are unable to use a value as an index to an object in an assign tag. I've updated the small testable case from yesterday as an example.

{% for kv in site.data.authors %}
{% assign name = kv[1].name %}
* {{ kv[0] }}: {{ name }}
{% endfor %}

The failure is in assign, it works when kv[1].name is directly used. (what is the name of the {{ }} blocks?)

This is used quite a lot in arewewebyet, and many Jekyll project's I've written/read make use of this feature to shorthand variables that are otherwise unwieldy. It's possible to not use it, but this feature makes reading the code a lot easier.

I took a quick look at perhaps implementing the fix myself, but after a small bit of reading it seems like the fix would likely be relatively invasive for a codebase I am not familiar with yet. Here's some of the things I found that might help:

  • It seems that parsing the assign tag's arguments goes wrong when parsing into a FilterChain
  • fn parse_output expects there to only be a single Token of input to turn into an Argument
  • The lexer outputs [Identifier("kv"), OpenSquare, IntegerLiteral(1), CloseSquare, Dot, Identifier("name")] for the input kv[1].name
  • In the library that Jekyll uses, liquid-c, the parser has a special case for Token::OpenSquare in parse_expression and parse_variable. It also has a special case for Token::Dot, but in liquid-rust the dots are already handled and put inside a single identifier - like Identifier("site.data.authors").

Hopefully some of that is helpful, again not yet familiar with the codebase.

Thanks

@chippers chippers changed the title Unable to use variable object index in assign tag Unable to use variable or value index for object in assign tag Oct 4, 2018
@chippers chippers changed the title Unable to use variable or value index for object in assign tag Unable to use a variable or value index for object in assign tag Oct 4, 2018
@epage
Copy link
Member

epage commented Oct 5, 2018

Yeah, the parser is in terrible shape and gets in the way of conforming (e.g. #92, #145). I'd rather rewrite it (#138) but just haven't gotten to it yet.

I'll take a look to see what I can do.

epage added a commit to epage/liquid-rust that referenced this issue Oct 5, 2018
This does not fix it so the filter arguments support indexing.

Fixes cobalt-org#207
@epage
Copy link
Member

epage commented Oct 5, 2018

I actually got something to work! Going to bed soon, it'll probably be tomorrow morning before I finish the merges and get the releases out

epage added a commit to epage/liquid-rust that referenced this issue Oct 5, 2018
This does not fix it so the filter arguments support indexing.

Fixes cobalt-org#207
epage added a commit to epage/liquid-rust that referenced this issue Oct 5, 2018
This does not fix it so the filter arguments support indexing.

Fixes cobalt-org#207
epage added a commit to epage/liquid-rust that referenced this issue Oct 5, 2018
This does not fix it so the filter arguments support indexing.

Fixes cobalt-org#207
@epage epage closed this as completed in #208 Oct 5, 2018
@epage
Copy link
Member

epage commented Oct 5, 2018

New cobalt release is now out!

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 a pull request may close this issue.

2 participants