FastParse: small, fast, easy to use parser combinators in Scala

302 views
Skip to first unread message

Haoyi Li

unread,
May 10, 2015, 7:48:09 PM5/10/15
to scala-user
I just published http://lihaoyi.github.io/fastparse, which is a parser combinator library that is:

- Fast (1/10 to 1/5 the speed of hand-written, v.s. 1/500 of scala-parser-combinators)
- Easy to use (no magic macros, standard method names e.g. map/flatMap, small set of symbolic operators)
- Completely standalone (no heavy dependencies e.g. parboiled2 depending on Shapeless) and <1000LOC
- Runs on both Scala-JVM and Scala.js

It comes with built-in example parsers for simple arithmetic, JSON, and Scala (which naturally contains a parser for XML too!)

If you've ever looked at scala-parser-combinators and found it lacking, or looked at Parboiled2 and found it hard to use, give FastParse a try ^_^

Alvaro Carrasco

unread,
May 11, 2015, 8:32:32 PM5/11/15
to Haoyi Li, scala-user
Wow. Looks great. Will try it out.

Alvaro

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alec Zorab

unread,
May 12, 2015, 7:44:37 AM5/12/15
to Alvaro Carrasco, Haoyi Li, scala-user
Haoyi,

Thanks for this, it's a great library and a please to use. However. I'm getting some slightlyodd types come out of the ~ operator - see (https://gist.github.com/AlecZorab/e9b4360c033bbdae75f9) for an example. Is this expected or should I file a bug?

Regards,
Alec

Haoyi Li

unread,
May 12, 2015, 10:34:22 AM5/12/15
to Alec Zorab, Alvaro Carrasco, scala-user
lol, I knew someone would bump into that, I didn't know it would be this soon! That's a consequence of the tuple extenders only going up to 8


Perhaps you could send a PR to make them longer? Or even make it code-generated...

Someday we'll have HLists, but for now duplicating this for every arity is the easiest thing to do

Alec Zorab

unread,
May 12, 2015, 12:27:52 PM5/12/15
to Haoyi Li, Alvaro Carrasco, scala-user
I'll have a look.

Rüdiger Klaehn

unread,
May 13, 2015, 5:44:19 AM5/13/15
to Haoyi Li, scala-user
This looks very good. Looks like a good replacement replacement for
parser-combinators.

The documentation does not say anything about thread safety. And it is
using mutable state under the hood. So is the high level API
thread-safe?

Cheers,

Rüdiger

Haoyi Li

unread,
May 13, 2015, 11:02:35 AM5/13/15
to Rüdiger Klaehn, scala-user
It's totally thread safe. Mutation is limited to every `parse` call, or during parser initialization. Once you get a Parser[T] back from the constructor, it's frozen and ready to use

William Harvey

unread,
May 21, 2015, 3:41:47 PM5/21/15
to scala...@googlegroups.com
Amazing work (again...) Haoyi!  Thank you very much for sharing this with the community.

Cheers,

William
Reply all
Reply to author
Forward
0 new messages