it does...something!

This commit is contained in:
xenia 2020-09-06 01:35:32 -04:00
parent ac99689463
commit 9905e167a1
2 changed files with 36 additions and 6 deletions

View File

@ -2,6 +2,6 @@
(define version "0.0.1") (define version "0.0.1")
(define collection "kaitai") (define collection "kaitai")
(define deps '("base" "yaml")) (define deps '("base" "yaml" "binaryio-lib"))
(define test-omit-paths '("info.rkt")) (define test-omit-paths '("info.rkt"))
; (define scribblings '(("kaitai.scrbl"))') ; (define scribblings '(("kaitai.scrbl"))')

View File

@ -1,15 +1,45 @@
#lang racket/base #lang racket/base
(provide (rename-out [kaitai-module-begin #%module-begin])) (require (for-syntax racket/base racket/list))
(provide (rename-out [kaitai:module-begin #%module-begin])
(except-out (all-from-out racket/base) #%module-begin))
(define-syntax-rule (kaitai-module-begin EXPR ...) ;; meow
(#%module-begin
(displayln `(EXPR ...)))) ;; makes a syntax error raiser
(define-for-syntax (rse msg)
(lambda () (raise-syntax-error #f msg)))
;; converts a ksy id to a racket id
;; maps _ to -
(define-for-syntax (kaitai-str->sym str)
(string->symbol (regexp-replace* #px"_" str "-")))
;; generates struct definitions
(define-for-syntax (gen-struct top [given-id #f])
(define id (or given-id (hash-ref (hash-ref top "meta" (hash)) "id"
(rse "type has no meta.id and none was provided"))))
(define id-sym (kaitai-str->sym id))
(define seq (hash-ref top "seq" (rse "form must have a seq element")))
(define instances (hash-ref top "instances" (hash)))
#`((provide [struct-out #,id-sym])
(struct #,id-sym
[#,@(map (lambda (a) (kaitai-str->sym (hash-ref a "id" (rse "seq element has no id"))))
seq)] #:transparent)))
;; language infrastructure
(define-syntax (kaitai:module-begin stx)
(define body (second (syntax-e stx)))
(define top-struct (gen-struct (syntax->datum body)))
; (displayln top-struct)
#`(#%module-begin
#,@top-struct))
(module reader syntax/module-reader (module reader syntax/module-reader
#:read kaitai-read #:read kaitai-read
#:read-syntax kaitai-read #:read-syntax kaitai-read
#:language "." #:language 'kaitai
(require yaml) (require yaml)