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

Introducing cats-parse #3855

Merged
merged 8 commits into from Nov 17, 2020
Merged

Introducing cats-parse #3855

merged 8 commits into from Nov 17, 2020

Conversation

rossabaker
Copy link
Member

HttpVersion is not a particularly interesting class to parse, but I'm going to bikeshed it while we're setting precedent.

@rossabaker rossabaker added this to In progress in Dotty cross-compilation via automation Nov 13, 2020
Copy link
Member Author

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

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

Spamming the cats-parse contributors, who might be interested in early usage. Thanks, and unsubscribe button is on your right. 😄

/cc @johnynek @regadas @Slakah @stephenjudkins @zmccoy @non @mpilquist

new Parser(s).HttpVersion.run()(Parser.DeliveryScheme.Either).leftMap { _ =>
ParseFailure("Invalid HTTP version", s"$s was not found to be a valid HTTP version")
parser.parseAll(s).leftMap { case e =>
ParseFailure("Invalid HTTP version", e.toString)
Copy link
Member Author

Choose a reason for hiding this comment

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

Is there a general pretty printer for Error? Is such a thing possible? We didn't offer much detail in the parboiled implementation, and don't have to here. Just exploring what's possible.

Choose a reason for hiding this comment

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

There is not. The expectations are sorted but there isn't much pretty about it. I have some utilities for this in bosatsu I can pull out (mostly about pointing at the part of the string that failed). That would be good to add to cats-parse.

core/src/main/scala/org/http4s/HttpVersion.scala Outdated Show resolved Hide resolved
core/src/main/scala/org/http4s/HttpVersion.scala Outdated Show resolved Hide resolved
new HttpVersion(major.toInt, minor.toInt)
}
}
private val parser: Parser1[HttpVersion] = {
Copy link
Member Author

Choose a reason for hiding this comment

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

Some of our parsers have existed on the companion of what they're parsing so they can access a private constructor after validation. It prevents a private [http4s] unsafeFromVersion(Int, Int).

Do we like this pattern or no? The lack of inheritance perhaps makes it more palatable than it was.

Copy link
Contributor

Choose a reason for hiding this comment

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

I use this pattern in internal libs a lot, and have found it quite useful.

Copy link
Member Author

Choose a reason for hiding this comment

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

As long as we have no circular dependencies between parsed types, I like it, too. No way to construct an invalid one outside this compilation unit.

Comment on lines +90 to +92
mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[MissingClassProblem]("org.http4s.HttpVersion$Parser"),
),
Copy link
Member Author

Choose a reason for hiding this comment

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

We have four options here:

  1. Deprecate this, and leave dead code in Dotty that would explode.
  2. Deprecate and move to a scala-2 directory. We'd need an HttpVersionCompat mixin.
  3. Remove it and grant MiMa exceptions as necessary.
  4. Surrender and call this branch 0.22, which might be necessary anyway.

On Gitter, @ChristopherDavenport and I overlapped on choice 3, so I'm pursuing that here. None of these choices are happy, so inviting more feedback.

Copy link
Member

Choose a reason for hiding this comment

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

3 or 4 seems like the way to go to me.

Copy link
Member Author

Choose a reason for hiding this comment

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

I was in favor of 2 or 3, and Chris liked 3 or 4.

I think the thing that may force an 0.22 is several integrations not publishing for Dotty (e.g. Play, Twirl), so we have to split up the repo, and therefore the release cycles.

@rossabaker
Copy link
Member Author

Going to retarget this for the dotty branch. It works on series/0.21, but we don't want to introduce an 0.x core dependency there that doesn't materially improve users' lives. This is motivated by Dotty, so let's aim for a series of small PRs to that branch and divvy the work among the interested.

@rossabaker rossabaker changed the base branch from series/0.21 to dotty November 14, 2020 02:52
@rossabaker rossabaker marked this pull request as ready for review November 14, 2020 04:38
Comment on lines +96 to +99
val genNonTchar = frequency(
4 -> oneOf(Set(0x00.toChar to 0x7f.toChar: _*) -- tchars),
1 -> oneOf(0x100.toChar to Char.MaxValue)
)
Copy link
Member Author

Choose a reason for hiding this comment

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

Something like this turns out to be a much more interesting generator than extended charsets in a lot of HTTP parsing cases. We could make some considerable improvements throughout this file.

@rossabaker
Copy link
Member Author

I think we've laid down some good patterns here, and I'd like to get this merged and keep chipping away at individual parsers before this grows out of control.

@rossabaker rossabaker merged commit 9445afd into dotty Nov 17, 2020
Dotty cross-compilation automation moved this from In progress to Done Nov 17, 2020
@rossabaker rossabaker deleted the cats-parse branch November 17, 2020 15:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

4 participants