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

Improve Level API a bit #31

Merged
merged 1 commit into from
Jun 24, 2024

Conversation

GuillaumeGomez
Copy link
Contributor

Part of #30.

It already improves the situation a bit. Not sure if the rest is worth improving or not though.

fn nest<'b, T, F: FnMut(&'b str) -> ParseResult<'b, T>>(
&self,
i: &'b str,
mut callback: F,
Copy link
Collaborator

Choose a reason for hiding this comment

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

F can be FnOnce. Currently that does not matter, but maybe we refactor the parser code later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!

i: &'b str,
mut callback: F,
) -> ParseResult<'b, T> {
let prev_level = self.level.get();
let (_, level) = self.level.get().nest(i)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could directly call prev_level.nest(i).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed!

Comment on lines -93 to -96
let (i, _) = s.nest(j)?;
let result = func(i, s);
s.leave();
let (i, node) = result?;
Copy link
Collaborator

@Kijewski Kijewski Jun 23, 2024

Choose a reason for hiding this comment

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

It is much clearer what is going on with your change, and the code does look much more nom-like. Clear advancement!

@GuillaumeGomez
Copy link
Contributor Author

GuillaumeGomez commented Jun 23, 2024

There is still the original Level. I'm still wondering if nest should return a non-Copy type which would contain a mutable reference to the calling Level or something along the line. Really not clear about it...

Something for later on. :)

@GuillaumeGomez
Copy link
Contributor Author

Fixed CI. :)

@Kijewski Kijewski merged commit 78878f0 into rinja-rs:master Jun 24, 2024
17 checks passed
@GuillaumeGomez GuillaumeGomez deleted the improve-level-api branch June 24, 2024 22:27
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