diff options
author | Juan Manuel Tomás <jtomas1815@gmail.com> | 2022-12-25 23:50:37 -0300 |
---|---|---|
committer | Juan Manuel Tomás <jtomas1815@gmail.com> | 2022-12-25 23:50:37 -0300 |
commit | d7d3e70886554cb8350ea444adf384ca078673fb (patch) | |
tree | ce1340d4dbbce302b3587845227b43d386cc8edb /json.lisp | |
parent | 7dc8f899bfb9c7d44fcfde6bb314e6f550222533 (diff) | |
download | json-d7d3e70886554cb8350ea444adf384ca078673fb.tar.gz json-d7d3e70886554cb8350ea444adf384ca078673fb.zip |
Adapt to latest version of monparser
Diffstat (limited to 'json.lisp')
-rw-r--r-- | json.lisp | 32 |
1 files changed, 14 insertions, 18 deletions
@@ -2,22 +2,22 @@ (defparameter number-literal (let ((signed-digits - (comp ((sign (optional (either (unit #\-) + (comp ((sign (optional (one-of (unit #\-) (unit #\+)))) (natural (if sign - (either (many (unit-if #'digit-char-p)) + (one-of (many (unit-if #'digit-char-p)) (fail "Malformed number.")) (many (unit-if #'digit-char-p))))) (cons sign natural)))) (comp ((base signed-digits) (dot (optional (unit #\.))) (fraction (if dot - (either (many (unit-if #'digit-char-p)) + (one-of (many (unit-if #'digit-char-p)) (fail "Malformed fractional part.")) nothing)) - (e (optional (either (unit #\e) (unit #\E)))) + (e (optional (one-of (unit #\e) (unit #\E)))) (exponent (if e - (either signed-digits + (one-of signed-digits (fail "Malformed exponent part.")) nothing))) (read-from-string @@ -26,7 +26,7 @@ (defparameter string-literal (comp ((_ (unit #\")) - (chars (optional (many (either (comp ((slash (unit #\\)) + (chars (optional (many (one-of (comp ((slash (unit #\\)) (escaped (unit-if)) (codepoints (if (char= escaped #\u) (comp ((cp0 (unit-if #'digit-char-p)) @@ -53,33 +53,29 @@ (t escaped))) (unit-if (lambda (x) (and (char/= x #\") (char/= x #\\)))))))) - (_ (either (unit #\") + (_ (one-of (unit #\") (fail "String is not properly closed.")))) (str:from-list chars))) -(defparameter whitespace - (comp ((_ (optional (many (either (unit #\Space) (unit #\Newline) (unit #\Tab)))))) - nil)) - (defparameter true-symbol (comp ((_ (unit #\t)) - (_ (either (literal "rue") + (_ (one-of (literal "rue") (fail "Expected 'true'.")))) 'true)) (defparameter false-symbol (comp ((_ (unit #\f)) - (_ (either (literal "alse") + (_ (one-of (literal "alse") (fail "Expected 'false'.")))) 'false)) (defparameter null-symbol (comp ((_ (unit #\n)) - (_ (either (literal "ull") + (_ (one-of (literal "ull") (fail "Expected 'null'.")))) 'null)) -(defvar json-value) +(defvar json-value nil) (defparameter json-array (comp ((_ (unit #\[)) @@ -90,10 +86,10 @@ (defparameter json-object (let ((json-pair (comp ((_ whitespace) - (k (either string-literal + (k (one-of string-literal (fail "Expected a string."))) (_ whitespace) - (_ (either (unit #\:) + (_ (one-of (unit #\:) (fail "Expected a \":\""))) (v json-value)) (cons k v)))) @@ -107,7 +103,7 @@ (setf json-value (comp ((_ whitespace) - (v (either number-literal + (v (one-of number-literal string-literal json-object json-array |