Skip to content

parseworks/parseworks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

150 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

parseWorks

Build parsers in Java with composable parser combinators. Use parseWorks to express grammars in code, get clear error messages, and keep your parsers fast and testable.

Key features

  • Compose parsers with a small set of powerful combinators.
  • Get precise, readable error messages for parse failures.
  • Write thread-safe code with immutable parsers and inputs.
  • Keep dependencies minimal (only JUnit in tests).
  • Avoid left-recursion pitfalls with built-in protection.
  • Detect infinite loops on empty input.

Install parseWorks

Requirements: Java 17 or higher.

Maven (latest release):

<dependency>
    <groupId>io.github.parseworks</groupId>
    <artifactId>parseworks</artifactId>
    <version>3.0.0</version>
    <scope>compile</scope>
</dependency>

Gradle:

repositories {
  maven { url 'https://central.sonatype.com/repository/maven/' }
}

dependencies {
  implementation 'io.github.parseworks:parseworks:3.0.0'
}

Write your first parser

Use parser combinators to build a simple addition parser:

import io.github.parseworks.parsers.Lexical;

import static io.github.parseworks.parsers.Numeric.*;

// Define a parser for a simple addition expression
Parser<Character, Integer> sum =
    Numeric.number.thenSkip(Lexical.chr('+')).then(number).map(Integer::sum);

    // Parse the input "1+2"
    int value = sum.parse(Input.of("1+2")).value();
assert value ==3;

    // Handle a parsing error
    String message = sum.parse(Input.of("1+z")).handle(
        success -> "Match: " + success,
        failure -> "Error: " + failure.error()
    );
// Example output contains: "Error: Parse error at line 1 position 3"

Learn more

License

parseWorks is available under the MIT License.

About

LLR(*) Parser Combinator-ish library to assist in building parsers in Java

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages