[<<][staapl][>>][..]
Sat Jul 19 12:28:27 CEST 2008

Zipper for the parser

The idea is this: currently the parser api uses 2 syntax elements to
pass around, and some context. It would be better to dump as much of
the context into the passed state, and also encode that state into a
single object that acts as normal syntax transformer.

The standard tree to accumulate is this:

  (lambda (state) x)
                  |
                state

where the x point is added to. The 'locals' parser takes the current
lambda expression and assigns it to a variable in a let expression,
and builds a new lambda expression.

How to represent zipper in syntax objects? If we're only representing
trees where the cursor is at the rightmost slot in a node, the data
structure becomes simpler:

  (state ((lambda (state) #f))) :: <node <<siblings> <root-path>>>

(define (stx-zip-up stx)
  (syntax-case stx ()
    ((node ((siblings ...) parent))
     #`((siblings ... node) parent))))

(define (stx-zip-down stx)
  (syntax-case stx ()
    (( (siblings ... node) parent)
     #`(node ((siblings ...) parent)))))




[Reply][About]
[<<][staapl][>>][..]