all repos

clerk @ e586ae2

missing tooling for ledger/hledger

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
lexer & parser & ast..., 14 days ago
1
package ast
2
3
import "github.com/olexsmir/ledger-tools/journal/token"
4
5
type Journal struct {
6
	Entries []Entry
7
	Errors  []*ParseError
8
}
9
10
type Entry interface {
11
	entryNode()
12
}
13
14
type ParseError struct {
15
	Span    token.Span
16
	Message string
17
}
18
19
type FileError struct {
20
	Path    string
21
	Span    token.Span
22
	Message string
23
}
24
25
type Date struct {
26
	Year, Month, Day int
27
	Sep              byte //  '-' '/' '.'
28
	Span             token.Span
29
}
30
31
type Time struct {
32
	Hour, Minute, Second int
33
	Span                 token.Span
34
}
35
36
type DateTime struct {
37
	Date Date
38
	Time *Time
39
	Span token.Span
40
}
41
42
type Comment struct {
43
	Marker byte // ';' '#' '%' '*'
44
	Text   string
45
	Span   token.Span
46
}
47
48
func (Comment) entryNode() {}
49
50
type StatusType int
51
52
func (s StatusType) String() string {
53
	switch s {
54
	case StatusCleared:
55
		return "*"
56
	case StatusPending:
57
		return "!"
58
	case StatusNone:
59
		return ""
60
	default:
61
		panic("unreachable")
62
	}
63
}
64
65
const (
66
	StatusCleared StatusType = iota // * cleared
67
	StatusPending                   // ! pending
68
	StatusNone                      // not set
69
)
70
71
type Status struct {
72
	// Value byte // '!' '*'
73
	Value StatusType
74
	Span  token.Span
75
}
76
77
type Payee struct {
78
	Name string
79
	Span token.Span
80
}
81
82
type Account struct {
83
	Name string // 'expenses:food'
84
	Span token.Span
85
}