all repos

clerk @ 225a2d31a31f0501b2133d0747baf2ebeba5a0d4

missing tooling for ledger/hledger

clerk/journal/ast/entries.go (view raw)

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
linter: add missing-payee rule, 1 month ago
1
package ast
2
3
import (
4
	"olexsmir.xyz/clerk/internal/decimal"
5
	"olexsmir.xyz/clerk/journal/token"
6
)
7
8
type BlankLine struct{ Span token.Span }
9
10
func (BlankLine) entryNode() {}
11
12
type Transaction struct {
13
	Date           Date
14
	SecondDate     *Date      // optional =2026-05-18 date
15
	Status         Status     // optional */! status
16
	Code           *string    // optional (123) code
17
	Payee          *Payee     // optional payee
18
	Note           *string    // part after |
19
	Comment        *Comment   // inline ; on header line
20
	HeaderComments []*Comment // indented ; lines before first posting
21
	Postings       []*Posting
22
	Span           token.Span
23
}
24
25
func (Transaction) entryNode() {}
26
27
type Period struct {
28
	Raw  string // "monthly", "every 2 weeks"
29
	From *Date
30
	To   *Date
31
	Span token.Span
32
}
33
34
func (Period) entryNode() {}
35
36
type PeriodicTransaction struct {
37
	Period         Period   // period-expr
38
	Status         Status   // optional */! status
39
	Code           *string  // optional (123) code
40
	Description    *string  // optional description
41
	Comment        *Comment // optional inline comment
42
	HeaderComments []*Comment
43
	Postings       []*Posting
44
	Span           token.Span
45
}
46
47
func (PeriodicTransaction) entryNode() {}
48
49
type AutomatedTransaction struct {
50
	Expr           string
51
	Postings       []*Posting
52
	Comment        *Comment   // inline ; on header line
53
	HeaderComments []*Comment // indented ; lines before first posting
54
	Span           token.Span
55
}
56
57
func (AutomatedTransaction) entryNode() {}
58
59
type PostingType int
60
61
const (
62
	PostingReal              PostingType = iota
63
	PostingVirtualBalanced               // '['
64
	PostingVirtualUnbalanced             // '('
65
)
66
67
func (p PostingType) String() string {
68
	switch p {
69
	case PostingReal:
70
		return "real"
71
	case PostingVirtualBalanced:
72
		return "balanced virtual"
73
	case PostingVirtualUnbalanced:
74
		return "unbalanced virtual"
75
	default:
76
		panic("unreachable")
77
	}
78
}
79
80
type Posting struct {
81
	Type     PostingType
82
	Status   Status
83
	Account  Account
84
	Amount   *Amount // nil == auto-balancing
85
	Cost     *Cost   // @ @@
86
	Balance  *BalanceAssertion
87
	Comment  *Comment
88
	Comments []Comment // continuation comment lines
89
	Span     token.Span
90
}
91
92
type Amount struct {
93
	IsNegative   bool
94
	Quantity     decimal.Decimal
95
	QuantityFmt  QuantityFormat
96
	Commodity    string
97
	CommodityPos CommodityPos // Before | After
98
	HasSpace     bool         // "$10" vs "$ 10"
99
	IsExpr       bool         // e.g: *-1
100
	Expr         string       // expression text e.g. "amount * -1". set only if IsExpr is true
101
	Span         token.Span
102
}
103
104
type Cost struct {
105
	IsTotal bool // @ vs @@
106
	Amount  Amount
107
	Span    token.Span
108
}
109
110
type BalanceAssertion struct {
111
	IsStrict    bool // ==  vs =
112
	IsInclusive bool // ===
113
	Amount      Amount
114
	Cost        *Cost // price after @/@@
115
	Span        token.Span
116
}
117
118
type CommodityPos int
119
120
func (c CommodityPos) String() string {
121
	if c == CommodityBefore {
122
		return "Before"
123
	}
124
	return "After"
125
}
126
127
const (
128
	CommodityBefore CommodityPos = iota
129
	CommodityAfter
130
)
131
132
type QuantityFormat struct {
133
	Decimal   byte // '.' or ','
134
	Thousands byte // ',' '.' ' ' or 0
135
	Precision int
136
}