Skip to content

Commit

Permalink
todo
Browse files Browse the repository at this point in the history
  • Loading branch information
benknoble committed Nov 5, 2024
1 parent 4656028 commit 58731f8
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
5 changes: 5 additions & 0 deletions parsers/foes.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@
(~> sep (partition
[foe/pc (~> (>< second) collect check-duplicates)])))

;; if foes/p and bestiary/p return values in a better order, we are set (see
;; comment in parsers/monster.rkt). Fortunately here we are still operating on
;; plain-values (conversion to syntax happens later in make-reader-like from
;; parsers/base.rkt, though see
;; https://github.com/benknoble/frosthaven-manager/issues/95).
(define foes/p
(guard/p
(ws-separated-whole-file/p (or/p import-monsters/p
Expand Down
1 change: 1 addition & 0 deletions parsers/monster.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
[monster-info? monster-name-dupes]
[listof-monster-ability? ability-set-dupes])))

;; organize result value better; change macro parsing in bestiary.rkt, foes.rkt
(define bestiary/p
(guard/p
(ws-separated-whole-file/p (or/p import-monsters/p (try/p monster/p) ability-deck/p))
Expand Down
39 changes: 39 additions & 0 deletions syntax-lang.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#lang racket

(provide #%app #%datum #%top #%top-interaction
(rename-out [mb #%module-begin])
text
newline)

(require syntax/parse/define
frosthaven-manager/gui/rich-text-display
pict)

(define-syntax-parser mb
[(_ e ...)
#'(#%module-begin
(provide expr)
(define expr
(list e ...)))])

(module reader syntax/module-reader
frosthaven-manager/syntax-lang
#:read read
#:read-syntax read-syntax

(require racket/match
syntax/strip-context
frosthaven-manager/gui/rich-text-display
pict)

(define i 2)
(define (read-syntax _src _in)
(begin0
(match i
[0 eof]
[1 (strip-context #'newline)]
[2 (strip-context #'(text "AoE spec"))])
(set! i (sub1 i))))

(define (read in)
(syntax->datum (read-syntax (object-name in) in))))
25 changes: 25 additions & 0 deletions syntax/monsters.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@
({~datum import} imports ...)
({~datum info} infos ...)
({~datum ability} (actions ...) ...))
;; ----- here is where we need to interpose to generate the (require …) forms
;; for the necessary AoE modules. Those are tied to the
;; (actions ... ...).
;;
;; We will need to expand monster-ability-abilities contract:
;; (listof (or/c string? pict?)). Then instead of struct-copying the
;; location, we place an expression that computes a "parsed" action
;; (which really just splices AoEs into …-abilities); this would need
;; to know which ID corresponds to which module? Seems like we either:
;; - 2-pass: up-front, generate temporaries for all the AoE modules.
;; Somehow tie them to the appropriate module names (a compile-time
;; or run-time hash?) for lookup later… if the expression computing
;; an action above is a macro, it can receive an identifier and
;; splice it.
;; - 1-pass: a single compile-time macro acts on each action; for
;; each action, it makes a pass over …-abilities. It returns a list
;; of (module, generated temporaries) pairs that we can use for a
;; require form _and_ an expression for the action that uses said
;; temporaries. We then splice those in as appropriate.
;; Either way, it seems the whole computation is done at compile-time…
;;
;; We shouldn't have prefab problems because the `read[-syntax]`
;; results are still `syntax?` (the …-abilities are all still strings);
;; the _expanded_ module contains expressions that compute picts.
#:with (imported-info-db ...) (generate-temporaries #'(imports ...))
#:with (imported-ability-db ...) (generate-temporaries #'(imports ...))
;; also binds `here` correctly
Expand All @@ -66,6 +90,7 @@
[ability-db imported-ability-db]) ...)
runtime-path-define
(define-values (original-info-db original-ability-db)
;; --------------------------v interpose on monster-ability creation to parse/attach AoE information?
(datums->dbs (list infos ... (struct-copy monster-ability actions [location here]) ... ...)))
(define info-db
(combine-infos original-info-db imported-info-db ...))
Expand Down
11 changes: 11 additions & 0 deletions test-syntax-lang.rkt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#lang frosthaven-manager/syntax-lang
;; vim: ft=racket
;;
;; proof that I can embed model values and picts into the "read" syntax of a
;; module, but only if they are returned as (stripped) syntax expressions that
;; would evaluate to the model value or pict; then, they have to be interpreted
;; in some way (usually by providing bindings or by using them in a macro that
;; does something intelligent)
;;
;; for example, (newline? (second expr)) and (show-pict (first expr)) both work
;; as expected

0 comments on commit 58731f8

Please sign in to comment.