Commitfbf504dbRecorded31 Mar 2026Repositorysigil-peg

Add README

Changed
 README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)
Diff
README.mdadded
@@ -0,0 +1,45 @@
+1
# sigil-peg
+2
+3
PEG (Parsing Expression Grammar) library for [Sigil](https://codeberg.org/sigil/sigil). Represent patterns as S-expressions with a capture stack for structured output. Inspired by Janet's PEG module.
+4
+5
## Usage
+6
+7
```scheme
+8
(import (sigil peg))
+9
+10
;; Match a literal string
+11
(peg/match '(seq "hello" " " "world") "hello world")
+12
; => #<peg-match 0..11 ()>
+13
+14
;; Capture matched text
+15
(peg-match-captures (peg/match '(<- (* (char-set char-alphabetic?))) "hello"))
+16
; => ("hello")
+17
+18
;; Define a grammar with named rules
+19
(define-grammar csv
+20
(main (* (seq 'field (? (seq "," 'field)) 'newline))
+21
(field (<- (+ (! ",") (! "\n") any-char)))
+22
(newline (/ "\n" (input-end))))
+23
```
+24
+25
## Pattern Language
+26
+27
- **Atomic:** `"literal"`, `#\char`, `'rule-ref`, `any-char`, `(char-range #\a #\z)`, `(char-set char-alphabetic?)`
+28
- **Combinators:** `(seq p ...)`, `(/ p ...)`, `(* p)`, `(+ p)`, `(? p)`, `(! p)`, `(& p)`, `(to p)`, `(thru p)`, `(between min max p)`
+29
- **Captures:** `(<- p)`, `(<- p tag)`, `(group p)`, `(position)`, `(constant val)`, `(cmt p fn)`, `(drop p)`, `(backref tag)`, `(replace p val)`
+30
- **Anchors:** `(line-start)`, `(line-end)`, `(input-start)`, `(input-end)`
+31
+32
## Dependencies
+33
+34
- sigil-stdlib
+35
+36
## Build
+37
+38
```sh
+39
sigil build
+40
sigil test
+41
```
+42
+43
## License
+44
+45
BSD-3-Clause