Skip to content

First take at removing HeaderError from YaccParser internals#554

Merged
ltratt merged 3 commits into
softdevteam:masterfrom
ratmice:grmtools_section_cleanup
Apr 20, 2025
Merged

First take at removing HeaderError from YaccParser internals#554
ltratt merged 3 commits into
softdevteam:masterfrom
ratmice:grmtools_section_cleanup

Conversation

@ratmice
Copy link
Copy Markdown
Collaborator

@ratmice ratmice commented Apr 17, 2025

This is a first take at removing the Location/Header error from the internals of Parser,
I haven't gone over the diff extremely carefully.

My original intent was to make Header generic on either Span or Location, and then use Header<Span> inside, and Header<Location> in CTParserBuilder and nimbleparse.

What I noticed though, that it was possible to do it without that change, by returning a Result<..., HeaderError> from what is essentially YaccParser::new rather than from parse where we currently return YaccGrammarErrors.

We absolutely could still make Header generic, the parsed header results all return Location::Span.
I thought it was worth noting this before I went ahead and did it, since the generic Span type permeates through both the errors, and the Value type.

Comment thread cfgrammar/src/lib/yacc/ast.rs Outdated
Comment thread cfgrammar/src/lib/yacc/parser.rs Outdated
Comment thread cfgrammar/src/lib/yacc/parser.rs Outdated
Comment thread nimbleparse/src/main.rs Outdated
Comment thread nimbleparse/src/main.rs Outdated
@ltratt
Copy link
Copy Markdown
Member

ltratt commented Apr 18, 2025

I think this one is ready now?

Comment thread cfgrammar/src/lib/yacc/grammar.rs Outdated
@ratmice
Copy link
Copy Markdown
Collaborator Author

ratmice commented Apr 18, 2025

I think it is ready, but I'd like to read through the patch more closely which I won't have time to do until tomorrow most likely.

// This is essentially a tuple that needs a newtype so we can implement `From` for it.
// Thus we aren't worried about it being `pub`.
#[derive(Debug, PartialEq)]
pub struct HeaderValue<T>(pub T, pub Value<T>);
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Likely needs #[doc(hidden)], and I should just go through the docs again, to ensure there isn't anything else I added that also needs it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I believe all the doc changes should be fixed across various commits,
this one in 7895675

@ratmice
Copy link
Copy Markdown
Collaborator Author

ratmice commented Apr 19, 2025

I did manage to get my self-review done before heading out which was mostly just documentation stuff,
but also hiding HeaderError from the public facing API, that allowed basically hiding the entire module from top-level.

I suppose I'm happy with this now, the public facing API seems good at least.

The callers/header building and what not seems like it could probably use some refinement,
but that all seems well within the scope of stuff that can be done as we come across things that can be improved (primarily error messages).

@ratmice ratmice marked this pull request as ready for review April 19, 2025 00:38
@ltratt
Copy link
Copy Markdown
Member

ltratt commented Apr 19, 2025

Please squash.

@ratmice ratmice force-pushed the grmtools_section_cleanup branch from 6cea97d to f32ddbb Compare April 19, 2025 20:41
@ratmice
Copy link
Copy Markdown
Collaborator Author

ratmice commented Apr 19, 2025

Is that alright? (It leaves the unwrap() in the first patch to avoid squashing those two fairly large patches together)

Edit: I suppose it would be nice if we moved the test movement/#[cfg(test)] to YaccGrammar to the first patch, but that is also changing the type of it's return value currently, so it would need some patch surgery.

Edit 2x: I guess it is at least worth a try.

ratmice added 3 commits April 19, 2025 14:22
This is an interim change which removes the `Header` parameter.
It also adds `FromStr` implementations for generating grammars
without first passing in a `YaccKind`.

This patch contains a few `unwrap` calls where we currently cannot convert
into the appropriate error return type. Which will be fixed in the next patch.
@ratmice ratmice force-pushed the grmtools_section_cleanup branch from f32ddbb to e5e3b65 Compare April 19, 2025 21:28
@ratmice
Copy link
Copy Markdown
Collaborator Author

ratmice commented Apr 19, 2025

I went ahead and switched moving the tests and added the FromStr implementation to the first patch
(modified to temporarily use HeaderError and unwrap)

That removes the #[cfg(test)] function entirely from the series, but that means adding a second call to unwrap in the first patch which then gets fixed in the second patch.

@ltratt
Copy link
Copy Markdown
Member

ltratt commented Apr 20, 2025

Is that alright? (It leaves the unwrap() in the first patch to avoid squashing those two fairly large patches together)

Yep!

@ltratt ltratt added this pull request to the merge queue Apr 20, 2025
Merged via the queue into softdevteam:master with commit 1627835 Apr 20, 2025
2 checks passed
@ratmice ratmice deleted the grmtools_section_cleanup branch April 20, 2025 07:37
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