refine project structure

This commit is contained in:
xenia 2020-09-10 02:48:28 -04:00
parent a2fe1cdb14
commit 9a15f1bdb2
6 changed files with 46 additions and 25 deletions

View File

@ -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" KSY_SCHEMA_REPO="https://github.com/kaitai-io/ksy_schema"
all: all:
@echo meow @raco make -j $$(nproc) -v $$(find . -iname '*.rkt')

18
examples/animal.ksy Normal file
View File

@ -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

View File

@ -1,3 +1,4 @@
#lang kaitai
meta: meta:
id: elf id: elf
title: Executable and Linkable Format title: Executable and Linkable Format

View File

@ -2,8 +2,8 @@
(define version "0.0.1") (define version "0.0.1")
(define collection "kaitai") (define collection "kaitai")
(define deps '("base" (define pkg-authors '(haskal))
"binaryio-lib" (define pkg-desc "Description Here")
"yaml")) (define deps '("base" "binaryio-lib" "yaml"))
(define test-omit-paths '("info.rkt")) (define build-deps '("scribble-lib" "racket-doc" "rackunit-lib"))
; (define scribblings '(("kaitai.scrbl"))') (define scribblings '(("scribblings/kaitai.scrbl" ())))

View File

@ -1,10 +1,10 @@
#lang racket/base #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]) (provide (rename-out [kaitai:module-begin #%module-begin])
(except-out (all-from-out racket/base) #%module-begin)) (except-out (all-from-out racket/base) #%module-begin))
;; meow ;; builtin types
;; utility to concat symbol stuff ;; utility to concat symbol stuff
(define-for-syntax (sym+ . args) (define-for-syntax (sym+ . args)
@ -15,17 +15,11 @@
(define-for-syntax (make-rse msg) (define-for-syntax (make-rse msg)
(lambda () (raise-syntax-error #f 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 ;; returns either the given id or meta.id
;; otherwise raises syntax error ;; otherwise raises syntax error
(define-for-syntax (get-id top given-id) (define-for-syntax (get-id top given-id)
(kaitai-str->sym
(or given-id (hash-ref (hash-ref top "meta" (hash)) "id" (or given-id (hash-ref (hash-ref top "meta" (hash)) "id"
(make-rse "type has no meta.id and none was provided"))))) (make-rse "type has no meta.id and none was provided"))))
;; helper for types meta lookup ;; helper for types meta lookup
(define-for-syntax (get-id-seq top given-id) (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"))) (define seq (hash-ref top "seq" (make-rse "form must have a seq element")))
(values id-sym seq)) (values id-sym seq))
;; generates struct definitions ;; idk yet
(define-for-syntax (gen-struct top [given-id #f]) (define-for-syntax (kaitai:process defn)
(define-values [id-sym seq] (get-id-seq top given-id)) (pretty-write defn)
(define instances (hash-ref top "instances" (hash))) (define-values [id seq] (get-id-seq defn #f))
#`((provide [struct-out #,id-sym])
(struct #,id-sym (void))
[#,@(map (lambda (a) (kaitai-str->sym (hash-ref a "id" (make-rse "seq element has no id"))))
seq)] #:transparent)))
;; runtime lib ;; runtime lib
@ -59,7 +51,7 @@
(define-syntax (kaitai:module-begin stx) (define-syntax (kaitai:module-begin stx)
(define body (second (syntax-e stx))) (define body (second (syntax-e stx)))
(displayln (syntax->datum body)) (kaitai:process (syntax->datum body))
#`(#%module-begin #`(#%module-begin
(module+ main (module+ main
(kaitai:uwu)))) (kaitai:uwu))))

View File

@ -0,0 +1,10 @@
#lang scribble/manual
@require[@for-label[kaitai
racket/base]]
@title{kaitai}
@author{haskal}
@defmodule[kaitai]
Package Description Here