jom

Kotlin/JVM parser combinator library

License

License

GroupId

GroupId

io.yegair.jom
ArtifactId

ArtifactId

jom
Last Version

Last Version

0.0.1-alpha.7
Release Date

Release Date

Type

Type

module
Description

Description

jom
Kotlin/JVM parser combinator library
Project URL

Project URL

https://github.com/Yegair/jom
Source Code Management

Source Code Management

https://github.com/Yegair/jom

Download jom

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.21

runtime (1)

Group / Artifact Type Version
com.squareup.okio : okio jar 2.10.0

Project Modules

There are no modules declared in this project.

jom

jom is a Kotlin/JVM parser combinator library. It is heavily inspired by the great Rust library nom.

Documentation

Installation

Add a dependency to jom. Have a look at the GitHub Releases for the most recent version.

Gradle

repositories {
    mavenCentral()
}

dependencies {
    implementation("io.yegair.jom:jom:$jomVersion")
}

Maven

<dependency>
  <groupId>io.yegair.jom</groupId>
  <artifactId>jom</artifactId>
  <version>${jom.version}</version>
</dependency>

Write a Parser

For more detailed examples have a look at the docs.

val camelCase =
  // map applies a single parser and then maps its output
  // by applying a custom function
  map(
    // pair applies two parsers in sequence and returns
    // their result as a Kotlin Pair
    pair(
      // satisfy1 reads one or more UTF-8 code points that match
      // a given predicate and returns a string containing all
      // matched code points
      satisfy1 { cp, _ -> cp.isLowerCase() },
      // many0 applies a parser zero or more times until it no longer matches
      // it then returns a list containing all results in order
      many0(
        // the second parameter given to satisfy1 is the index
        // of the codepoint within the current parser invocation
        satisfy1 { cp, index ->
          when (index) {
            0 -> cp.isUpperCase()
            else -> cp.isLowerCase()
          }
        }
      )
    )
  ) { (first, rest) ->
    // first is the result of the first satisfy1 parser
    // rest is the result of the many0 parser
    listOf(first) + rest
  }

Versions

Version
0.0.1-alpha.7
0.0.1-alpha.6
0.0.1-alpha.5
0.0.1-alpha.4
0.0.1-alpha.3