#lang scheme/base
(require (planet "aif.ss" ("schematics" "macro.plt" 1))
(lib "list.ss" "srfi" "1"))
(provide location-source
location-line
location-column
location-position
location-span
syntax->location
location->string)
(define location-source first)
(define location-line second)
(define location-column third)
(define location-position fourth)
(define location-span fifth)
(define (syntax->location stx)
(list (syntax-source stx)
(syntax-line stx)
(syntax-column stx)
(syntax-position stx)
(syntax-span stx)))
(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)
"?"))