Skip to content

Commit

Permalink
syntax: synthesize fewer identifiers
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
benknoble committed Oct 27, 2024
1 parent f15c6fb commit 4656028
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
4 changes: 1 addition & 3 deletions aoe.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions bestiary.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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") | <monster-info> | listof <monster-ability>
(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 ...) ...)
Expand All @@ -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 ...) ...))))])
Expand Down
11 changes: 4 additions & 7 deletions foes.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,9 +13,6 @@
;; e ::= '(import "path") | <monster-info> | listof <monster-ability> | <foe>
(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 ...) ...)
Expand All @@ -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 ...) ...))
Expand Down
6 changes: 5 additions & 1 deletion scribblings/syntax/monsters.scrbl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ...) ...))
Expand All @@ -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?)])
Expand Down
7 changes: 5 additions & 2 deletions syntax/monsters.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4656028

Please sign in to comment.