chickadee » yaml » yaml-parse

yaml-parse input stream-start stream-end document-start document-end alias scalar sequence-start sequence-end mapping-start mapping-end seedprocedure

Parse a YAML representation into an object. input may be a string or input port. The remaining arguments are callback procedures along with the initial seed value seed. Each callback procedure accepts zero or more arguments representing the callback event, followed by the seed value. The return value of each callback procedure becomes the new seed value. Finally, the seed value is returned.

The following example prints out a list of all events:

(import scheme)
(import (chicken base))
(import (chicken pretty-print))
(import yaml)

(define (yaml-events yaml)
  (reverse
   (yaml-parse yaml
               (lambda (enc seed)
                 (cons (list 'stream-start enc) seed))
               (lambda (seed)
                 (cons (list 'stream-end) seed))
               (lambda (version tags implicit seed)
                 (cons (list 'document-start version tags implicit) seed))
               (lambda (implicit? seed)
                 (cons (list 'document-end implicit?) seed))
               (lambda (alias seed)
                 (cons (list 'alias alias) seed))
               (lambda (value anchor tag plain quoted style seed)
                 (cons (list 'scalar value anchor tag plain quoted style) seed))
               (lambda (anchor tag implicit style seed)
                 (cons (list 'sequence-start anchor tag implicit style) seed))
               (lambda (seed)
                 (cons '(sequence-end) seed))
               (lambda (anchor tag implicit style seed)
                 (cons (list 'mapping-start anchor tag implicit style) seed))
               (lambda (seed)
                 (cons '(mapping-end) seed))
               '())))

(pp (yaml-events "--- { }"))