Commits

Anonymous committed 4219200

Add recursive-parser helper syntax

  • Participants
  • Parent commits 75c99ba

Comments (0)

Files changed (2)

  (author "Moritz Heidkamp")
  (category parsing)
  (license "BSD")
- (depends lazy-seq)
+ (depends lazy-seq latch)
  (test-depends test lazy-seq)
  (foreign-depends))
  repeated zero-or-more one-or-more
  any-of all-of none-of none-of*
  preceded-by followed-by enclosed-by
- as-string)
+ as-string recursive-parser)
 
 (import chicken scheme)
 
-(use data-structures lazy-seq srfi-1 srfi-14 extras)
+(use data-structures lazy-seq srfi-1 srfi-14 extras latch)
 
 (define ((result value) input)
   (cons value input))
   (sequence* ((parts parser))
     (result (apply conc (remove boolean? (flatten parts))))))
 
+(define-syntax recursive-parser
+  (syntax-rules ()
+    ((_ body ...)
+     (lambda ()
+       (lambda (input)
+         (let-once
+          ((parser (begin body ...)))
+          (parser input)))))))
+
 (define (->lazy-seq x)
   (cond ((lazy-seq? x) x)
         ((string? x) (list->lazy-seq (string->list x)))