parsec

A Parsec-style parser combinator library for Carp.

Parser is a closure-in-struct holding a run function over an input string and a position cursor. Build parsers from primitives (byte, satisfy, string, ...), combine them with map, seq, alt, many, and friends, and run with parse.

Backtracking follows Parsec semantics: alternation only retries when the left branch fails without consuming. Wrap with try for full backtracking.

Quick start

(load "git@github.com:carpentry-org/parsec@0.1.0")

(let [p (Parser.between (Parser.byte \[)
                        (Parser.byte \])
                        (Parser.Lexer.integer))]
  (match (Parser.parse p "[42]")
    (Result.Success n) (println* &n)
    (Result.Error e)   (IO.errorln &(Parser.format-error &e))))

Modules

Guides