diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-02-03 14:39:39 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2023-02-03 14:39:39 -0300 |
commit | fdeb8e5de32f21a4a016b99165d248a7d8c3abde (patch) | |
tree | a98a034636d7188dfd0b8c3acde2ff69dfdc5af9 | |
parent | e858144ddf1e50b3a390d33961945a9063d746f0 (diff) | |
download | json-fdeb8e5de32f21a4a016b99165d248a7d8c3abde.tar.gz json-fdeb8e5de32f21a4a016b99165d248a7d8c3abde.zip |
Change api and add object generation
-rw-r--r-- | generate.lisp | 9 | ||||
-rw-r--r-- | json.asd | 5 | ||||
-rw-r--r-- | load.lisp | 4 | ||||
-rw-r--r-- | package.lisp | 7 | ||||
-rw-r--r-- | save.lisp (renamed from dump.lisp) | 0 |
5 files changed, 18 insertions, 7 deletions
diff --git a/generate.lisp b/generate.lisp new file mode 100644 index 0000000..de213a4 --- /dev/null +++ b/generate.lisp @@ -0,0 +1,9 @@ +(in-package #:json) + +(defmacro obj (&rest fields) + (let ((o (gensym)) + (f (gensym))) + `(let ((,o (make-hash-table :test #'equal :size ,(length fields)))) + (dolist (,f ',fields) + (setf (gethash (car ,f) ,o) (cadr ,f))) + ,o))) @@ -4,5 +4,6 @@ #:monparser) :components ((:file "package") - (:file "dump") - (:file "load"))) + (:file "save") + (:file "load") + (:file "generate"))) @@ -113,8 +113,8 @@ (_ whitespace)) v)) -(defun parse-string (str) +(defun from-string (str) (run json-value (input:from-string str))) -(defun parse-file (file) +(defun from-file (file) (run json-value (input:from-file file))) diff --git a/package.lisp b/package.lisp index 2c7c3a7..d4024f8 100644 --- a/package.lisp +++ b/package.lisp @@ -1,6 +1,7 @@ (defpackage #:json (:use #:cl #:parser) - (:export #:parse-string - #:parse-file + (:export #:from-string + #:from-file #:to-string - #:to-file)) + #:to-file + #:obj)) |