com-lihaoyi / fastparse

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

Allow failure within a map call #28

Closed nrinaudo closed 9 years ago

nrinaudo commented 9 years ago

There are some cases where we need to fail gracefully within a map call. As an example, I have some code that parses a charset name and needs to turn it into an instance of java.nio.charset.Charset. The name itself might be valid syntactically but not actually be the name of a valid Charset, which I can only discover in the map call.

I think what I'm really asking for is for is for map to be able to return a failing parser - that is, for Parser to have a flatMap method.

lihaoyi commented 9 years ago

Do you mean something like https://github.com/lihaoyi/fastparse/blob/master/fastparse/shared/src/main/scala/fastparse/ParserApi.scala#L67-L71

nrinaudo commented 9 years ago

I'm terribly sorry, I appear to be using an out-of-date version (0.3.0) in which it was not yet implemented. Apologies, I should have looked at the most recent source.

lihaoyi commented 9 years ago

No problem :) On Jun 16, 2015 6:41 PM, "Nicolas Rinaudo" notifications@github.com wrote:

I'm terribly sorry, I appear to be using an out-of-date version (0.3.0) in which it was not yet implemented. Apologies, I should have looked at the most recent source.

— Reply to this email directly or view it on GitHub https://github.com/lihaoyi/fastparse/issues/28#issuecomment-112365353.

nrinaudo commented 9 years ago

As a side note, it's a bit confusing that the more recent version is 0.1.7, but there's a 0.3.0 version available in Maven.

Granted, if one follows your (well written) instructions, there is no problem, but it confuses tools such as sbt-updates (and people like who follow such tools blindly).

FranklinChen commented 9 years ago

I just encountered this version confusion before figuring out there really shouldn't be 0.3.0 out there.