Commits

Anonymous committed 0e73065

Add all-of combinator

Comments (0)

Files changed (2)

  fail result item bind satisfies is char-seq maybe
  sequence sequence*
  repeated zero-or-more one-or-more
- any-of none-of last-of 
+ any-of all-of none-of last-of
  preceded-by followed-by
  as-string)
 
          (or ((car parsers) input)
              (loop (cdr parsers))))))
 
+(define ((all-of parser . parsers) input)
+  (let loop ((parsers (cons parser parsers)))
+    (and-let* ((value ((car parsers) input)))
+      (if (null? (cdr parsers))
+          value
+          (and value (loop (cdr parsers)))))))
+
 (define ((none-of parser . parsers) input)
   (let loop ((parsers (cons parser parsers)))
     (if (null? parsers)
                                      (zero-or-more (is #\space)))
                            min: 2)
                "ho    ho ho rofl"))
+
+(test-group "all-of"
+  (test-parse #\b (all-of (none-of (is #\a)) (is #\b)) "b")
+  (test-parse #f (all-of (none-of (is #\a)) (is #\b)) "a"))