com-lihaoyi / fastparse

Writing Fast Parsers Fast in Scala
https://com-lihaoyi.github.io/fastparse
MIT License
1.09k stars 164 forks source link

Make Whitespace a proper trait rather than function to avoid unwanted implicit conversions #272

Closed lihaoyi closed 1 year ago

lihaoyi commented 1 year ago

Fixes https://github.com/com-lihaoyi/fastparse/issues/261, which is caused by the whitespace P[_] => P[Unit] implicits firing as implicit conversions rather than the implicit parameters they were originally intended to be. Since whitespace is meant to ignore failures, this caused failures caused by the Fail.! : P[String] to be ignored when implicitly converted to P[Unit]

The fix is to create a proper Whitespace trait to inherit from.

Note that this is a binary incompatible change. It's stacked on top of https://github.com/com-lihaoyi/fastparse/pull/271 for convenience, but should probably land separately after. The relevant changes are in this commit https://github.com/com-lihaoyi/fastparse/pull/272/commits/d87ab6d9de062ec1e0bbf897643cefef7cd03338 if anyone wants to look.

Note that I moved the custom whitespace tests to a scala2.12+ folder to skip them on 2.11. 2.11 does not support SAM conversion, which makes defining custom whitespaces a lot more boilerplatey. Can still be done, but no need to burden everyone with boilerplatey examples just to cater for the 2.11 folks in the test suite. Things are unlikely to break just for 2.11 anyway

lihaoyi commented 1 year ago

@lefou @lolgab if we expect the next version of Fastparse to be 3.0.0, then I'll merge this to get the bincompat breakage in before the version bump

lefou commented 1 year ago

Can you rebase this PR on top of #271, please?

lihaoyi commented 1 year ago

@lefou should already be rebased

lefou commented 1 year ago

@lefou should already be rebased

I meant on top of master branch.

lihaoyi commented 1 year ago

@lefou I squashesd it on top of latest master, we can use the Squash and Merge button to make sure the PR description is used on the final commit that ends up in master