Version0.9.2Verifiednot yet verifiedLicenseBSD-3-Clause

sigil-peg

PEG parsing expression grammar library

Report a bug or suggest a feature
Readme

sigil-peg

PEG (Parsing Expression Grammar) library for Sigil. Represent patterns as S-expressions with a capture stack for structured output. Inspired by Janet's PEG module.

Usage

(import (sigil peg))

;; Match a literal string
(peg/match '(seq "hello" " " "world") "hello world")
; => #<peg-match 0..11 ()>

;; Capture matched text
(peg-match-captures (peg/match '(<- (* (char-set char-alphabetic?))) "hello"))
; => ("hello")

;; Define a grammar with named rules
(define-grammar csv
  (main (* (seq 'field (? (seq "," 'field)) 'newline))
  (field (<- (+ (! ",") (! "\n") any-char)))
  (newline (/ "\n" (input-end))))

Pattern Language

  • Atomic: "literal", #\char, 'rule-ref, any-char, (char-range #\a #\z), (char-set char-alphabetic?)
  • Combinators: (seq p ...), (/ p ...), (* p), (+ p), (? p), (! p), (& p), (to p), (thru p), (between min max p)
  • Captures: (<- p), (<- p tag), (group p), (position), (constant val), (cmt p fn), (drop p), (backref tag), (replace p val)
  • Anchors: (line-start), (line-end), (input-start), (input-end)

Dependencies

  • sigil-stdlib

Build

sigil build
sigil test

License

BSD-3-Clause

Clone

$ git clone https://codeberg.org/sigil/sigil-peg

Releases

v0.9.2 — latest by version, released 19 Jul 2026

All releases — 2 tags in this repository.

Source

Browse the latest source

One page per file, and every line has a permalink.

Recent commitsAtom

The last 20 commits keep a page here. Everything older lives in the clone.