Commit6c4c8fa3Recorded25 Feb 2026Repositorysigil-peg

Add specs to (sigil peg) and (sigil sxml)

Message
  • peg: 6 specs for match, find, find-all, replace, replace-all, match-text
  • sxml: 9 specs for html/xml conversion and element accessors
Changed
 src/sigil/peg.sgl | 6 ++++++
 1 file changed, 6 insertions(+)
Diff
src/sigil/peg.sglmodified
@@ -467,6 +467,7 @@
467
;;; ; => #<peg-match 0..5 ("hello")>
468
;;; ```
469
(define (peg/match grammar input . rest)
+470
(: any? string? integer? ... -> (maybe peg-match?))
471
(let* ((start (if (null? rest) 0 (car rest)))
472
(gram (normalize-grammar grammar))
473
(result (peg--parse 'main input start '() (list '()) gram)))
@@ -486,6 +487,7 @@
487
;;; ; => #<peg-match 6..11 ("world")>
488
;;; ```
489
(define (peg/find grammar input)
+490
(: any? string? -> (maybe peg-match?))
491
(let ((len (string-length input))
492
(gram (normalize-grammar grammar)))
493
(let loop ((pos 0))
@@ -507,6 +509,7 @@
509
;;; ; => (#<peg-match 0..5 ("hello")> #<peg-match 6..11 ("world")> ...)
510
;;; ```
511
(define (peg/find-all grammar input)
+512
(: any? string? -> list?)
513
(let ((len (string-length input))
514
(gram (normalize-grammar grammar)))
515
(let loop ((pos 0) (matches '()))
@@ -532,6 +535,7 @@
535
;;; ; => "abcXdef"
536
;;; ```
537
(define (peg/replace grammar replacement input)
+538
(: any? (any-of string? procedure?) string? -> string?)
539
(let ((m (peg/find grammar input)))
540
(if m
541
(let ((rep (if (procedure? replacement)
@@ -550,6 +554,7 @@
554
;;; ; => "aNbNcN"
555
;;; ```
556
(define (peg/replace-all grammar replacement input)
+557
(: any? (any-of string? procedure?) string? -> string?)
558
(let ((matches (peg/find-all grammar input))
559
(len (string-length input)))
560
(if (null? matches)
@@ -575,4 +580,5 @@
580
;;; ; => "hello"
581
;;; ```
582
(define (peg-match-text m input)
+583
(: peg-match? string? -> string?)
584
(substring input (peg-match-start m) (peg-match-end m)))))