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

Add support for generics syntax in parser #317

Merged
merged 10 commits into from
Jan 22, 2025

Conversation

GuillaumeGomez
Copy link
Contributor

Extracted the parser generics support add from #311.

fn parse(i: &mut &'i str, level: Level<'_>) -> ParseResult<'i, WithSpan<'i, Self>> {
let start = *i;
(
ws(identifier_with_refs),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allows e.g. &&u32, but would fail for &&core::primitive::u32. I think we need to support paths in here. What do you think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't even think about it but I agree.

@Kijewski
Copy link
Collaborator

I made minor changes to keep track of the nesting level, so A<A<A<A<A<…>>>>>> won't cause problems.

@GuillaumeGomez
Copy link
Contributor Author

Funnily enough, I was thinking about this case the other day but it was late and I forgot afterwards. ^^'

@GuillaumeGomez
Copy link
Contributor Author

Anyway, gonna allow to have paths as generics tomorrow.

@Kijewski
Copy link
Collaborator

Oops, I didn't see that you answered immediately. I'll give the PR back to you, now. :)

node: Span<'_>,
) -> Result<DisplayWrap, CompileError> {
ensure_filter_has_no_generics(ctx, name, generics, node)?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a big fan because this call can (and will be) forgotten when we add new filters. I voluntarily moved this check outside of the function to special-case filters which actually were making use of generics so by default, all the others would error.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I don't think that the line get be forgotten. Without the line, the argument generics is unused, and rust will print a warning.

For functions like visit_filter() I like to use a clear dispatch pattern. The brains should be in the dispatch target functions, the dispatcher should be as stupid and as simple as possible. And because an unused argument would render a warning, I don't see any drawbacks in here.

But if you dislike this implementation very much, then I could live is an implementation with more logic inside the dispatcher, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a valid argument although I think centralizing checks when possible is a better approach. And also, sometimes you can just prepend with _ to do your things and forget about it later on (happened to me 😅).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, go ahead. 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeay. :D

But another day, tonight it's video game time. :)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hehe, have fun! :)

@GuillaumeGomez
Copy link
Contributor Author

Oops, I didn't see that you answered immediately. I'll give the PR back to you, now. :)

Oh no, less work for me. 😛

Just waiting for you to tell me what you think about my logic and if that sounds ok to you, I'll change the code and move the check in the "common filter path" instead.

@GuillaumeGomez
Copy link
Contributor Author

Sorry, it was meant for a fix I wrote on docs.rs. ^^'

@GuillaumeGomez
Copy link
Contributor Author

Applied the changes we talked about. I think we're good to go for this part?

Copy link
Collaborator

@Kijewski Kijewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the implementation looks fine. Thank you!

@Kijewski Kijewski merged commit 8253624 into rinja-rs:master Jan 22, 2025
36 checks passed
@GuillaumeGomez GuillaumeGomez deleted the generics branch January 23, 2025 09:36
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