summaryrefslogtreecommitdiff
path: root/json.lisp
diff options
context:
space:
mode:
authorJuan Manuel Tomás <jtomas1815@gmail.com>2022-11-02 10:51:58 -0300
committerJuan Manuel Tomás <jtomas1815@gmail.com>2022-11-02 10:51:58 -0300
commit550204b6840d2986b1707a16d0a77c0e69d5d5b3 (patch)
treeff0ac11fdd4a27d48ded24784eab8af4152240cf /json.lisp
parente04918e60ca56d0ab24eff72ef675a08c961e335 (diff)
downloadjson-550204b6840d2986b1707a16d0a77c0e69d5d5b3.tar.gz
json-550204b6840d2986b1707a16d0a77c0e69d5d5b3.zip
Add a string parser
Doesn't have good error reporting yet. Planning on making so the monparser comp macro allows not defining a binding. That way less work is needed when ignoring stuff.
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)))