1 ;;; locations.rkt -- locating symbols
3 ;; Copyright (C) 2009, 2010 Jose Antonio Ortega Ruiz
5 ;; This program is free software; you can redistribute it and/or
6 ;; modify it under the terms of the Modified BSD License. You should
7 ;; have received a copy of the license along with this program. If
8 ;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
10 ;; Start date: Sun Apr 26, 2009 19:43
14 (provide symbol-location
20 (require geiser/utils geiser/modules)
22 (define (symbol-location* sym)
23 (let* ([id (namespace-symbol->identifier sym)]
24 [binding (and id (identifier-binding id))])
28 (resolved-module-path-name
29 (module-path-index-resolve (car binding))))
32 (define (make-location name path line)
33 (list (cons "name" name)
34 (cons "file" (if (path? path) (path->string path) '()))
35 (cons "line" (or line '()))))
37 (define (symbol-location sym)
38 (let* ([loc (symbol-location* sym)]
42 (make-location name path #f)
43 (module-location sym))))
45 (define symbol-module (compose cdr symbol-location*))
47 (define symbol-module-name
48 (compose module-path-name->name symbol-module))
50 (define (module-location sym)
51 (make-location sym (module-spec->path-name sym) 1))