summaryrefslogtreecommitdiff
path: root/ledger-regex.el
diff options
context:
space:
mode:
Diffstat (limited to 'ledger-regex.el')
-rw-r--r--ledger-regex.el26
1 files changed, 14 insertions, 12 deletions
diff --git a/ledger-regex.el b/ledger-regex.el
index 9d858c8..8ac3002 100644
--- a/ledger-regex.el
+++ b/ledger-regex.el
@@ -22,6 +22,8 @@
(require 'rx)
(require 'cl-lib)
+(defvar ledger-iso-date-regex)
+
(defconst ledger-amount-regex
(concat "\\( \\|\t\\| \t\\)[ \t]*-?"
"\\([A-Z$€£₹_(]+ *\\)?"
@@ -71,28 +73,28 @@
(defconst ledger-init-string-regex
"^--.+?\\($\\|[ ]\\)")
+(defconst ledger-account-name-regex
+ "\\(?1:[^][(); \t\r\n]+\\(?: [^][(); \t\r\n]+\\)*\\)")
+
(defconst ledger-account-directive-regex
- "^account [ \t]*\\(?2:[^;]+?\\)\\(?3:[ \t]*\\)\\(;.*\\)?$")
+ (concat "^account[ \t]+" ledger-account-name-regex))
-(defconst ledger-account-any-status-no-trailing-spaces-regex
- "^[ \t]+\\(?1:[*!]\\s-+\\)?[[(]?\\(?2:[^; ].+?\\)[])]?")
+(defconst ledger-account-name-maybe-virtual-regex
+ (concat "[[(]?" ledger-account-name-regex "[])]?"))
(defconst ledger-account-any-status-regex
- (format "%s%s"
- ledger-account-any-status-no-trailing-spaces-regex
- "\\(?3:\t\\| [ \t]\\|$\\)"))
+ (concat "^[ \t]+\\(?:[!*][ \t]*\\)?" ledger-account-name-maybe-virtual-regex))
+;; This would incorrectly match "account (foo)", but writing the regexp this way
+;; allows us to have just one match result
(defconst ledger-account-name-or-directive-regex
- (format "\\(?:%s\\|%s\\(?3:\t\\| [ \t]\\)\\)"
- ledger-account-directive-regex
- ledger-account-any-status-no-trailing-spaces-regex))
+ (format "\\(?:%s\\|%s\\)" ledger-account-any-status-regex ledger-account-directive-regex))
(defconst ledger-account-pending-regex
- "\\(^[ \t]+\\)\\(!\\s-*[^ ].*?\\)\\( \\|\t\\|$\\)")
+ (concat "\\(^[ \t]+\\)!" ledger-account-name-maybe-virtual-regex))
(defconst ledger-account-cleared-regex
- "\\(^[ \t]+\\)\\(*\\s-*[^ ].*?\\)\\( \\|\t\\|$\\)")
-
+ (concat "\\(^[ \t]+\\)*" ledger-account-name-maybe-virtual-regex))
(defmacro ledger-define-regexp (name regex docs &rest args)
"Simplify the creation of a Ledger regex and helper functions."