From 465602886e7fb40b9d843e3a147030fc3448bf31 Mon Sep 17 00:00:00 2001 From: "D. Ben Knoble" Date: Sun, 27 Oct 2024 10:45:58 -0400 Subject: [PATCH] syntax: synthesize fewer identifiers These identifiers do _not_ need to be synthesized in order to be visible in provide specifications, contrary to my earlier beliefs. However, as a result, the input #'info-db to make-dbs is no longer original in the sense of coming from the original module's syntax: this is a problem because it means that the define-runtime-path form gets the wrong context, causing the AoE modules to not be found at runtime. Perhaps there is a way to use imports, infos, or actions as appropriate sources, but using #'(imports ...) as the context and source for datum->syntax also failed. Instead, pass an original syntax that can be used for this information (and document it). Note that this requires quasisyntax in order to embed this-syntax from syntax-parse. --- aoe.rkt | 4 +--- bestiary.rkt | 10 ++++------ foes.rkt | 11 ++++------- scribblings/syntax/monsters.scrbl | 6 +++++- syntax/monsters.rkt | 7 +++++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/aoe.rkt b/aoe.rkt index 541b7c2..cdf5acf 100644 --- a/aoe.rkt +++ b/aoe.rkt @@ -2,13 +2,11 @@ (provide (rename-out [mb #%module-begin]) #%app #%datum #%top #%top-interaction) -(require (for-syntax racket/syntax) - frosthaven-manager/aoe-images +(require frosthaven-manager/aoe-images syntax/parse/define) (define-syntax-parser mb [(_ spec:expr) - #:with aoe (format-id this-syntax "aoe" #:source this-syntax) (syntax/loc this-syntax (#%module-begin (provide aoe) diff --git a/bestiary.rkt b/bestiary.rkt index 5741f07..d5b8899 100644 --- a/bestiary.rkt +++ b/bestiary.rkt @@ -4,16 +4,13 @@ #%app #%datum #%top #%top-interaction (rename-out [mb #%module-begin])) -(require (for-syntax frosthaven-manager/syntax/monsters - racket/syntax) +(require (for-syntax frosthaven-manager/syntax/monsters) frosthaven-manager/syntax/monsters syntax/parse/define) ;; e ::= '(import "path") | | listof (define-syntax-parser mb [(_ e:expr ...) - #:with info-db (format-id this-syntax "info-db" #:source this-syntax) - #:with ability-db (format-id this-syntax "ability-db" #:source this-syntax) #:with ((({~datum import} imports) ...) (infos ...) ((actions ...) ...) @@ -28,9 +25,10 @@ (syntax->datum #'(infos ...)) (syntax->datum #'(actions ... ...))) ;;=> - (syntax/loc this-syntax + (quasisyntax/loc this-syntax (#%module-begin - (make-dbs (provide info-db ability-db) + (make-dbs #,this-syntax + (provide info-db ability-db) (import imports ...) (info infos ...) (ability (actions ...) ...))))]) diff --git a/foes.rkt b/foes.rkt index 86361e0..298bd4b 100644 --- a/foes.rkt +++ b/foes.rkt @@ -4,8 +4,7 @@ #%app #%datum #%top #%top-interaction (rename-out [mb #%module-begin])) -(require (for-syntax frosthaven-manager/syntax/monsters - racket/syntax) +(require (for-syntax frosthaven-manager/syntax/monsters) frosthaven-manager/curlique frosthaven-manager/defns frosthaven-manager/syntax/monsters @@ -14,9 +13,6 @@ ;; e ::= '(import "path") | | listof | (define-syntax-parser mb [(_ e:expr ...) - #:with info-db (format-id this-syntax "info-db" #:source this-syntax) - #:with ability-db (format-id this-syntax "ability-db" #:source this-syntax) - #:with make-foes (format-id this-syntax "make-foes" #:source this-syntax) #:with ((({~datum import} imports) ...) (infos ...) ((actions ...) ...) @@ -37,9 +33,10 @@ (syntax->datum #'(infos ...)) (syntax->datum #'(foes ...))) ;;=> - (syntax/loc this-syntax + (quasisyntax/loc this-syntax (#%module-begin - (make-dbs (provide info-db ability-db) + (make-dbs #,this-syntax + (provide info-db ability-db) (import imports ...) (info infos ...) (ability (actions ...) ...)) diff --git a/scribblings/syntax/monsters.scrbl b/scribblings/syntax/monsters.scrbl index d060713..cdd40e6 100644 --- a/scribblings/syntax/monsters.scrbl +++ b/scribblings/syntax/monsters.scrbl @@ -10,7 +10,8 @@ @defmodule[frosthaven-manager/syntax/monsters] @defform[#:literals (provide import info ability) - (make-dbs (provide info-db-id ability-db-id) + (make-dbs original-syntax + (provide info-db-id ability-db-id) (import import-mod-path ...) (info monster-info ...) (ability (monster-ability ...) ...)) @@ -28,6 +29,9 @@ The @racket[provide] keyword in the provide specification is recognized by binding and must be the same as the one from @racketmodname[racket/base]. The @racket[import], @racket[info], and @racket[ability] keywords are recognized by datum identity. + +The @racket[original-syntax] input is used for binding and source information +for constructed runtime paths which mark paths for later use to find AoE specs. } @defproc[(syntaxes->bestiary-parts [syntaxes (listof syntax?)]) diff --git a/syntax/monsters.rkt b/syntax/monsters.rkt index 5dab35b..6dadb70 100644 --- a/syntax/monsters.rkt +++ b/syntax/monsters.rkt @@ -47,14 +47,17 @@ ;;;; exports (define-syntax-parser make-dbs - [(_ ({~literal provide} info-db ability-db) + [(_ original-stx + ({~literal provide} info-db ability-db) ({~datum import} imports ...) ({~datum info} infos ...) ({~datum ability} (actions ...) ...)) #:with (imported-info-db ...) (generate-temporaries #'(imports ...)) #:with (imported-ability-db ...) (generate-temporaries #'(imports ...)) ;; also binds `here` correctly - #:with runtime-path-define (datum->syntax #'info-db (syntax-e #'(define-runtime-path here ".")) #'info-db) + #:with runtime-path-define (datum->syntax #'original-stx + (syntax-e #'(define-runtime-path here ".")) + #'original-stx) (syntax/loc this-syntax (begin (provide info-db ability-db)