all repos

clerk @ cb14fd1f70ffde11a56b98a07cebd7091dff1d83

missing tooling for ledger/hledger

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

Oleksandr Smirnov Oleksandr Smirnov
olexsmir@gmail.com
lexer & parser & ast..., 14 days 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
	AT     // @
58
	ATAT   // @@
59
	PIPE   // |
60
	PLUS   // +
61
	MINUS  // -
62
	TILDE  // ~
63
64
	LPAREN       // (
65
	RPAREN       // )
66
	LBRACE       // {
67
	LBRACELBRACE // {{
68
	RBRACERBRACE // }}
69
	RBRACE       // }
70
	LBRACKET     // [
71
	RBRACKET     // ]
72
73
	COMMODITYMARK // USD, $, £, "my fund"
74
	DATE          // 2024/01/01 / 2024-01-01
75
	TIME          // 12:00:00
76
	PARENEXPR     // (...) parenthesized expression in amount
77
78
	// directives
79
	COMMENTKW   // "comment"
80
	ACCOUNT     // "account"
81
	COMMODITY   // "commodity"
82
	INCLUDE     // "include"
83
	ALIAS       // "alias"
84
	PAYEE       // "payee"
85
	TAG         // "tag"
86
	APPLY       // "apply"
87
	END         // "end"
88
	YEAR        // "Y" or "year"
89
	DECIMALMARK // "decimal-mark"
90
	D           // "D" default commodity
91
	P           // "P" market price
92
	N           // "N" ignored price commodity
93
)