diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2022-11-02 10:51:58 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2022-11-02 10:51:58 -0300 |
commit | 550204b6840d2986b1707a16d0a77c0e69d5d5b3 (patch) | |
tree | ff0ac11fdd4a27d48ded24784eab8af4152240cf /json.lisp | |
parent | e04918e60ca56d0ab24eff72ef675a08c961e335 (diff) | |
download | json-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.lisp | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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))) |