Ver Fonte

new aux parse functions, render posting length control

Innocenty Enikeew há 8 anos atrás
pai
commit
8a575f2fab
3 ficheiros alterados com 16 adições e 3 exclusões
  1. 4 1
      package.lisp
  2. 7 1
      parsing.lisp
  3. 5 1
      render.lisp

+ 4 - 1
package.lisp

@@ -1,6 +1,7 @@
 (defpackage #:pta-ledger
   (:use #:cl #:smug)
-  (:export #:amount
+  (:export #:*posting-length*
+           #:amount
            #:make-amount
            #:amount-quantity
            #:amount-commodity
@@ -22,6 +23,8 @@
            #:entry-comment
            #:entry-postings
            #:parse-date
+           #:parse-account
+           #:parse-amount
            #:parse-journal
            #:parse-query
            #:entries

+ 7 - 1
parsing.lisp

@@ -111,7 +111,7 @@
       (error () (.fail)))))
 
 (defun parse-date (text &optional default-year)
-  (parse (.simple-date default-year) text))
+  (parse (.prog1 (.simple-date default-year) (.eol)) text))
 
 (defun .status ()
   (.is 'member '(#\! #\*)))
@@ -130,6 +130,9 @@
                                 (.char= #\Newline)) :result-type 'string)))
     (.identity (strip-space account))))
 
+(defun parse-account (text)
+  (parse (.prog1 (.account) (.eol)) text))
+
 (defun .money-number (thousands-sep decimal-sep)
   (.let* ((first-part (.while (.is 'digit-char-p) :result-type 'string))
           (rest-parts (.mapcar* (.progn (.char= thousands-sep)
@@ -184,6 +187,9 @@
                                  quantity)
                    :commodity commodity)))))
 
+(defun parse-amount (text)
+  (parse (.prog1 (.amount) (.eol)) text))
+
 (defun .posting ()
   (.let* ((_ (.whitespace))
           (status (.optional (.prog1 (.status) (.optional (.spaces)))))

+ 5 - 1
render.lisp

@@ -1,5 +1,7 @@
 (in-package #:pta-ledger)
 
+(defvar *posting-length* 46 "Length of posting without amount")
+
 (defun render-date (universal-time)
   (when universal-time
     (format nil "~{~4,'0D/~2,'0D/~2,'0D~}" (get-date universal-time))))
@@ -19,7 +21,9 @@
            (status-text (format nil "~@[~A ~]" status))
            (text (format nil "    ~A~vA~@[  ~A~]~@[ @ ~A~]~@[ @@ ~A~]"
                          status-text
-                         (if amount-text (- 46 (position #\Space amount-text) (length status-text)) 0)
+                         (if amount-text (- *posting-length*
+                                            (position #\Space amount-text)
+                                            (length status-text)) 0)
                          account
                          amount-text
                          (when unit-price (render unit-price))