[<<][staapl][>>][..]
Sun May 3 11:19:45 CEST 2009

parser macros again

Hmm.. because 'expand uses the 'forth-begin linked to the compiler
implementation, instantiating the forth words like it's done now wont
work unless the dependencies are propagated through:

(define-forth
  ;; defines parser invocation from scheme + Forth parser words ...
  (forth-begin forth macro : :macro :forth :variable)
  ;; ... in terms of registration and compiler wrappers.
  (register! wrap-macro wrap-word wrap-variable))

So I'm going to make this macro non-hygienic to solve the dependency problem.

This seems to work:


(begin-for-syntax
 (define $ syntax-local-introduce))
;; Primitive parsing word transformers coupled to compilation forms.
(define-syntax (define-forth stx)
  (syntax-case stx ()
    ((_ (forth macro : :macro :forth :variable)
        (reg wrap-macro wrap-word wrap-variable))
     #`(begin
         (define-syntax-rule (#,($ #'forth-begin) . code)
           (forth-begin/init (forth-word reg wrap-word #f rpn-lambda) . code)) ;; (*)
         (ns (macro) (define-syntax :macro    (with-mode #'macro-word #'reg #'wrap-macro)))
         (ns (macro) (define-syntax :forth    (with-mode #'forth-word #'reg #'wrap-word)))
         (ns (macro) (define-syntax :variable (with-mode #'forth-word #'reg #'wrap-variable)))
         (ns (macro) (define-syntax :         (last-mode #'reg
                                                         #'forth-word #'wrap-word
                                                         #'macro-word #'wrap-macro)))
         (prefix-parsers
          (macro)
          ((forth) (:forth #f))
          ((macro) (:macro #f)))))))

Now to be honest I'm getting confused by the levels of quoting /
unquoting here.  That code is derived by successive transformation of
correct code, but I've lost the intuitive understanding.

Maybe by introducing the identifiers once this can be made more readable.

Ok: this abstracts it:

;; Non-higienically introduce a collection of identifiers.
(define (datum->syntax-list stx lst)
  (map (lambda (x) (datum->syntax stx x)) lst))

(define-syntax-rule (syntax-introduce-identifiers stx lst body)
  (syntax-case (datum->syntax-list stx 'lst) ()
    (lst body)))




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