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

Fixed path parser to account for single identifier type names #453

Merged
merged 3 commits into from
Feb 22, 2021
Merged

Conversation

vallentin
Copy link
Collaborator

  • Fixed parser::path() to account for None and Some. In short, a single identifier is considered a path, if it contains at least 1 uppercase and lowercase character
  • Added parser tests for variables and paths
  • Added generator test for {{ Self::foo(None) }} {{ Self::foo(Some(2)) }}

Reference #451

@vallentin vallentin requested a review from djc February 22, 2021 03:24
@vallentin vallentin mentioned this pull request Feb 22, 2021
@vallentin
Copy link
Collaborator Author

While fixing this I was thinking about #433. Instead of having the following check, then we could e.g. change Expr::Var(&'a str) into Expr::Var(&'a str, bool). The bool would then represent whether if it's a constant or not, and in short enforce that self. is not prepended.

https://github.com/djc/askama/blob/7ee368e57a419bf05826522df695ddd62d17684d/askama_shared/src/generator.rs#L1726

Note I didn't really look into it much, but I feel like using bool would be the smallest change. We could also refactor Expr::Var into Expr::Field and Expr::Const. Again, I didn't look into it, but the initial thought is that it would be a bigger change than adding a bool. Though I prefer the latter, as it is less ambiguous.

What do you think? Honestly, whether it's none, the former or the latter. It doesn't really matter, I'll refactor if you like the idea.

@djc
Copy link
Collaborator

djc commented Feb 22, 2021

I like the idea of refactoring into Field and Const if you're up for it!

@vallentin
Copy link
Collaborator Author

I assume you just want me to continue in this PR?

But yeah, I'll do it. I'll have time tonight or tomorrow.

@djc
Copy link
Collaborator

djc commented Feb 22, 2021

I don't mind whether you want to do it here or start a new PR for it -- I haven't actually looked at this one yet, so feel free to do what is easiest for you.

@vallentin
Copy link
Collaborator Author

Ah, in that case, just review this when you have time. Then I'll make a new PR after refactoring Var into Field and Const.

@djc djc merged commit bfeaf5d into main Feb 22, 2021
@delete-merged-branch delete-merged-branch bot deleted the option branch February 22, 2021 12:50
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 this pull request may close these issues.

2 participants