This is an automated archive made by the Lemmit Bot.

The original was posted on /r/opensource by /u/WellFoundedCake on 2025-11-10 11:00:15+00:00.


Hideo, r/opensource!

last time I shared my open source project Jar Jar Parse (or jjparse for short), a parser combinator library for Java. The feedback was … let’s say, polite silence. So I figured: maybe what’s missing isn’t another “I made this”-post, but a real example.

Parsing in Java usually means ANTLR (or, if you’re from the old school like me, CUP), or just a home-grown mess of recursive descent and regex soup. I wanted something that feels like Scala’s parser combinators, but in Java: readable, type-safe, zero code generation and full IDE support.

So here’s how to build a small config parser in a few lines of plain Java using only jjparse:

Parser<String> key = regex("[a-zA-Z_][a-zA-Z_0-9_]*");

Parser<String> value = regex("[^\n]*");

Parser<Product<String, String>> line =
  key.keepLeft(literal("=")).and(value);

Parser<Map<String, String>> config =
  line.repeat().map(lines -> lines.stream().collect(
    Collectors.toMap(Product::first, Product::second)
  ));

Some highlights:

  • Parsers are type-safe; they are generic in their input and their output type!
  • The input type is fixed for the whole class, so we don’t need to provide it multiple times
  • There is a special support for character parsing, which handles unicode positions and whitespace gracefully
  • There are no additional dependencies besides JUnit and Maven plugins

Jar Jar Parse is for anyone who has ever thought:

“ANTLR is overkill, but regex make my eyes bleed.”

I’d love to hear your thoughts, feedback, ideas, PRs, or just your favorite Star Wars memes!

Mesa parse now!