all repos

clerk @ 6106d588c3cc8b0aa2d551af7c80a0e8268ae14a

missing tooling for ledger/hledger

clerk/journal/semantic/context.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
journal/semantic: collect payees, 1 month ago
1
package semantic
2
3
import (
4
	"olexsmir.xyz/clerk/journal"
5
	"olexsmir.xyz/clerk/journal/ast"
6
)
7
8
// Context holds workspace-level semantic data built from parsed journal files.
9
type Context struct {
10
	// Files in dependency order (includes before includers).
11
	Files []*journal.ParsedFile
12
13
	Accounts    map[string]*AccountInfo
14
	Commodities map[string]*CommodityInfo
15
	Payees      map[string]*PayeeInfo
16
}
17
18
type AccountInfo struct {
19
	// len == 0 =  account is used but never declared (undeclared)
20
	// len  > 1 = account is declared more than once (duplicated)
21
	// len  > 0 = account appears in a posting
22
	Directives []*ast.AccountDirective
23
	Usages     []AccountUsage
24
}
25
26
// AccountUsage is a single posting that references an account.
27
type AccountUsage struct {
28
	FileIndex int
29
	Posting   *ast.Posting
30
}
31
32
// CommodityInfo tracks all declarations and usages for one commodity.
33
type CommodityInfo struct {
34
	Directives []*ast.CommodityDirective
35
	Usages     []CommodityUsage
36
}
37
38
// CommodityUsage is a single amount that references a commodity.
39
type CommodityUsage struct {
40
	FileIndex int
41
	Amount    *ast.Amount
42
}
43
44
type PayeeInfo struct {
45
	Directives []*ast.Payee
46
	Usage      []PayeeUsage
47
}
48
49
type PayeeUsage struct {
50
	FileIndex int
51
	Payee     *ast.Payee
52
}