#lang scheme/base
(require (planet untyped/unlib:3/symbol)
"../persistent-struct-info.ss"
(for-template scheme/base))
(define private-sql-identifier-key
'snooze-sql-identifier)
(define (make-private-sql-identifier [prefix #f])
(define private
(if prefix
(datum->syntax #f (symbol-append prefix '-private))
#'private))
(syntax-property private private-sql-identifier-key #t))
(define (private-sql-identifier? stx)
(and (member private-sql-identifier-key (syntax-property-symbol-keys stx))
(eq? (syntax-property stx private-sql-identifier-key) #t)))
(define (make-sql-transformer secret-binding-stx)
(with-syntax ([secret-binding secret-binding-stx])
#'(case-lambda
[(stx) #'secret-binding]
[() #'secret-binding])))
(define (sql-identifier? stx)
(and (identifier? stx)
(with-handlers ([exn? (lambda _ #f)])
(let ([proc (syntax-local-value stx #f)])
(and (procedure? proc)
(private-sql-identifier? (proc)))))))
(define (self-quoting-literal? stx)
(define datum (syntax->datum stx))
(or (boolean? datum)
(integer? datum)
(real? datum)
(string? datum)
(and (pair? datum)
(memq (car datum) '(quote quasiquote)))))
(define (entity-identifier? stx)
(and (identifier? stx)
(persistent-struct-info-set? stx)))
(provide entity-identifier?
make-private-sql-identifier
make-sql-transformer
sql-identifier?
self-quoting-literal?)