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

Cannot loop some expressions in for that Jinja2 can #180

Closed
jpcima opened this issue Nov 3, 2019 · 3 comments
Closed

Cannot loop some expressions in for that Jinja2 can #180

jpcima opened this issue Nov 3, 2019 · 3 comments

Comments

@jpcima
Copy link

jpcima commented Nov 3, 2019

Hi, I have tried a set of expressions which are not currently working as expected.

1. {% for v in [1, 2] %}{{v}}{% endfor %}
2. {% for v in [1, 2]+[3, 4] %}{{v}}{% endfor %}
3. {% for v in "ab" %}{{v}}{% endfor %}
4. {% for v in "ab"+"cd" %}{{v}}{% endfor %}
5. {% for v in 'a' ~ 'b' %}{{v}}{% endfor %}

According to Jinja2:

1. 12
2. 1234
3. ab
4. abcd
5. ab

In Jinja2cpp, I find only the first one is working, the other 4 evaluate as empty.

I believe that 3 4 and 5 are because it's not handled to loop over characters.
Regarding 2, I'm under impression it's the + operation not supported for concatenating lists. (possibly in scope of issue #135)

@flexferrum
Copy link
Collaborator

Hi! Thank you for pointing that out. Actually, you're right. 2 is because of + operator doesn't concatenate lists (but it should? ok). 3, 4, and 5 need checking. Strings should be treated as iterable (in general). But seems like something went wrong. Will check it soon with #178 issue.

@jpcima
Copy link
Author

jpcima commented Nov 7, 2019

2 is because of + operator doesn't concatenate lists (but it should? ok).

Yes. Lists also recognize a commutative * operator on (List, Int) which repeats N times the sequence.

Strings should be treated as iterable (in general). But seems like something went wrong.

I'm sure the commented part of ListConverter must be relevant to the problem.

// template<typename CharT>
// result_t operator() (const std::basic_string<CharT>& str) const
// {
// return result_t(ListAdapter([adaptor = StringAdapter<CharT>(&str)]() {return &adaptor;}));
// }

flexferrum added a commit that referenced this issue Nov 11, 2019
- Add support for some operators
- Improve 'for' loop implementation to support tuples unpack
@jpcima
Copy link
Author

jpcima commented Nov 12, 2019

I confirm this worked great, thanks for the work.

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

No branches or pull requests

2 participants