Skip to content

Commit

Permalink
schema: add schema-out
Browse files Browse the repository at this point in the history
  • Loading branch information
yfzhe committed Feb 12, 2024
1 parent aeac063 commit ca93de4
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions telebot/private/schema.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
"bot.rkt"
(for-syntax racket/base
syntax/parse/pre
racket/provide-transform
racket/syntax
racket/string
syntax/parse/experimental/template
threading))

(provide define-schema
(provide define-schema schema-out
integer? string? boolean? listof
optional
define-api ->
ref :)
ref :
define-api ->)

;; TODO:
;; - contracts
;; - provide transformer `schema-out`
;; - cooperate with check-syntax
;; - implement gen:custom-write
;; - field converter?
Expand Down Expand Up @@ -203,6 +203,23 @@
set-field-value ...
jsexpr)]))

(define-syntax schema-out
(make-provide-transformer
(lambda (stx modes)
(syntax-parse stx
[(_ id:schema-id)
(define export-ids
(list #'id
(format-id #'id "make-~a" #'id)
(format-id #'id "schema:~a" #'id)
(format-id #'id "jsexpr->~a" #'id)
(format-id #'id "~a->jsexpr" #'id)))

(for/list ([id (in-list export-ids)])
(make-export (syntax-property id 'disappeared-use
(syntax-local-introduce id))
id 0 #f id))]))))

(define-syntax (ref stx)
(syntax-parse stx
#:literals (:)
Expand Down

0 comments on commit ca93de4

Please sign in to comment.