all repos

clerk @ 0b03250

missing tooling for ledger/hledger

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
rename to clerk, 14 days ago
1
package ast
2
3
import (
4
	"olexsmir.xyz/clerk/journal/token"
5
	"github.com/shopspring/decimal"
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
15
	Status         *Status
16
	Code           *string
17
	Payee          *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
38
	Status         *Status
39
	Code           *string
40
	Description    *string
41
	Note           *string
42
	Comment        *Comment
43
	HeaderComments []*Comment
44
	Postings       []*Posting
45
	Span           token.Span
46
}
47
48
func (PeriodicTransaction) entryNode() {}
49
50
type AutomatedTransaction struct {
51
	Expr           string
52
	Postings       []*Posting
53
	Comment        *Comment   // inline ; on header line
54
	HeaderComments []*Comment // indented ; lines before first posting
55
	Span           token.Span
56
}
57
58
func (AutomatedTransaction) entryNode() {}
59
60
type PostingType int
61
62
const (
63
	PostingReal              PostingType = iota
64
	PostingVirtualBalanced               // '['
65
	PostingVirtualUnbalanced             // '('
66
)
67
68
func (p PostingType) String() string {
69
	switch p {
70
	case PostingReal:
71
		return "real"
72
	case PostingVirtualBalanced:
73
		return "balanced virtual"
74
	case PostingVirtualUnbalanced:
75
		return "unbalanced virtual"
76
	default:
77
		panic("unreachable")
78
	}
79
}
80
81
type Posting struct {
82
	Type     PostingType
83
	Status   *Status
84
	Account  Account
85
	Amount   *Amount // nil == auto-balancing
86
	Cost     *Cost   // @ @@
87
	Balance  *BalanceAssertion
88
	Comment  *Comment
89
	Comments []Comment // continuation comment lines
90
	Span     token.Span
91
}
92
93
type Amount struct {
94
	IsNegative   bool
95
	Quantity     decimal.Decimal
96
	QuantityFmt  QuantityFormat
97
	Commodity    string
98
	CommodityPos CommodityPos // Before | After
99
	HasSpace     bool         // "$10" vs "$ 10"
100
	IsExpr       bool         // e.g: *-1
101
	Expr         string       // expression text e.g. "amount * -1". set only if IsExpr is true
102
	Span         token.Span
103
}
104
105
type Cost struct {
106
	IsTotal bool // @ vs @@
107
	Amount  *Amount
108
	Span    token.Span
109
}
110
111
type BalanceAssertion struct {
112
	IsStrict    bool // ==  vs =
113
	IsInclusive bool // ===
114
	Amount      Amount
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
}