From 9a15f1bdb281ea756e9afdd95be35d76eaec4d7b Mon Sep 17 00:00:00 2001 From: haskal Date: Thu, 10 Sep 2020 02:48:28 -0400 Subject: [PATCH] refine project structure --- Makefile | 2 +- examples/animal.ksy | 18 ++++++++++++++++++ examples/elf.ksy | 1 + kaitai/info.rkt | 10 +++++----- kaitai/main.rkt | 30 +++++++++++------------------- kaitai/scribblings/kaitai.scrbl | 10 ++++++++++ 6 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 examples/animal.ksy create mode 100644 kaitai/scribblings/kaitai.scrbl diff --git a/Makefile b/Makefile index ba66cd3..75fc20c 100644 --- a/Makefile +++ b/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') diff --git a/examples/animal.ksy b/examples/animal.ksy new file mode 100644 index 0000000..2708398 --- /dev/null +++ b/examples/animal.ksy @@ -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 diff --git a/examples/elf.ksy b/examples/elf.ksy index 4188d30..aa8e854 100644 --- a/examples/elf.ksy +++ b/examples/elf.ksy @@ -1,3 +1,4 @@ +#lang kaitai meta: id: elf title: Executable and Linkable Format diff --git a/kaitai/info.rkt b/kaitai/info.rkt index 20a09e3..9b2a458 100644 --- a/kaitai/info.rkt +++ b/kaitai/info.rkt @@ -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" ()))) diff --git a/kaitai/main.rkt b/kaitai/main.rkt index 2d9b7c9..6399d06 100644 --- a/kaitai/main.rkt +++ b/kaitai/main.rkt @@ -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)))) diff --git a/kaitai/scribblings/kaitai.scrbl b/kaitai/scribblings/kaitai.scrbl new file mode 100644 index 0000000..fae10bd --- /dev/null +++ b/kaitai/scribblings/kaitai.scrbl @@ -0,0 +1,10 @@ +#lang scribble/manual +@require[@for-label[kaitai + racket/base]] + +@title{kaitai} +@author{haskal} + +@defmodule[kaitai] + +Package Description Here