Commits

Moritz Heidkamp  committed 372e292

Add convenience none-of* combinator

  • Participants
  • Parent commits 1b6fb6c

Comments (0)

Files changed (2)

File comparse.scm

  fail result item bind satisfies is char-seq maybe
  sequence sequence*
  repeated zero-or-more one-or-more
- any-of all-of none-of
+ any-of all-of none-of none-of*
  preceded-by followed-by enclosed-by
  as-string)
 
                 (result value)
                 (loop (cdr parsers)))))))
 
+(define (none-of* parser but . parsers)
+  (receive (but parsers) (car+cdr (reverse (cons* parser but parsers)))
+    (preceded-by (none-of parsers) but)))
+
 (define ((followed-by parser following . more-following) input)
   (and-let* ((value (parser input)))
     (let loop ((following (parser-list following more-following))

File tests/run.scm

     (test-parse #f parenthesized "(x/")
     (test-parse #f parenthesized "()")))
 
+(test-group "none-of"
+  (let ((not-xy (preceded-by (none-of (is #\x) (is #\y)) item)))
+    (test-parse #\a not-xy "a")
+    (test-parse #f not-xy "x")
+    (test-parse #f not-xy "y")))
+
+(test-group "none-of*"
+  (let ((not-xy (none-of* (is #\x) (is #\y) item)))
+    (test-parse #\a not-xy "a")
+    (test-parse #f not-xy "x")
+    (test-parse #f not-xy "y")))
+
 (test-exit)