Commits

Anonymous committed 35da6da

Allow a list to be passed to vararg functions alternatively

Comments (0)

Files changed (2)

            (lambda (binding)
              (sequence* (more-bindings ...) body ...))))))
 
+(define (parser-list parser more-parsers)
+  (if (and (list? parser) (null? more-parsers))
+      parser
+      (cons parser more-parsers)))
+
 (define ((sequence parser . parsers) input)
-  (let loop ((parsers (cons parser parsers))
+  (let loop ((parsers (parser-list parser parsers))
              (parts '())
              (input input))
     (if (null? parsers)
                (eq? (lazy-head input) (string-ref str pos))
                (loop (+ pos 1) (lazy-tail input)))))))
 
+;; Allow (any-of (list parser ...)) alternatively?
 (define ((any-of parser . parsers) input)
-  (let loop ((parsers (cons parser parsers)))
+  (let loop ((parsers (parser-list parser parsers)))
     (and (not (null? parsers))
          (or ((car parsers) input)
              (loop (cdr parsers))))))
 
 (define ((all-of parser . parsers) input)
-  (let loop ((parsers (cons parser parsers)))
+  (let loop ((parsers (parser-list 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)))
+  (let loop ((parsers (parser-list parser parsers)))
     (if (null? parsers)
         (cons #t input)
         (and (not ((car parsers) input))
              (loop (cdr parsers))))))
 
 (define (preceded-by parser . parsers)
-  (let loop ((parsers (cons parser parsers)))
+  (let loop ((parsers (parser-list parser parsers)))
     (bind (car parsers)
           (lambda (value)
             (if (null? (cdr parsers))
   (test-parse 3 (preceded-by (is 1) (is 2) (is 3)) '(1 2 3)))
 
 (test-group "sequence"
-  (test-parse* "ab" (sequence (is #\a) (is #\b)) "abc"))
+  (test-parse* "ab" (sequence (is #\a) (is #\b)) "abc")
+  (test-parse* "ab" (sequence (list (is #\a) (is #\b))) "abc"))
 
 (test-group "maybe"
   (let ((foo (preceded-by (maybe (is #\x)) (char-seq "foo"))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.