A simple parser combinator library
Initially built while trying to learn Gleam and Parser Combinators using The YouTube Series by Low Byte Productions and Understanding Parser Combinators
The project exposes the following modules:
parz.- contains therunmethod which is used for executing a parserparz/combinators- the parser combinator librarypars/parsers- some simple, primitive parsers
gleam add parzimport parz.{run}
import parz/combinators.{map, separator}
import parz/parsers.{regex, str}
type Path {
Path(List(String))
}
// parsers are defined at the top level to ensure recursion is
// possible if needed
fn segment() {
// a parser can be made with a pre-defined base parser from `parz/parsers`
regex("\\w+")
}
// a more complex parser can be defined by combining other parsers from `parz/combinators`
fn parser() {
separator(segment(), str("/")) |> map(Path)
}
pub fn main() {
let result = "my/example/path" |> run(parser())
// do something with the parsed output
}For more examples see the
testdirectory
Further documentation can be found at https://hexdocs.pm/parz.
gleam run # Run the project
gleam test # Run the tests
gleam shell # Run an Erlang shell