rinja-rs / rinja

A template rendering engine based on Jinja, generating type-safe Rust code at compile time.
https://rinja.readthedocs.io
Apache License 2.0
28 stars 4 forks source link

Simplify syntax by removing all binary operations (like `|`/`&`/`^`) #16

Closed GuillaumeGomez closed 2 weeks ago

GuillaumeGomez commented 2 weeks ago

It is something I expect to be rarely used in templates and it makes some syntax errors very confusing, like:

{% a | indent %}

In this case, the only difference between making an or binary operation or applying a filter on a are the whitespace characters around |.

Instead, I suggest to just remove them and eventually add them as filters (I'm not convinced it's worth it though but why not).

I don't include other mathematical operations (like +, /, *) in this removal though as there is no syntax ambiguity in this case as far as I know.

What do you think @Kijewski?

Kijewski commented 2 weeks ago

How about not removing or re-implementing them as filters or functions, but renaming them like:

Or the ISO 646 way:

Our parser does the lexing and parsing in one step, so you could still have expressions like {{ bor band xor }}write!(w, "{}", self.bor & self.xor) without syntax clashes. (I would still advise against it, though. :) )

GuillaumeGomez commented 2 weeks ago

Hum. It's an alternative I didn't think of. Although it's also an extension of syntax. I personally tend to prefer to keep the syntax small if possible. There is no direct equivalent of {{ var call other_var }}, except for math operations like {{ var + other_var }}. I'm once again not convinced. :laughing:

Kijewski commented 2 weeks ago

I can tell that there are actually strange people out there, who do need bit-operators in their template code, because they use SQL integer fields like flags. I know that, because I do that sometimes. :) I don't think that it should be made too difficult to do bit tests.

And I actually like languages that use fewer "special characters" like ^ & |. It takes me much longer to write && than typing and. Maybe only milliseconds longer, but you type && and || a lot over the day.

GuillaumeGomez commented 2 weeks ago

Well, if you have a use case for it, then it's fine by me! Let's go for the ISO 646 way then!