diff options
Diffstat (limited to 'lisp/ldg-regex.el')
-rw-r--r-- | lisp/ldg-regex.el | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/lisp/ldg-regex.el b/lisp/ldg-regex.el index 226475df..cdd06d39 100644 --- a/lisp/ldg-regex.el +++ b/lisp/ldg-regex.el @@ -37,39 +37,59 @@ "-?[1-9][0-9.]*[,]?[0-9]*") (defconst ledger-amount-decimal-period-regex - "-?[1-9][0-9.]*[.]?[0-9]*") + "-?[1-9][0-9,]*[.]?[0-9]*") (defconst ledger-other-entries-regex "\\(^[~=A-Za-z].+\\)+") (defconst ledger-comment-regex - "\\( \\| \\|^\\)\\(;.*\\)") + "^[;#|\\*%].*\\|[ \t]+;.*") + +(defconst ledger-multiline-comment-start-regex + "^!comment$") +(defconst ledger-multiline-comment-end-regex + "^!end_comment$") +(defconst ledger-multiline-comment-regex + "^!comment\n\\(.*\n\\)*?!end_comment$") (defconst ledger-payee-any-status-regex - "^[0-9/.=-]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.+?\\)\\(\t\\|\n\\| [ \t]\\)") + "^[0-9]+[-/][-/.=0-9]+\\(\\s-+\\*\\)?\\(\\s-+(.*?)\\)?\\s-+\\(.+?\\)\\s-*\\(;\\|$\\)") (defconst ledger-payee-pending-regex - "^[0-9]+[-/][-/.=0-9]+\\s-\\!\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(;\\|$\\)") + "^[0-9]+[-/][-/.=0-9]+\\s-\\!\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\s-*\\(;\\|$\\)") (defconst ledger-payee-cleared-regex - "^[0-9]+[-/][-/.=0-9]+\\s-\\*\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(;\\|$\\)") + "^[0-9]+[-/][-/.=0-9]+\\s-\\*\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\s-*\\(;\\|$\\)") (defconst ledger-payee-uncleared-regex - "^[0-9]+[-/][-/.=0-9]+\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\(;\\|$\\)") + "^[0-9]+[-/][-/.=0-9]+\\s-+\\(([^)]+)\\s-+\\)?\\([^*].+?\\)\\s-*\\(;\\|$\\)") (defconst ledger-init-string-regex "^--.+?\\($\\|[ ]\\)") (defconst ledger-account-any-status-regex - "^[ \t]+\\([*!]\\s-+\\)?\\([[(]?.+?\\)\\(\t\\|\n\\| [ \t]\\)") + "^[ \t]+\\(?1:[*!]\\s-*\\)?\\(?2:[^ ;].*?\\)\\( \\|\t\\|$\\)") (defconst ledger-account-pending-regex - "\\(^[ \t]+\\)\\(!.+?\\)\\( \\|$\\)") + "\\(^[ \t]+\\)\\(!\\s-*.*?\\)\\( \\|\t\\|$\\)") (defconst ledger-account-cleared-regex - "\\(^[ \t]+\\)\\(\\*.+?\\)\\( \\|$\\)") - - + "\\(^[ \t]+\\)\\(*\\s-*.*?\\)\\( \\|\t\\|$\\)") + +(defconst ledger-metadata-regex + "[ \t]+\\(?2:;[ \t]+.+\\)$") + +(defconst ledger-account-or-metadata-regex + (concat + ledger-account-any-status-regex + "\\|" + ledger-metadata-regex)) + +(defmacro rx-static-or (&rest rx-strs) + "Returns rx union of regexps which can be symbols that eval to strings." + `(rx (or ,@(mapcar #'(lambda (rx-str) + `(regexp ,(eval rx-str))) + rx-strs)))) (defmacro ledger-define-regexp (name regex docs &rest args) "Simplify the creation of a Ledger regex and helper functions." |