-
Notifications
You must be signed in to change notification settings - Fork 16
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
Allow identifiers to start with an uppercase letter #256
Comments
We use upper case characters to variables, and unit structs / unit enum variants apart. In this regard rust is context sensitive, we need to know what a name refers to. To keep things easy / manageable, we assume anything that contains an upper case character is not a variable. It would be nice to have the same semantics as rust, but IMHO practicability beats completeness. |
But the following, although it contains an upper case letter (but doesn't start with one) is accepted by both Askama and Rinja. Thus perhaps only the first letter must be lower?
I didn't quite understand this: in Rust code, one can have variables starting with an upper case letter, or enum variants starting with a lower case one, and everything works just fine; thus the Rust language doesn't differentiate at all between upper case and lower case letters, and it's only a convention. Granted, the Rust compiler is much more complex, and has much more context to decide if an identifier is a enum variant (i.e. In the end, as long as it's documented, I believe having the limitation of variables needing to start with a lowercase letter is acceptable. (For example in Erlang and Prolog variables must always start with an uppercase letter.) However, after the initial first letter (or |
Do you have an example where there would be an ambiguity @Kijewski ? |
Yes, |
Same issue with all unit struct. But I mean, in which expressions would this ambiguity be an issue? |
How would we know what the users intends ↓ to do? Should we match on {% match var %}
{% when Some(x) %}
{% let y = None %}
{# → let y = None #}
{% when None %}
{% let y = None %}
{# → let y = &None #}
{% endmatch %} Unless I'm altogether mistaken. |
In the end, I don't care too much. If the tests pass, then I'm happy either way. I just fear that this change could break things down the road if we notice that we have to undo the change. But a few unit tests could probably take away my fears. :) |
It's tricky indeed. But in case we already have a variable named |
As was suggested while discussing #244, I'm creating a new feature request to allow identifiers to start with an uppercase letter:
This fails (both on Rinja and Askama) with the same error:
However, it is allowed by the Python Jinja2 code:
Why might one want to use an identifier starting with an upper-case?
XXX_YYY_ZZZ
);Moreover, it would be nice (unless it conflicts with the Jinja syntax) that all Rust valid identifiers (as specified in https://doc.rust-lang.org/reference/identifiers.html) to be considered valid identifiers for
let
,for
,match
and other places where identifiers are to be used.The text was updated successfully, but these errors were encountered: