From ca93de4e27306c92babcd963da3271185d963fd7 Mon Sep 17 00:00:00 2001 From: yfzhe Date: Mon, 12 Feb 2024 23:30:05 +0800 Subject: [PATCH] schema: add `schema-out` --- telebot/private/schema.rkt | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/telebot/private/schema.rkt b/telebot/private/schema.rkt index 44afb81..7a60e62 100644 --- a/telebot/private/schema.rkt +++ b/telebot/private/schema.rkt @@ -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? @@ -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 (:)