hledger-lib-0.17: Core data types, parsers and utilities for the hledger accounting tool.



More generic matching, done in one step, unlike FilterSpec and filterJournal*. Currently used only by hledger-web.



data Matcher Source

A matcher is a single, or boolean composition of, search criteria, which can be used to match postings, transactions, accounts and more. Currently used by hledger-web, will likely replace FilterSpec at some point.



always match


never match

MatchNot Matcher

negate this match

MatchOr [Matcher]

match if any of these match

MatchAnd [Matcher]

match if all of these match

MatchDesc String

match if description matches this regexp

MatchAcct String

match postings whose account matches this regexp

MatchDate DateSpan

match if actual date in this date span

MatchEDate DateSpan

match if effective date in this date span

MatchStatus Bool

match if cleared status has this value

MatchReal Bool

match if realness (involves a real non-virtual account ?) has this value

MatchEmpty Bool

match if emptiness (from the --empty command-line flag) has this value. Currently this means a posting with zero amount.

MatchDepth Int

match if account depth is less than or equal to this value


data QueryOpt Source

A query option changes a query's/report's behaviour and output in some way.


QueryOptInAcctOnly AccountName

show an account register focussed on this account

QueryOptInAcct AccountName

as above but include sub-accounts in the account register | QueryOptCostBasis -- ^ show amounts converted to cost where possible | QueryOptEffectiveDate -- ^ show effective dates instead of actual dates


inAccount :: [QueryOpt] -> Maybe (AccountName, Bool)Source

The account we are currently focussed on, if any, and whether subaccounts are included. Just looks at the first query option.

inAccountMatcher :: [QueryOpt] -> Maybe MatcherSource

A matcher for the account(s) we are currently focussed on, if any. Just looks at the first query option.

parseQuery :: Day -> String -> (Matcher, [QueryOpt])Source

Convert a query expression containing zero or more space-separated terms to a matcher and zero or more query options. A query term is either:

  1. a search criteria, used to match transactions. This is usually a prefixed pattern such as: acct:REGEXP date:PERIODEXP not:desc:REGEXP
  2. a query option, which changes behaviour in some way. There is currently one of these: inacct:FULLACCTNAME - should appear only once

Multiple search criteria are AND'ed together. When a pattern contains spaces, it or the whole term should be enclosed in single or double quotes. A reference date is required to interpret relative dates in period expressions.

words'' :: [String] -> String -> [String]Source

Quote-and-prefix-aware version of words - don't split on spaces which are inside quotes, including quotes which may have one of the specified prefixes in front, and maybe an additional not: prefix in front of that.

parseMatcher :: Day -> String -> Either Matcher QueryOptSource

Parse a single query term as either a matcher or a query option.

parseStatus :: String -> BoolSource

Parse the boolean value part of a status: matcher, allowing * as another way to spell True, similar to the journal file format.

parseBool :: String -> BoolSource

Parse the boolean value part of a status: matcher. A true value can be spelled as 1, t or true.

negateMatcher :: Matcher -> MatcherSource

Convert a match expression to its inverse.

matchesPosting :: Matcher -> Posting -> BoolSource

Does the match expression match this posting ?

matchesTransaction :: Matcher -> Transaction -> BoolSource

Does the match expression match this transaction ?

matchesAccount :: Matcher -> AccountName -> BoolSource

Does the match expression match this account ? A matching in: clause is also considered a match.

matcherStartDate :: Bool -> Matcher -> Maybe DaySource

What start date does this matcher specify, if any ? If the matcher is an OR expression, returns the earliest of the alternatives. When the flag is true, look for a starting effective date instead.

matcherIsStartDateOnly :: Bool -> Matcher -> BoolSource

Does this matcher specify a start date and nothing else (that would filter postings prior to the date) ? When the flag is true, look for a starting effective date instead.

earliestMaybeDate :: [Maybe Day] -> Maybe DaySource

Does this matcher match everything ?

What is the earliest of these dates, where Nothing is earliest ?

latestMaybeDate :: [Maybe Day] -> Maybe DaySource

What is the latest of these dates, where Nothing is earliest ?

compareMaybeDates :: Maybe Day -> Maybe Day -> OrderingSource

Compare two maybe dates, Nothing is earliest.