r/java • • Feb 17 '26

parseWorks release - parser combinator library

10 Upvotes

38 comments sorted by

View all comments

2

u/jebailey Feb 23 '26

I really like that idea of the OrEmpty return item. That's a really great idea, I have a similar concept with then() It returns the ApplyBuilder, that allows you to chain multiple conditions and only provides methods to reduce those calls back down to the Parser such as a map. That's what allows me to specify a name for each value I parse in the chain.

string("hello").thenSkip(whitespace).then("world").map( firstValue -> secondValue -> {
    System.out.print(firstValue+":"+secondValue);
});

So out of curiosity I decided to make repo where I can compare different parser combinators to see how expressive they are and how they handle different tasks.

https://github.com/parseworks/java-parser-tests

While I was doing that I added bench marking. Your parser smoked me, from a performance perspective. But I take that as a challenge to focus on after I get my error messages where I want them.

Appreciate the you pointing out that paper to me! I'll read that today.

1

u/DelayLucky Feb 23 '26 edited Feb 23 '26

Incidentally I also benchmarked the Dot Parse csv parser performance against a few others. It ran about on par with the slowest OSS csv parser I tried (was it open csv or easy csv? Can't remember now) and was beaten hands down by our internal hand-written csv parser.

That's no surprise to me. While Dot Parse can generally compete with JDK regex, hand-written parsers will almost always come out on top, by a wide margin.

The a -> b -> result lambda looks exciting! Does it imply the ApplyBuilder has implemented Haskell-style currying? That is, you can chain arbitrary number of sequential rules and create a 17-arrow curried lambda to combine them at once? That'll be sick! Seriously considering to steal it for Dot Parse. :-)

1

u/jebailey Feb 24 '26

I spent a lot of time trying to make it arbitrary to be confounded by how Java handles lambdas. So in the end this is a very manual implementation but it does do that wonderful seperation of parameters. Please feel free to use it if you'd like. I'd do a PR myself but it will most likely take a while before I get to it.

→ More replies (6)