#lang scheme/base
(require "../base.ss")
(require (unlib-in 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)
(let ([proc (with-handlers ([exn? (lambda args #f)])
(syntax-local-value stx #f))])
(if (procedure? proc)
(private-sql-identifier? (proc))
#f))))
(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)
(if (identifier? stx)
(persistent-struct-info-set? stx)
#f))
(provide entity-identifier?
make-private-sql-identifier
make-sql-transformer
sql-identifier?
self-quoting-literal?)