From 8351935b3764169b83159ec0984ad231dc6b4e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 10 Jun 2024 20:35:00 -0300 Subject: Use coerce and repeat --- load.lisp | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) (limited to 'load.lisp') diff --git a/load.lisp b/load.lisp index 4acfede..2377efc 100644 --- a/load.lisp +++ b/load.lisp @@ -18,39 +18,25 @@ (crit signed-digits) nothing))) (read-from-string - (str:from-list - (remove nil (append base (cons dot fraction) (cons (when e #\d) exponent)))))))) + (coerce + (remove nil (append base (cons dot fraction) (cons (when e #\d) exponent))) + 'string))))) (defparameter string-literal (comp ((_ (unit #\")) (chars (optional (many (one-of (comp ((slash (unit #\\)) (escaped (unit)) (codepoints (if (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 7))) - (setf (char str 0) #\#) - (setf (char str 1) #\\) - (setf (char str 2) #\u) - (setf (char str 3) cp0) - (setf (char str 4) cp1) - (setf (char str 5) cp2) - (setf (char str 6) cp3) - str)) + (repeat (unit digit-char-p) 4) nothing))) (case escaped - (#\n - #\Newline) - (#\t - #\Tab) - (#\u - (read-from-string codepoints)) + (#\n #\Newline) + (#\t #\Tab) + (#\u (read-from-string (coerce (append '(#\# #\\ #\u) codepoints) 'string))) (t escaped))) (unit (and (char/= it #\") (char/= it #\\))))))) (_ (crit (unit #\")))) - (str:from-list chars))) + (coerce chars 'string))) (defparameter true-symbol (comp ((_ (unit #\t)) -- cgit v1.2.3