(in-package #:json) (defparameter number-parser (let ((signed-digits (comp ((sign (zero-or-one (unit (lambda (x) (or (char= x #\-) (char= x #\+)))))) (natural (one-or-more (unit #'digit-char-p)))) (cons sign natural)))) (comp ((base (either signed-digits (fail "Malformed number."))) (dot (zero-or-one (unit (lambda (x) (char= x #\.))))) (fraction (if dot (either (one-or-more (unit #'digit-char-p)) (fail "Malformed fractional part.")) nothing)) (e (zero-or-one (unit (lambda (x) (or (char= x #\e) (char= x #\E)))))) (exponent (if e (either signed-digits (fail "Malformed exponent part.")) nothing))) (list 'number base fraction exponent))))