Package Version Hex Docs Erlang-compatible JavaScript-compatible

Pickle 🥒

A parser combinator library for Gleam that supports all targets.

Pickle’s API does heavily rely on pipelines, thus you can create powerful parsers by chaining multiple parsers together with the pipe operator. This is a stark contrast to other parser combinator libraries for Gleam, which are often built around the use expression.

Pickle enables scannerless recursive descent parsing, but this applies to almost every other parser combinator library.

Demo 🥒

import gleam/io
import gleam/string
import pickle.{type Parser}

type Point {
  Point(x: Int, y: Int)
}

fn new_point() -> Point {
  Point(0, 0)
}

fn point_parser() -> Parser(Point, Point, String) {
  pickle.string("(", pickle.drop)
  |> pickle.then(pickle.integer(fn(point, x) { Point(..point, x: x) }))
  |> pickle.then(pickle.string(",", pickle.drop))
  |> pickle.then(pickle.integer(fn(point, y) { Point(..point, y: y) }))
  |> pickle.then(pickle.string(")", pickle.drop))
}

pub fn main() {
  let assert Ok(point) =
    pickle.parse("(100,-25)", new_point(), point_parser())

  string.inspect(point) |> io.print() // prints "Point(100, -25)"
}

Changelog 🥒

Take a look at the changelog to get an overview of each release and its changes.

Contribution Guidelines 🥒

More information can be found here.

License 🥒

Pickle is licensed under the MIT license.

Search Document