summaryrefslogtreecommitdiffstats
path: root/token.go
blob: a6b08b9c52c35c4a190c9dbbf5ee7ec291d60088 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package cnm

// Token represents a parsed line in a CNM document.
type Token interface {
	Indent() int
	Raw() string
	Line() int
}

// TokenLine represents an arbitrary CNM line.
type TokenLine struct {
	Indentation int
	RawLine     string
	LineNo      int
}

// Indent returns the indentation of the parsed line.
func (t *TokenLine) Indent() int { return t.Indentation }

// Raw returns the original unparsed line.
func (t *TokenLine) Raw() string { return t.RawLine }

// Line returns the line number in the document, starting from 1.
func (t *TokenLine) Line() int { return t.LineNo }

// TokenEmptyLine represents an empty line.
//
// A line is empty as long as it contains up to as many tab characters as the
// line's indentation and nothing else.
type TokenEmptyLine struct {
	TokenLine
}

// TokenBlock represents a block header line.
type TokenBlock struct {
	TokenLine
	// Parent is the parent block
	Parent *TokenBlock
	// Name is the block name.
	Name string
	// Args are the block arguments, split by whitespace and then parsed as
	// simple text.
	Args []string
}

// TokenSimpleText represents a line of simple text.
type TokenSimpleText struct {
	TokenLine
	// Text is the line contents parsed as simple text.
	Text string
}

// TokenRawText represents a non-empty line with unparsed contents.
type TokenRawText struct {
	TokenLine
	// Text is the raw contents of the line with the indentation removed.
	Text string
}