Skip to content

[WIP] Config parsing #40

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

Closed
wants to merge 10 commits into from
Closed

[WIP] Config parsing #40

wants to merge 10 commits into from

Conversation

Byron
Copy link
Member

@Byron Byron commented Feb 1, 2021

Generally there will be many small commits and a lot of 'sketching' in an effort to try find good ways of doing things, and iterate until it feels right, before going into all kinds of depths and details.

Thus there should be the first steps of basic parsing along with some pieces of editing and (re-)serialisation of config files to jiggle the API into something ergonomic and idiomatic.

@Byron
Copy link
Member Author

Byron commented Feb 1, 2021

Hi @avitex,

I finally pulled myself together to face my fears: Write the git config parser using dangerous 😅. Of course this is a bit of a dramatisation as I hope you may find a moment to take a cursory look to call out my blunders if there are any :).

Thus I am super interested to hear what you think, and now I will go and point out a few places where I think I might be doing something wrong.

Thanks in advance ❤️

@@ -30,6 +30,15 @@ impl From<Span> for Range<usize> {
}
}

impl From<Range<usize>> for Span {
Copy link
Member Author

Choose a reason for hiding this comment

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

Since dangerous uses a Range<usize> I might just use this instead of an own version of ..=. Probably I had a reason to use an inclusive range in the first place, but it's not entirely clear to me right now what that was 🤦‍♂️.

let mut tokens = Vec::new();
skip_whitespace_or_comment(r, ConsumeTo::NextToken).map(|section| {
tokens.push(spanned::Comment(
dangerous::input(section)
Copy link
Member Author

Choose a reason for hiding this comment

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

In theory this conversion would have to be done for each token we parse here. Certainly this can be sugared up a bit more to feel less cluttered, but might also be a case for just using zc.
After all, the File type really is an zc type, owning data and keeping offsets into the data. The data will always be read into memory I think, so that would match too (as opposed to memory mapping them).

}
let parsed = r
.take_consumed(|r| skip_whitespace_or_comment(r, to_where))
.as_dangerous();
Copy link
Member Author

Choose a reason for hiding this comment

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

Here I thought there could be an as_dangerous_opt(), as I specifically avoided doing as_dangerous_non_empty().ok() probably due to a very premature optimization. Generally I like the _opt() versions of methods a lot.

}

#[must_use]
fn skip_whitespace_or_comment<'a, E>(r: &mut BytesReader<'a, E>, to_where: ConsumeTo) -> Option<&'a [u8]> {
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this was a little lazy, and this should really be refactored to not need the inner function. One would probably end up with something cloning the input, but… I don't actually know how to do this properly.

@avitex
Copy link

avitex commented Feb 1, 2021

Hey @Byron, awesome to see this! I'll check this out tonight and give you any feedback!

@Byron
Copy link
Member Author

Byron commented Feb 18, 2021

Note that this branch will be replaced with #44 when it exits that draft status.

@Byron Byron closed this Mar 13, 2021
@Byron Byron deleted the config-parsing branch August 27, 2021 08:42
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