all repos

clerk @ 2298caf

missing tooling for ledger/hledger

clerk/internal/analyzer/analyzer.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
ast: inline leaf value+span wrapper structs, 1 month ago
1
package analyzer
2
3
import (
4
	"olexsmir.xyz/clerk/journal"
5
	"olexsmir.xyz/clerk/journal/ast"
6
	"olexsmir.xyz/clerk/journal/token"
7
)
8
9
type Analysis struct {
10
	Files []*journal.ParsedFile
11
12
	Transactions          []*ast.Transaction
13
	PeriodicTransactions  []*ast.PeriodicTransaction
14
	AutomatedTransactions []*ast.AutomatedTransaction
15
	Directives            []ast.Entry // account, commodity, payee, etc
16
17
	Accounts    map[string]*AccountInfo
18
	Commodities map[string]*CommodityInfo
19
	Payees      map[string]*PayeeInfo
20
21
	AccountAliases  map[string]string     // maps alias names to the account they resovle to
22
	AliasDirectives []*ast.AliasDirective // holds every top-level "alias A = B" directive in entry order
23
24
	AccountNames     []string            // sorted for binary search
25
	PayeeNames       []string            // sorted, all payee names from directives + usage
26
	AccountsByPrefix map[string][]string // "expenses:" -> ["expenses:food", "expenses:taxi"]
27
28
	Tags      map[string]*TagInfo
29
	TagNames  []string // unique tag names, sorted
30
	TagValues []string // unique non-empty tag values across all tags, sorted
31
32
	Dates       []ast.Date // unique transaction dates, sorted
33
	DateStrings []string   // same order as Dates, rendered as written
34
35
	TransactionsCountByDate map[string]int                // counts transactions per date, keyed by [Date.String]
36
	TransactionsByKey       map[string][]*ast.Transaction // groups transactions by [TxDuplicateKey] signature
37
}
38
39
type AccountInfo struct {
40
	Directives []*ast.AccountDirective
41
	Usages     []AccountUsage
42
	UsedCount  int
43
	LastUsed   ast.Date
44
}
45
46
type AccountUsage struct {
47
	FileIndex int
48
	Posting   *ast.Posting
49
}
50
51
type CommodityInfo struct {
52
	Directives []*ast.CommodityDirective
53
	Usages     []CommodityUsage
54
	UsedCount  int
55
	LastUsed   ast.Date
56
}
57
58
type CommodityUsage struct {
59
	FileIndex int
60
	Amount    *ast.Amount
61
}
62
63
type PayeeInfo struct {
64
	Directives []*ast.PayeeDirective
65
	Usage      []PayeeUsage
66
	UsedCount  int
67
	LastUsed   ast.Date
68
}
69
70
type PayeeUsage struct {
71
	FileIndex int
72
	Name      string
73
	Span      token.Span
74
}
75
76
type TagInfo struct {
77
	Directives []*ast.TagDirective
78
	Usage      []TagUsage
79
	UsedCount  int
80
	LastUsed   ast.Date
81
	Values     []string // unique non-empty values from comment usages, sorted
82
}
83
84
type TagUsage struct {
85
	FileIndex int
86
	Tag       *ast.Tag
87
}
88
89
type PostingTemplate struct {
90
	Account    string
91
	Amount     string
92
	Commodity  string
93
	IsInferred bool // true if the amount was inferred (auto-balanced)
94
}