|
|
@@ -269,9 +269,25 @@
|
|
|
(.eol)))))
|
|
|
(.empty-lines)))
|
|
|
|
|
|
+(define-condition journal-failed (error)
|
|
|
+ ((position :initarg :position :reader parse-error-pos)
|
|
|
+ (left-data :initarg :left-data :reader parse-error-left))
|
|
|
+ (:report (lambda (condition stream)
|
|
|
+ (with-slots (position left-data) condition
|
|
|
+ (format stream "Ledger parse failed at position ~A~@[, starting from ~A~]" position left-data)))))
|
|
|
+
|
|
|
(defun parse-journal (str)
|
|
|
(let ((*default-year* (car (get-date (get-universal-time)))))
|
|
|
- (parse (.journal) str)))
|
|
|
+ (multiple-value-bind (result left rest)
|
|
|
+ (parse (.journal) str)
|
|
|
+ (cond
|
|
|
+ ((null result) (error 'journal-failed :left-data (subseq str 0 (min 200 (length str)))))
|
|
|
+ ((not (string= "" left)) (error 'journal-failed
|
|
|
+ :position (- (length str)
|
|
|
+ (length left))
|
|
|
+ :left-data (subseq left 0 (min 200 (length left)))))
|
|
|
+ ((not (null rest)) (error 'journal-failed :position (length str)))
|
|
|
+ (:otherwise result)))))
|
|
|
|
|
|
(defun .query-coloned (type key-parser value-parser)
|
|
|
(.let* ((key key-parser)
|
|
|
@@ -534,3 +550,7 @@
|
|
|
(amount-quantity a)
|
|
|
(amount-commodity a)))
|
|
|
(rest amounts))))))))
|
|
|
+
|
|
|
+(defun journal-balance (journal &optional query)
|
|
|
+ (format-balance (balance (entries journal)
|
|
|
+ :predicate (when query (parse-query query)))))
|