all repos

clerk @ 1f6bd77466d05af3033931d98b68dc9c430fa662

missing tooling for ledger/hledger

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
syntax: respect commodity format; =*; ===; :=, 2 months ago
1
package token
2
3
import "fmt"
4
5
type Type int
6
7
type Token struct {
8
	Type    Type
9
	Literal string
10
	Span    Span
11
}
12
13
type Span struct{ Start, End Pos }
14
15
func (s Span) String() string {
16
	if s.Start.File != "" {
17
		return fmt.Sprintf("%s:%d:%d-%d:%d", s.Start.File,
18
			s.Start.Line, s.Start.Col,
19
			s.End.Line, s.End.Col)
20
	}
21
	return fmt.Sprintf("%d:%d-%d:%d",
22
		s.Start.Line, s.Start.Col,
23
		s.End.Line, s.End.Col)
24
}
25
26
type Pos struct {
27
	File   string // absolute path, "" for unknow
28
	Offset int
29
	Line   int
30
	Col    int
31
}
32
33
//go:generate go tool stringer -type=Type
34
const (
35
	ILLEGAL Type = iota
36
	EOF
37
38
	WHITESPACE // singe space or tab
39
	INDENT     // leading whitespace (posting/subdirective marker)
40
	NEWLINE    // \n
41
42
	INT     // 42
43
	DECIMAL // 420.69
44
	STRING  // quoted "string"
45
	TEXT    // free text, description, payee, account names
46
47
	BANG      // ! status
48
	STAR      // * status or comment marker
49
	PERCENT   // % comment
50
	HASH      // # comment
51
	SEMICOLON // ; comment or line break
52
	COLON     // :
53
54
	EQ     // =
55
	EQEQ   // ==
56
	EQEQEQ // ===
57
	EQSTAR // =* inclusive balance assertion
58
	AT     // @
59
	ATAT   // @@
60
	PIPE   // |
61
	PLUS   // +
62
	MINUS  // -
63
	TILDE  // ~
64
65
	LPAREN       // (
66
	RPAREN       // )
67
	LBRACE       // {
68
	LBRACELBRACE // {{
69
	RBRACERBRACE // }}
70
	RBRACE       // }
71
	LBRACKET     // [
72
	RBRACKET     // ]
73
74
	COMMODITYMARK // USD, $, £, "my fund"
75
	DATE          // 2024/01/01 / 2024-01-01
76
	TIME          // 12:00:00
77
	PARENEXPR     // (...) parenthesized expression in amount
78
79
	// directives
80
	COMMENTKW   // "comment"
81
	ACCOUNT     // "account"
82
	COMMODITY   // "commodity"
83
	INCLUDE     // "include"
84
	ALIAS       // "alias"
85
	PAYEE       // "payee"
86
	TAG         // "tag"
87
	APPLY       // "apply"
88
	END         // "end"
89
	YEAR        // "Y" or "year"
90
	DECIMALMARK // "decimal-mark"
91
	D           // "D" default commodity
92
	P           // "P" market price
93
	N           // "N" ignored price commodity
94
	C           // "C" commodity conversion
95
)