/gleam-nibble

A string parsing library heavily inspired by elm/parser.

Primary LanguageGleamMIT LicenseMIT

nibble

Package Version Hex Docs

A string parsing library heavily inspired by elm/parser.

Quick start

import gleam/function
import nibble.{ Parser }

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

pub fn main () {
    let parser = 
        nibble.succeed(function.curry2(Point))
            |> nibble.drop(nibble.grapheme("("))
            |> nibble.drop(nibble.spaces())
            |> nibble.keep(nibble.int())
            |> nibble.drop(nibble.spaces())
            |> nibble.drop(nibble.grapheme(","))
            |> nibble.drop(nibble.spaces())
            |> nibble.keep(nibble.int())
            |> nibble.drop(nibble.spaces())
            |> nibble.drop(nibble.grapheme(")"))

    assert Ok(point) = nibble.run("(1, 2)", parser)

    point.x //=> 1
    point.y //=> 2
}

Installation

If available on Hex this package can be added to your Gleam project:

gleam add nibble

and its documentation can be found at https://hexdocs.pm/nibble.