aoc2020/scripts/make-day

29 lines
874 B
Plaintext
Raw Normal View History

2020-12-01 21:33:57 +00:00
#!/usr/bin/env racket
#lang racket
(require racket/runtime-path
2020-12-02 08:49:57 +00:00
scribble/text (rename-in scribble/text/output [output scribble-output])
"aoc-lib.rkt")
2020-12-01 21:33:57 +00:00
(define-runtime-path template "template.rktrkt")
(define (eval-template file vars [port (current-output-port)])
(define cs (current-namespace))
(define output-exp
(parameterize ([current-namespace (make-base-namespace)])
(for ([mod (in-list '(scribble/text))])
(namespace-attach-module cs mod)
(namespace-require mod))
(hash-for-each vars namespace-set-variable-value!)
(eval `(include/text (file ,file)))))
(scribble-output output-exp port))
(command-line
2020-12-01 23:14:54 +00:00
#:program "make-day"
2020-12-01 21:33:57 +00:00
#:args (day)
2020-12-02 08:49:57 +00:00
;; make solution file
2020-12-01 21:33:57 +00:00
(call-with-output-file
(format "~a.rkt" day)
(lambda (out)
2020-12-15 00:55:55 +00:00
(eval-template (path->string template) (hash 'day day) out))))