Glindo

Package Version
Hex Docs

Glindo is a functional parser-combinator library for Gleam that makes it easy to build powerful, composable parsers for context-free grammars: JSON, CSV, small DSLs, YAML, and more. Glindo uses familiar FP abstractions—functors, monads, lazy evaluation—to thread parsing state and errors in a purely functional way.


🔑 Key Features


📦 Installation

gleam add glindo

In your gleam.toml

[dependencies] glindo = “>= 1.0.0”

🚀 Quick Start

import glindo/parser
import glindo/types
import glindo/csv   
import glindo/json

pub fn main() {
  // Parse CSV
  let csv_text = "name,age\nAlice,30\nBob,25"
  case P.run(glindo.csv(), csv_text) {
    Ok(T.ParseResult(csv, _, _)) ->
      io.println("Parsed CSV: \(inspect(csv))")
    Error(err) ->
      io.println("CSV parse error: \(err)")
  }

  // Parse JSON
  let json_text = "{\"foo\": [1, 2, 3], \"bar\": true}"
  case glindo.parse_json(json_text) {
    Ok(value) ->
      io.println("Parsed JSON: \(inspect(value))")
    Error(err) ->
      io.println("JSON parse error: \(err)")
  }
}

📚 Core API Overview

CombinatorType SignatureDescription
map(Parser(a), fn(a) -> b) -> Parser(b)Transform parsed result
bind(Parser(a), fn(a) -> Parser(b)) -> Parser(b)Sequence two parsers
seq_ofList(Parser(a)) -> Parser(List(a))Run parsers in order; fail if any fails
chc_ofList(Parser(a)) -> Parser(a)Try parsers until one succeeds
chc_optList(Parser(a)) -> Parser(a)Greedy choice: pick the one that consumes the most input
mny_ofParser(a) -> Parser(List(a))Zero-or-more repetition
mny_chcList(Parser(a)) -> Parser(List(a))Zero-or-more choice
opt_ofParser(a) -> Parser(Option(a))Optional parser
sep_by(Parser(a), Parser(b)) -> Parser(List(a))Parse a list separated by a delimiter
btwn(Parser(a), Parser(b), Parser(c)) -> Parser(b)Between two delimiters
peek_fwdParser(a) -> Parser(a)Look ahead without consuming input
lazy(fn() -> Parser(a)) -> Parser(a)Deferred parser for recursion
tokParser(a) -> Parser(a)Skip leading/trailing whitespace around a parser

See the HexDocs API Reference for full details and examples.

🛠️ Development

Glindo is under active development. To run tests and play with the library locally:

git clone https://github.com/daniel-shunom/glindo.git
cd glindo
gleam run     # Run examples or REPL
gleam test    # Execute the test suite

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b my-feature)
  3. Write tests for new functionality
  4. Submit a pull request

Please follow the Gleam style guide and include documentation comments for any new public API.

📄 License

This project is released under the Apache License. Feel free to use, modify, and distribute as you see fit.

📞 Contact Information

If you’d like to reach out, feel free to connect via:

Search Document