summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorBoutade <thegoofist@protonmail.com>2019-05-04 09:27:00 -0500
committerBoutade <thegoofist@protonmail.com>2019-05-04 09:27:00 -0500
commitbedbdf77261d0930bbc1d433ca7c35472a228e88 (patch)
tree167906d62a92e911537d9200f8bcdae07d89862d /examples
parent6a1882899b6b4e7d856da348659c6030c5f9b7f3 (diff)
added advisory and comment
Diffstat (limited to 'examples')
-rw-r--r--examples/json-parzival.lisp38
1 files changed, 37 insertions, 1 deletions
diff --git a/examples/json-parzival.lisp b/examples/json-parzival.lisp
index e25eaf0..50164d9 100644
--- a/examples/json-parzival.lisp
+++ b/examples/json-parzival.lisp
@@ -1,3 +1,8 @@
+;;;; A Toy parser for a most of JSON.
+;;;; Specificially, double-quote characters are not escaped in strings
+;;;; And the full range of numbers defined in the JSON specification are
+;;;; not supported. This is file is intended to be a demonstration
+
(defpackage "json-parzival"
(:use :cl :parzival))
@@ -29,12 +34,16 @@
(<<sep-by <json-value< <comma-sep<)
(<<strip (<<char #\]))))
+(defun make-keyword-symbol (str)
+ (read-from-string (format nil ":~a" str)))
+
+
(defvar <json-object-pair<
(<<bind (<<brackets <whitespace<
<json-string<
(<<strip (<<char #\:)))
(lambda (key)
- (<<map (lambda (value) (cons key value))
+ (<<map (lambda (value) (cons (make-keyword-symbol key) value))
<json-value<))))
(defvar <json-object<
@@ -44,4 +53,31 @@
+;;; An Example
+(defun run-the-example ()
+ (with-open-file (input "foo.json")
+ (let ((stream (make-instance 'replay-streams:character-input-replay-stream
+ :source input)))
+ (parse stream <json-value<))))
+;; should produce:
+;; (((:NAME . "Boutade")
+;; (:LANGUAGES ((:LANG . "Common Lisp") (:PROFICIENCY . :NULL) (:LOVESIT . T))
+;; ((:LANG . "Rust") (:PROFICIENCY . 0.8) (:LOVESIT . T)
+;; (:ISASHAMEDTOLOVEIT . T))
+;; ((:LANG . "Haskell") (:PROFICIENCY . 0.5)
+;; (:LOVESIT . "sometimes, in some ways")))
+;; (:PIZZAORDER "Tempeh Italian Sausage" "Spinach" "Mushrooms"
+;; "Red Pepper Flakes")
+;; (:ISCOOL) (:ISFUNNY) (:THINKSPEOPLEARELAUGHING . T)
+;; (:BEHONEST_THINKSPEOPLEARELAUGHING))
+;; ((:NAME . "Goofist")
+;; (:LANGUAGES
+;; ((:LANG . "Common Lisp") (:PROFICIENCY "over" 9000) (:LOVESIT . T))
+;; ((:LANG . "Rust") (:PROFICIENCY . -1) (:LOVESIT . T)
+;; (:ISASHAMEDTOLOVEIT . T))
+;; ((:LANG . "Haskell") (:PROFICIENCY . -1)
+;; (:LOVESIT . "i cannot tell a lie")))
+;; (:PIZZAORDER "Blue Stilton" "Walnuts" "Pork Sausage" "Apple Slices")
+;; (:ISCOOL . T) (:ISFUNNY . T) (:THINKSPEOPLEARELAUGHING . T)
+;; (:BEHONEST_THINKSPEOPLEARELAUGHING . T)))