summaryrefslogtreecommitdiff
path: root/json.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'json.lisp')
-rw-r--r--json.lisp28
1 files changed, 28 insertions, 0 deletions
diff --git a/json.lisp b/json.lisp
index cb94985..5f570d5 100644
--- a/json.lisp
+++ b/json.lisp
@@ -20,3 +20,31 @@
(fail "Malformed exponent part."))
nothing)))
(list 'number base fraction exponent))))
+
+(defparameter string-parser
+ (comp ((start (unit (lambda (x) (char= x #\"))))
+ (chars (zero-or-more (either (comp ((slash (unit (lambda (x) (char= x #\\))))
+ (escaped (unit))
+ (codepoints (if (and escaped (char= escaped #\u))
+ (comp ((cp0 (unit #'digit-char-p))
+ (cp1 (unit #'digit-char-p))
+ (cp2 (unit #'digit-char-p))
+ (cp3 (unit #'digit-char-p)))
+ (let ((str (make-string 4)))
+ (setf (char str 0) cp0)
+ (setf (char str 1) cp1)
+ (setf (char str 2) cp2)
+ (setf (char str 3) cp3)
+ str))
+ nothing)))
+ (case escaped
+ (#\n
+ #\Newline)
+ (#\t
+ #\Tab)
+ (#\u
+ codepoints)
+ (t escaped)))
+ (unit (lambda (x) (char/= x #\"))))))
+ (end (unit (lambda (x) (char= x #\")))))
+ (list 'string chars)))