(module helpers mzscheme
(require (lib "etc.ss")
"../syntax/ast.ss"
"../syntax/token.ss")
(define stx-for-original-property (read-syntax #f (open-input-string "original")))
(define Identifier->syntax
(opt-lambda (id [loc (Term-location id)])
(build-syntax (Identifier-name id) loc)))
(define (Identifier->key id)
(build-syntax (symbol->string (Identifier-name id))
(Term-location id)))
(define build-syntax
(opt-lambda (expr [location #f] [original? #t])
(datum->syntax-object #f
expr
(and location (region->syntax location original?))
(and original? stx-for-original-property))))
(define region->syntax
(opt-lambda (region [original? #t])
(let ([start (region-start region)]
[end (region-end region)])
(datum->syntax-object #f
'source-location
(list
(region-source region)
(position-line start)
(position-col start)
(position-offset start)
(- (position-offset end) (position-offset start)))
(and original? stx-for-original-property)))))
(provide (all-defined)))