From d7d3e70886554cb8350ea444adf384ca078673fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Sun, 25 Dec 2022 23:50:37 -0300 Subject: Adapt to latest version of monparser --- json.lisp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'json.lisp') diff --git a/json.lisp b/json.lisp index 17e111a..80fef99 100644 --- a/json.lisp +++ b/json.lisp @@ -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 -- cgit v1.2.3