all repos

clerk @ 336ef9125580710f81bc59d0743eb25def0e505b

missing tooling for ledger/hledger

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
ast: add enum for subdirective kinds, 1 month ago
1
package ast
2
3
import "olexsmir.xyz/clerk/journal/token"
4
5
type AccountDirective struct {
6
	Account       Account
7
	Subdirectives []AccountSubdirective // indented block lines, in order
8
	Comment       *Comment
9
	Span          token.Span
10
}
11
12
func (AccountDirective) entryNode() {}
13
14
type AccountSubdirectiveKind uint8
15
16
const (
17
	SubdirectiveComment AccountSubdirectiveKind = iota
18
	SubdirectiveAlias
19
	SubdirectiveType
20
	SubdirectiveNote
21
)
22
23
func (k AccountSubdirectiveKind) String() string {
24
	switch k {
25
	case SubdirectiveAlias:
26
		return "alias"
27
	case SubdirectiveType:
28
		return "type"
29
	case SubdirectiveNote:
30
		return "note"
31
	default:
32
		panic("unreachable")
33
	}
34
}
35
36
type AccountSubdirective struct {
37
	Kind      AccountSubdirectiveKind // keyword; SubdirectiveComment for comment lines
38
	NameSpan  token.Span              // keyword span; for comment lines, the marker span
39
	Value     string                  // text after the keyword; "" for comment lines
40
	ValueSpan token.Span              // value span; zero for comment lines and empty values
41
	Comment   *Comment                // inline comment after the value; for comment lines, the line itself
42
}
43
44
type CommodityDirective struct {
45
	Commodity     string
46
	CommoditySpan token.Span          // span of the commodity token
47
	FormatSub     *FormatSubDirective // display format; nil when not given
48
	BlockComments []*Comment          // indented comment-only lines inside the block
49
	Comment       *Comment            // optional inline comment
50
	Span          token.Span
51
}
52
53
func (CommodityDirective) entryNode() {}
54
55
// FormatSubDirective is a commodity display format, either inline on the
56
// directive line ("commodity $1,000.00") or as a "format" subdirective.
57
type FormatSubDirective struct {
58
	Amount      Amount
59
	KeywordSpan token.Span // span of the "format" keyword; zero when inline
60
	Comment     *Comment   // inline comment; subdirective form only
61
}
62
63
type PayeeDirective struct {
64
	Name    *Payee
65
	Comment *Comment
66
	Span    token.Span
67
}
68
69
func (PayeeDirective) entryNode() {}
70
71
type TagDirective struct {
72
	Name    string
73
	Comment *Comment // optional inline comment
74
	Span    token.Span
75
}
76
77
func (TagDirective) entryNode() {}
78
79
type IncludeDirective struct {
80
	Path    string
81
	Comment *Comment // optional inline comment
82
	Span    token.Span
83
}
84
85
func (IncludeDirective) entryNode() {}
86
87
type AliasDirective struct {
88
	From, To Account
89
	Comment  *Comment // optional inline comment
90
	Span     token.Span
91
}
92
93
func (AliasDirective) entryNode() {}
94
95
type YearDirective struct {
96
	Year    int
97
	Comment *Comment // optional inline comment
98
	Span    token.Span
99
}
100
101
func (YearDirective) entryNode() {}
102
103
type DecimalMarkDirective struct {
104
	Mark    byte     // '.' ','
105
	Comment *Comment // optional inline comment
106
	Span    token.Span
107
}
108
109
func (DecimalMarkDirective) entryNode() {}
110
111
type DefaultCommodityDirective struct {
112
	Amount  Amount
113
	Comment *Comment // optional inline comment
114
	Span    token.Span
115
}
116
117
func (DefaultCommodityDirective) entryNode() {}
118
119
type MarketPriceDirective struct {
120
	DateTime  DateTime
121
	Commodity string
122
	Amount    Amount
123
	Comment   *Comment // optional inline comment
124
	Span      token.Span
125
}
126
127
func (MarketPriceDirective) entryNode() {}
128
129
type ConversionDirective struct {
130
	From    Amount
131
	To      Amount
132
	Comment *Comment // optional inline comment
133
	Span    token.Span
134
}
135
136
func (ConversionDirective) entryNode() {}
137
138
type ApplyDirective struct {
139
	Expr    string // text after apply e.g "tag foo"
140
	Comment *Comment
141
	Span    token.Span
142
}
143
144
func (ApplyDirective) entryNode() {}
145
146
type EndDirective struct {
147
	Expr    string   // text after end e.g "tag"
148
	Comment *Comment // optional inline comment
149
	Span    token.Span
150
}
151
152
func (EndDirective) entryNode() {}
153
154
type CommentBlockDirective struct {
155
	Header  string // text after "comment" on the same line
156
	Content string
157
	Comment *Comment // optional inline comment
158
	Span    token.Span
159
}
160
161
func (CommentBlockDirective) entryNode() {}
162
163
type IgnoredDirective struct {
164
	Text    string   // content after N (commodity symbol or text)
165
	Comment *Comment // optional inline comment
166
	Span    token.Span
167
}
168
169
func (IgnoredDirective) entryNode() {}