Commits

Anonymous committed ab2bb5e

Add preceded-by

  • Participants
  • Parent commits 8f7eca7

Comments (0)

Files changed (1)

File comparse.scm

 (parse 
  fail result item bind satisfies is char-seq maybe
  sequence sequence*
- repeatedly zero-or-more one-or-more
- any-of none-of last-of followed-by
+ repeated zero-or-more one-or-more
+ any-of none-of last-of 
+ preceded-by followed-by
  as-string)
 
 (import chicken scheme)
 
-(use data-structures lazy-seq srfi-14 extras)
+(use data-structures lazy-seq srfi-1 srfi-14 extras)
 
 (define ((result value) input)
   (cons value input))
          (or ((car parsers) input)
              (loop (cdr parsers))))))
 
-;; skipping-over, finally, preceded-by
+(define ((none-of parser . parsers) input)
+  (let loop ((parsers (cons parser parsers)))
+    (if (null? parsers)
+        (cons #t input)
+        (and (not ((car parsers) input))
+             (loop (cdr parsers))))))
+
 (define (last-of parser . parsers)
   (let loop ((parsers (cons parser parsers)))
     (bind (car parsers)
                 (result value)
                 (loop (cdr parsers)))))))
 
-(define ((none-of parser . parsers) input)
-  (let loop ((parsers (cons parser parsers)))
-    (if (null? parsers)
-        (cons #t input)
-        (and (not ((car parsers) input))
-             (loop (cdr parsers))))))
+(define (preceded-by parser preceeding . more-preceeding)
+  (let loop ((preceeding (cons preceeding more-preceeding)))
+    (bind (car preceeding)
+          (lambda (value)
+            (if (null? (cdr preceeding))
+                parser
+                (loop (cdr preceeding)))))))
 
 (define ((followed-by parser following) input)
   (let ((value (parser input)))