aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/homemade/scl/scanner_line.go
blob: 972c7662ab6f1ff17460f519c901d6e5f649ae53 (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
package scl

import (
	"fmt"
	"strings"
)

type lineContent string

func (s lineContent) indent() int {
	return len(s) - len(strings.TrimLeft(string(s), " \t"))
}

type scannerLine struct {
	file     string
	line     int
	column   int
	content  lineContent
	children scannerTree
}

func newLine(fileName string, lineNumber, column int, content string) *scannerLine {
	return &scannerLine{
		file:     fileName,
		line:     lineNumber,
		column:   column,
		content:  lineContent(content),
		children: make(scannerTree, 0),
	}
}

func (l *scannerLine) branch() *scannerLine {
	return newLine(l.file, l.line, l.content.indent(), strings.Trim(string(l.content), " \t"))
}

func (l *scannerLine) String() string {
	return fmt.Sprintf("%s:%d", l.file, l.line)
}