(module erase-lexical-scope mzscheme (require (lib "contract.ss")) (provide/contract (erase-lexical-scope (syntax? . -> . syntax?))) ;; erase-lexical-scope: syntax -> syntax ;; Removes identifier-binding information from a syntax, preserving ;; location information. (define (erase-lexical-scope stx) (define (syntax-properties stx) (map (lambda (f) (f stx)) (list syntax-source syntax-line syntax-column syntax-position syntax-span))) (syntax-case stx () [() (datum->syntax-object #f '() stx)] [(a . b) (let ([ea (erase-lexical-scope #'a)] [eb (erase-lexical-scope #'b)]) (datum->syntax-object #f `(,ea . ,eb) (syntax-properties stx)))] [_ (datum->syntax-object #f (syntax-object->datum stx) (syntax-properties stx))])))