diff --git a/racket/collects/syntax/location.rkt b/racket/collects/syntax/location.rkt index b643c7adfa..de2db3a135 100644 --- a/racket/collects/syntax/location.rkt +++ b/racket/collects/syntax/location.rkt @@ -11,7 +11,9 @@ quote-character-position quote-character-span quote-module-path - quote-module-name) + quote-module-name + syntax-source-directory + syntax-source-file-name) (begin-for-syntax @@ -143,3 +145,19 @@ [(null? path) src] [(pair? src) (append src path)] [else (cons src path)]))) + +;; ------------------------------------------------------------------------ + +(define (syntax-source-directory stx) + (let* ([source (syntax-source stx)]) + (and (path-string? source) + (let-values ([(base file dir?) (split-path source)]) + (and (path? base) + (path->complete-path base + (or (current-load-relative-directory) + (current-directory)))))))) + +(define (syntax-source-file-name stx) + (let* ([f (syntax-source stx)]) + (and (path-string? f) + (let-values ([(base file dir?) (split-path f)]) file)))) diff --git a/racket/collects/unstable/syntax.rkt b/racket/collects/unstable/syntax.rkt index 90dfc3d772..eda0e336de 100644 --- a/racket/collects/unstable/syntax.rkt +++ b/racket/collects/unstable/syntax.rkt @@ -3,15 +3,12 @@ (require racket/syntax (for-syntax racket/base) (for-template racket/base) - syntax/transformer) ; for re-export + syntax/transformer ; for re-export + syntax/location) ; for re-export (provide ;; by endobson syntax-length - ;; by cce: - syntax-source-file-name - syntax-source-directory - ;; by stamourv: format-unique-id syntax-within? @@ -21,33 +18,9 @@ phase-of-enclosing-module ;; re-export, for backwards compatibility - make-variable-like-transformer) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; By Carl Eastlund, below -;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; Syntax Locations -;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(define (syntax-source-directory stx) - (let* ([source (syntax-source stx)]) - (and (path-string? source) - (let-values ([(base file dir?) (split-path source)]) - (and (path? base) - (path->complete-path base - (or (current-load-relative-directory) - (current-directory)))))))) - -(define (syntax-source-file-name stx) - (let* ([f (syntax-source stx)]) - (and (path-string? f) - (let-values ([(base file dir?) (split-path f)]) file)))) + make-variable-like-transformer + syntax-source-file-name + syntax-source-directory) ;; by stamourv: