;;; ;;; Time-stamp: <06/01/27 21:26:17 noel> ;;; ;;; Copyright (C) 2005 by Noel Welsh. ;;; ;;; This library is free software; you can redistribute it ;;; and/or modify it under the terms of the GNU Lesser ;;; General Public License as published by the Free Software ;;; Foundation; either version 2.1 of the License, or (at ;;; your option) any later version. ;;; This library is distributed in the hope that it will be ;;; useful, but WITHOUT ANY WARRANTY; without even the ;;; implied warranty of MERCHANTABILITY or FITNESS FOR A ;;; PARTICULAR PURPOSE. See the GNU Lesser General Public ;;; License for more details. ;;; You should have received a copy of the GNU Lesser ;;; General Public License along with this library; if not, ;;; write to the Free Software Foundation, Inc., 59 Temple ;;; Place, Suite 330, Boston, MA 02111-1307 USA ;;; Author: Noel Welsh <noelwelsh@yahoo.com> ;; ;; ;; Commentary: (module location mzscheme (require (lib "list.ss" "srfi" "1")) (provide location-source location-line location-column location-position location-span syntax->location location->string) ;; type location = (list any number/#f number/#f number/#f number/#f) ;; location : source line column position span (define location-source first) (define location-line second) (define location-column third) (define location-position fourth) (define location-span fifth) ;; syntax->location : syntax -> location (define (syntax->location stx) (list (syntax-source stx) (syntax-line stx) (syntax-column stx) (syntax-position stx) (syntax-span stx))) ;; location->string : (list-of string) -> string (define (location->string location) (string-append (source->string (location-source location)) ":" (maybe-number->string (location-line location)) ":" (maybe-number->string (location-column location)))) (define (source->string source) (cond ((string? source) source) ((path? source) (path->string source)) ((not source) "unknown") (else (format "~a" source)))) (define (maybe-number->string number) (if (number? number) (number->string number) "?")) )