all repos

clerk @ d12c079

missing tooling for ledger/hledger

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
ast: inline leaf value+span wrapper structs, 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     string
65
	NameSpan token.Span
66
	Comment  *Comment
67
	Span     token.Span
68
}
69
70
func (PayeeDirective) entryNode() {}
71
72
type TagDirective struct {
73
	Name    string
74
	Comment *Comment // optional inline comment
75
	Span    token.Span
76
}
77
78
func (TagDirective) entryNode() {}
79
80
type IncludeDirective struct {
81
	Path    string
82
	Comment *Comment // optional inline comment
83
	Span    token.Span
84
}
85
86
func (IncludeDirective) entryNode() {}
87
88
type AliasDirective struct {
89
	From, To Account
90
	Comment  *Comment // optional inline comment
91
	Span     token.Span
92
}
93
94
func (AliasDirective) entryNode() {}
95
96
type YearDirective struct {
97
	Year    int
98
	Comment *Comment // optional inline comment
99
	Span    token.Span
100
}
101
102
func (YearDirective) entryNode() {}
103
104
type DecimalMarkDirective struct {
105
	Mark    byte     // '.' ','
106
	Comment *Comment // optional inline comment
107
	Span    token.Span
108
}
109
110
func (DecimalMarkDirective) entryNode() {}
111
112
type DefaultCommodityDirective struct {
113
	Amount  Amount
114
	Comment *Comment // optional inline comment
115
	Span    token.Span
116
}
117
118
func (DefaultCommodityDirective) entryNode() {}
119
120
type MarketPriceDirective struct {
121
	DateTime  DateTime
122
	Commodity string
123
	Amount    Amount
124
	Comment   *Comment // optional inline comment
125
	Span      token.Span
126
}
127
128
func (MarketPriceDirective) entryNode() {}
129
130
type ConversionDirective struct {
131
	From    Amount
132
	To      Amount
133
	Comment *Comment // optional inline comment
134
	Span    token.Span
135
}
136
137
func (ConversionDirective) entryNode() {}
138
139
type ApplyDirective struct {
140
	Expr    string // text after apply e.g "tag foo"
141
	Comment *Comment
142
	Span    token.Span
143
}
144
145
func (ApplyDirective) entryNode() {}
146
147
type EndDirective struct {
148
	Expr    string   // text after end e.g "tag"
149
	Comment *Comment // optional inline comment
150
	Span    token.Span
151
}
152
153
func (EndDirective) entryNode() {}
154
155
type CommentBlockDirective struct {
156
	Header  string // text after "comment" on the same line
157
	Content string
158
	Comment *Comment // optional inline comment
159
	Span    token.Span
160
}
161
162
func (CommentBlockDirective) entryNode() {}
163
164
type IgnoredDirective struct {
165
	Text    string   // content after N (commodity symbol or text)
166
	Comment *Comment // optional inline comment
167
	Span    token.Span
168
}
169
170
func (IgnoredDirective) entryNode() {}