Mercurial > core / lisp/lib/organ/object/stat-cookie.lisp
changeset 698: |
96958d3eb5b0 |
parent: |
a5ae5a58c4cd
|
author: |
Richard Westhaver <ellis@rwest.io> |
date: |
Fri, 04 Oct 2024 22:04:59 -0400 |
permissions: |
-rw-r--r-- |
description: |
fixes |
4 ;; the logic will be a bit weird here - we store 2 numbers (completed 5 ;; vs remaining) but sometimes need to parse a percentage without 6 ;; actually knowing the counts of completed vs remaining. To get 7 ;; around this, we'll allow a float to be stored in the N1 slot, which 8 ;; indicated that we parsed a percentage without knowing our counts. 9 (define-org-object stat-cookie ((n1 0 :type number) (n2 0 :type fixnum))) 11 (defmacro matches (name) 12 `(make-matcher ,name)) 14 (define-matcher stat-cookie-percent (is #\%)) 16 (define-matcher stat-cookie-ratio (is #\/)) 18 (define-matcher int (in #\0 #\9)) 20 (define-matcher stat-cookie-start 22 (next (matches (or :int 24 :stat-cookie-percent))))) 26 (define-matcher stat-cookie-end (is #\])) 29 (define-org-parser (stat-cookie :from string) 31 (with-lexer-environment (input) 32 (when (char= #\[ (consume)) 33 (let ((res (org-create :stat-cookie))) 34 (setf (org-stat-cookie-n1 res) 36 (consume-until (matches (not :int))))) 38 (#\/ (setf (org-stat-cookie-n2 res) (parse-number (consume-until (matches :stat-cookie-end))))) 39 (#\% (setf (org-stat-cookie-n1 res) (/ (org-stat-cookie-n1 res) 100))))