AtlatestRenderedmarkdown
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 testLicense
BSD-3-Clause