Changeset 14701 in project


Ignore:
Timestamp:
05/19/09 05:13:47 (10 years ago)
Author:
Ivan Raikov
Message:

abnf release 1.2

Location:
release/4/abnf
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • release/4/abnf/abnf.scm

    r14692 r14701  
    4646          optional-sequence
    4747          set set-from-string
     48          bind drop consume collect
    4849          )
    4950
     
    173174(define char-set:quoted (char-set-complement (string->char-set "\\\"\r\n")))
    174175
    175 ;;;; Additional convenience procedures
     176;;;; Additional convenience procedures and parser combinators
    176177
    177178;; match any character from an SRFI-14 character set
     
    182183  (lex:set (string->char-set s)))
    183184
     185(define (bind f p)
     186  (lambda (s)
     187    (let ((s1 (p s)))
     188      (match (longest (p s))
     189             ((eaten food)
     190              (let ((x (f eaten)))
     191                (and x `((,x ,food)))))
     192             (else #f)))))
     193
     194(define (drop p) (bind (lambda (x) (list)) p))
     195
     196(define (consume p)
     197  (lambda (s)
     198    (let loop ((lst (list)) (rst s))
     199      (match (p rst)
     200             ((a rst)  (loop (cons a lst) rst))
     201             (else  (list (reverse lst) rst))))))
     202
     203(define ($ cs)
     204  (let loop ((cs cs) (ax (list)))
     205    (cond ((null? cs)         `(,ax))
     206          ((atom? (car cs))   (loop (cdr cs) (cons (car cs) ax)))
     207          (else               (cons ax cs)))))
     208
     209(define (collect . rest)
     210  (let-optionals rest ((label #f))
     211    (let ((make (if label (lambda (x) `(,label ,(car x))) car)))
     212      (lambda (x)
     213        (or (and (pair? x) (let ((x1 ($ x)))
     214                             (cons (make x1) (cdr x1)))) x)))))
     215
     216
    184217)
  • release/4/abnf/abnf.setup

    r14692 r14701  
    1717
    1818  ;; Assoc list with properties for your extension:
    19   '((version 1.1)
     19  '((version 1.2)
    2020    (documentation "abnf.html")
    2121    ))
Note: See TracChangeset for help on using the changeset viewer.