1
0
Fork
You've already forked nibble
0
No description
  • Gleam 100%
2026年07月06日 18:57:50 +02:00
.github/workflows 🔧 Update release action. 2025年07月29日 07:41:26 +01:00
docs Remove io.debug usage ( #27 ) 2025年07月26日 19:05:18 +01:00
src ♻️ Replace deprecated result.then call with result.try 2025年07月29日 07:39:30 +01:00
test ♻️ Fix deprecations for new gleam_stdlib ( #21 ) 2024年12月27日 10:40:11 +01:00
.gitignore 🎉 Initialise gleam project. 2022年07月17日 02:48:31 +01:00
gleam.toml Update deps 2026年07月06日 18:57:50 +02:00
LICENSE 🎉 Initialise gleam project. 2022年07月17日 02:48:31 +01:00
manifest.toml Update deps 2026年07月06日 18:57:50 +02:00
README.md Update deps 2026年07月06日 18:57:50 +02:00

nibble

Temporary fork from https://github.com/hayleigh-dot-dev/nibble for deps update.

A lexer and parser combinator library inspired by elm/parser.

Package Version Hex Docs

This project is written in pure Gleam so you can use it anywhere Gleam runs: Erlang, Elixir, Node, Deno, and the browser!

Quick start

If you just want to get a feel for what nibble can do, check out the example below.

importgleam/option.{None,Some}importnibble.{do,return}importnibble/lexertypePoint{Point(x:Int,y:Int)}typeToken{Num(Int)LParenRParenComma}pubfnmain(){// Your lexer knows how to take an input string and
// turn it into a flat list of tokens. You define the
// type of token you want to use, but nibble will wrap
// that up in its own `Token` type that includes the
// source span and original lexeme for each token.
letlexer=lexer.simple([lexer.int(Num),lexer.token("(",LParen),lexer.token(")",RParen),lexer.token(",",Comma),// Skip over whitespace, we don't care about it!
lexer.whitespace(Nil)|>lexer.ignore,])// Your parser(s!) know how to transform a list of
// tokens into whatever you want. You have the full
// power of Gleam here, so you can go wild!
letint_parser={// Use `take_map` to only consume certain kinds of tokens and transform the
// result.
usetok<-nibble.take_map("expected number")casetok{Num(n)->Some(n)_->None}}letparser={use_<-do(nibble.token(LParen))usex<-do(int_parser)use_<-do(nibble.token(Comma))usey<-do(int_parser)use_<-do(nibble.token(RParen))return(Point(x,y))}letassertOk(tokens)=lexer.run("(1, 2)",lexer)letassertOk(point)=nibble.run(tokens,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.