refine project structure
This commit is contained in:
parent
a2fe1cdb14
commit
9a15f1bdb2
2
Makefile
2
Makefile
|
@ -4,4 +4,4 @@ KSY_FORMATS_REPO="https://github.com/kaitai-io/kaitai_struct_formats"
|
|||
KSY_SCHEMA_REPO="https://github.com/kaitai-io/ksy_schema"
|
||||
|
||||
all:
|
||||
@echo meow
|
||||
@raco make -j $$(nproc) -v $$(find . -iname '*.rkt')
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
#lang kaitai
|
||||
|
||||
meta:
|
||||
id: animal_record
|
||||
endian: be
|
||||
seq:
|
||||
- id: uuid
|
||||
size: 16
|
||||
- id: name
|
||||
type: str
|
||||
size: 24
|
||||
encoding: UTF-8
|
||||
- id: birth_year
|
||||
type: u2
|
||||
- id: weight
|
||||
type: f8
|
||||
- id: rating
|
||||
type: s4
|
|
@ -1,3 +1,4 @@
|
|||
#lang kaitai
|
||||
meta:
|
||||
id: elf
|
||||
title: Executable and Linkable Format
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
(define version "0.0.1")
|
||||
(define collection "kaitai")
|
||||
(define deps '("base"
|
||||
"binaryio-lib"
|
||||
"yaml"))
|
||||
(define test-omit-paths '("info.rkt"))
|
||||
; (define scribblings '(("kaitai.scrbl"))')
|
||||
(define pkg-authors '(haskal))
|
||||
(define pkg-desc "Description Here")
|
||||
(define deps '("base" "binaryio-lib" "yaml"))
|
||||
(define build-deps '("scribble-lib" "racket-doc" "rackunit-lib"))
|
||||
(define scribblings '(("scribblings/kaitai.scrbl" ())))
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
#lang racket/base
|
||||
|
||||
(require (for-syntax racket/base racket/list racket/match))
|
||||
(require (for-syntax racket/base racket/list racket/match racket/pretty))
|
||||
(provide (rename-out [kaitai:module-begin #%module-begin])
|
||||
(except-out (all-from-out racket/base) #%module-begin))
|
||||
|
||||
;; meow
|
||||
;; builtin types
|
||||
|
||||
;; utility to concat symbol stuff
|
||||
(define-for-syntax (sym+ . args)
|
||||
|
@ -15,17 +15,11 @@
|
|||
(define-for-syntax (make-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 "-")))
|
||||
|
||||
;; returns either the given id or meta.id
|
||||
;; otherwise raises syntax error
|
||||
(define-for-syntax (get-id top given-id)
|
||||
(kaitai-str->sym
|
||||
(or given-id (hash-ref (hash-ref top "meta" (hash)) "id"
|
||||
(make-rse "type has no meta.id and none was provided")))))
|
||||
(or given-id (hash-ref (hash-ref top "meta" (hash)) "id"
|
||||
(make-rse "type has no meta.id and none was provided"))))
|
||||
|
||||
;; helper for types meta lookup
|
||||
(define-for-syntax (get-id-seq top given-id)
|
||||
|
@ -33,14 +27,12 @@
|
|||
(define seq (hash-ref top "seq" (make-rse "form must have a seq element")))
|
||||
(values id-sym seq))
|
||||
|
||||
;; generates struct definitions
|
||||
(define-for-syntax (gen-struct top [given-id #f])
|
||||
(define-values [id-sym seq] (get-id-seq top given-id))
|
||||
(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" (make-rse "seq element has no id"))))
|
||||
seq)] #:transparent)))
|
||||
;; idk yet
|
||||
(define-for-syntax (kaitai:process defn)
|
||||
(pretty-write defn)
|
||||
(define-values [id seq] (get-id-seq defn #f))
|
||||
|
||||
(void))
|
||||
|
||||
;; runtime lib
|
||||
|
||||
|
@ -59,7 +51,7 @@
|
|||
|
||||
(define-syntax (kaitai:module-begin stx)
|
||||
(define body (second (syntax-e stx)))
|
||||
(displayln (syntax->datum body))
|
||||
(kaitai:process (syntax->datum body))
|
||||
#`(#%module-begin
|
||||
(module+ main
|
||||
(kaitai:uwu))))
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
#lang scribble/manual
|
||||
@require[@for-label[kaitai
|
||||
racket/base]]
|
||||
|
||||
@title{kaitai}
|
||||
@author{haskal}
|
||||
|
||||
@defmodule[kaitai]
|
||||
|
||||
Package Description Here
|
Loading…
Reference in New Issue