Changeset 15805 in project


Ignore:
Timestamp:
09/09/09 05:29:42 (10 years ago)
Author:
Ivan Raikov
Message:

json-abnf now uses abnf-consumers

Location:
release/4/json-abnf
Files:
2 edited

Legend:

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

    r15783 r15805  
    1313        (import scheme chicken data-structures srfi-1 srfi-14)
    1414
    15         (require-library abnf)
    16         (import (prefix abnf abnf:) )
     15        (require-library abnf abnf-consumers)
     16        (import (prefix abnf abnf:)
     17                (prefix abnf-consumers abnf:)
     18                )
    1719
    1820
     
    2325    ((_ fn) (lambda args (apply fn args)))))
    2426
    25 ;; construct strings from consumed chars
    26 (define scollect (abnf:collect-chars list->string))
    27 
    28 ;; shortcut for (abnf:bind scollect (abnf:longest ... ))
    29 (define-syntax consumed->string
    30   (syntax-rules ()
    31     ((_ p)    (abnf:bind scollect (abnf:longest p)))
    32     ))
    33 
    34 (define-syntax consumed->symbol
    35   (syntax-rules ()
    36     ((_ p)    (abnf:bind (compose string->symbol scollect) (abnf:longest p)))
    37     ))
    38 
    39 (define-syntax consumed->number
     27;; construct numbers from consumed chars
     28(define consumed-chars->number
     29  (abnf:consumed-chars->list
     30   (compose string->number list->string)))
     31
     32;; shortcut for (bind consumed-chars->number (longest ... ))
     33(define-syntax bind-consumed->number
    4034  (syntax-rules ()
    4135    ((_ p)    (abnf:bind
    42                (abnf:collect-chars
    43                 (compose string->number list->string))
     36               consumed-chars->number
    4437               (abnf:longest p)))
    4538    ))
    4639
    47 (define-syntax consumed->char-code
     40(define consumed-chars->char-code
     41  (abnf:consumed-chars->list
     42   (compose (lambda (x) (string->number x 16))
     43            list->string)))
     44
     45(define-syntax bind-consumed->char-code
    4846  (syntax-rules ()
    4947    ((_ p)    (abnf:bind
    50                (abnf:collect-chars
    51                 (compose (lambda (x) (string->number x 16)) list->string))
     48               consumed-chars->char-code
    5249               (abnf:longest p)))
    53     ))
    54 
    55 ;; collects all consumed objects of type obj?
    56 (define (consumed-objects obj?)
    57   (lambda (cs)
    58     (and (pair? cs)
    59          (let loop ((cs cs) (ax (list)))
    60            (cond ((null? cs)   (list ax ))
    61                  ((obj? (car cs))
    62                   (loop (cdr cs) (cons (car cs) ax)))
    63                  (else (cons ax cs)))))))
    64 
    65 ;; construct lists from consumed objects
    66 (define (lcollect obj?)
    67   (let ((get-consumed (consumed-objects obj?)))
    68     (lambda rest
    69       (let-optionals rest ((kons identity))
    70         (let ((make (if (procedure? kons) kons (lambda (x) `(,kons . ,x)))))
    71           (lambda (x)
    72             (let ((x1 (get-consumed x)))
    73               (and x1 (pair? (car x1)) (cons (make (car x1)) (cdr x1))))))))))
    74 
    75 
    76 (define lcollect-pairs  (lcollect pair?))
    77 
    78 ;; shortcut for (abnf:bind (lcollect-pairs ...) (abnf:longest ... ))
    79 (define-syntax consumed-pairs->list
    80   (syntax-rules ()
    81     ((_ l p)    (abnf:bind (lcollect-pairs l)  (abnf:longest p)))
    82     ((_ p)      (abnf:bind (lcollect-pairs)    (abnf:longest p)))
    8350    ))
    8451
     
    8653                           (vector? x) (list? x)))
    8754
    88 (define lcollect-values  (lcollect value?))
    89 
    90 ;; shortcut for (abnf:bind (lcollect-pairs ...) (abnf:longest ... ))
    91 (define-syntax consumed-values->list
    92   (syntax-rules ()
    93     ((_ l p)    (abnf:bind (lcollect-values l)  (abnf:longest p)))
    94     ((_ p)      (abnf:bind (lcollect-values)    (abnf:longest p)))
    95     ))
    96 
    97 ;; construct vectors from consumed objects
    98 (define (vcollect obj?)
    99   (let ((get-consumed (consumed-objects obj?)))
    100     (lambda rest
    101       (lambda (x)
    102         (let ((x1 (get-consumed x)))
    103           (and x1 (pair? (car x1))
    104                (cons (list->vector (car x1)) (cdr x1))))))))
    105 
    106 (define vcollect-values  (vcollect value?))
    107 
    108 ;; shortcut for (abnf:bind (vcollect-pairs ...) (abnf:longest ... ))
    109 (define-syntax consumed-values->vector
    110   (syntax-rules ()
    111     ((_ p)      (abnf:bind (vcollect-values)    (abnf:longest p)))
    112     ))
    113 
     55(define consumed-values (abnf:consumed-objects value?))
     56(define consumed-values->list (abnf:consumed-objects-lift consumed-values))
     57
     58;; shortcut for (abnf:bind (consumed-values->list ...) (abnf:longest ... ))
     59(define-syntax bind-consumed-values->list
     60  (syntax-rules ()
     61    ((_ l p)    (abnf:bind (consumed-values->list l)  (abnf:longest p)))
     62    ((_ p)      (abnf:bind (consumed-values->list)    (abnf:longest p)))
     63    ))
     64
     65;; construct vectors from consumed values
     66(define consumed-values->vector
     67  ((abnf:consumed-objects-lift consumed-values)
     68   list->vector))
     69
     70;; shortcut for (abnf:bind (consumed-values->vector ...) (abnf:longest ... ))
     71(define-syntax bind-consumed-values->vector
     72  (syntax-rules ()
     73    ((_ p)      (abnf:bind consumed-values->vector  (abnf:longest p)))
     74    ))
    11475
    11576(define ws (abnf:repetition (abnf:set-from-string " \t\r\n")))
     
    13596(define false
    13697  (abnf:bind
    137    (abnf:collect-chars (lambda x #f))
     98   (abnf:consumed-chars->list (lambda x #f))
    13899   (abnf:lit "false")))
    139100
    140101(define null
    141102  (abnf:bind
    142    (abnf:collect-chars (lambda x '()))
     103   (abnf:consumed-chars->list (lambda x '()))
    143104   (abnf:lit "null")))
    144105
    145106(define true
    146107  (abnf:bind
    147    (abnf:collect-chars (lambda x (list #t)))
     108   (abnf:consumed-chars->list (lambda x (list #t)))
    148109   (abnf:lit "true")))
    149110
     
    155116     (char-set #\" #\\ #\/ #\backspace #\page
    156117               #\newline #\return #\tab))
    157     (consumed->char-code
     118    (bind-consumed->char-code
    158119     (abnf:repetition-n 4 abnf:hexadecimal)))))
    159120
     
    169130
    170131(define p-string
    171   (consumed->string
     132  (abnf:bind-consumed->string
    172133   (abnf:concatenation
    173134    (abnf:drop-consumed (abnf:char #\"))
     
    194155                        (abnf:char #\-))))
    195156
    196     (consumed->number
     157    (bind-consumed->number
    197158     (abnf:concatenation
    198159      sign
     
    203164
    204165(define p-member
    205   (consumed-values->list
     166  (bind-consumed-values->list
    206167   (abnf:concatenation
    207168    p-string
     
    212173
    213174(define object
    214   (consumed-pairs->list 'object
     175  (abnf:bind-consumed-pairs->list 'object
    215176   (abnf:concatenation
    216177    begin-object
     
    228189 
    229190(define array
    230   (consumed-values->vector
     191  (bind-consumed-values->vector
    231192   (abnf:concatenation
    232193    begin-array
  • release/4/json-abnf/json-abnf.setup

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