www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

main.rkt (1024B)


      1 #lang racket/base
      2 
      3 (provide chain-module-begin)
      4 
      5 (require (for-syntax racket/base
      6                      syntax/parse
      7                      debug-scopes/named-scopes/exptime))
      8 
      9 (define-syntax continue
     10   (syntax-parser
     11     [(_ whole-ctx lang lang-modbeg . body)
     12      #:with ({~literal #%plain-module-begin} . expanded-body)
     13      (local-expand (datum->syntax #'whole-ctx
     14                                   `(,#'lang-modbeg . ,#'body)
     15                                   #'whole-ctx)
     16                    'module-begin
     17                    '())
     18      (define new-scope (make-module-like-named-scope
     19                         (format "nested-lang-~a" (syntax-e #'lang))))
     20      (new-scope #`(begin . expanded-body))]))
     21 
     22 (define-syntax chain-module-begin
     23   (syntax-parser
     24     [{~and whole (_ lang . body)}
     25      #:with lang-modbeg (datum->syntax #'lang '#%module-begin #'lang)
     26      #:with whole-ctx (datum->syntax #'whole 'ctx #'whole)
     27      #'(#%plain-module-begin
     28         (require lang)
     29         (continue whole-ctx lang lang-modbeg . body))]))