AtlatestRepositorysigil-peg
1
# sigil-peg3
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.5
## Usage7
```scheme8
(import (sigil peg))10
;; Match a literal string11
(peg/match '(seq "hello" " " "world") "hello world")12
; => #<peg-match 0..11 ()>14
;; Capture matched text15
(peg-match-captures (peg/match '(<- (* (char-set char-alphabetic?))) "hello"))16
; => ("hello")18
;; Define a grammar with named rules19
(define-grammar csv20
(main (* (seq 'field (? (seq "," 'field)) 'newline))21
(field (<- (+ (! ",") (! "\n") any-char)))22
(newline (/ "\n" (input-end))))23
```25
## Pattern Language27
- **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)`32
## Dependencies34
- sigil-stdlib36
## Build38
```sh39
sigil build40
sigil test41
```43
## License45
BSD-3-Clause