1(module struct-util '#%kernel
2  (#%require "define.rkt"
3             "cond.rkt")
4
5  (#%provide predicate->struct-name)
6
7  ;; predicate->struct-name : any/c syntax? (or/c identifier? #f) -> string?
8  ;; Infers struct name from a predicate identifier. This is used as a fallback
9  ;; method to extract field names when struct-field-info is not available.
10  (define (predicate->struct-name who orig-stx stx)
11    (if stx
12        (cond
13          [(regexp-match #rx"^(.*)[?]$" (symbol->string (syntax-e stx))) => cadr]
14          [else
15           (raise-syntax-error
16            who
17            "unable to cope with a struct type whose predicate doesn't end with `?'"
18            orig-stx)])
19        (raise-syntax-error
20         who
21         "unable to cope with a struct whose predicate is unknown"
22         orig-stx))))
23