-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathast.go
65 lines (52 loc) · 1.09 KB
/
ast.go
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
59
60
61
62
63
64
65
package main
import (
"net"
"strings"
)
type ASTHostLine interface {
Line() int
String() string
}
type ASTComment struct {
Comment string
line int
}
func (c ASTComment) String() string {
return c.Comment + "\n"
}
func (c ASTComment) Line() int { return c.line }
type ASTBlank struct {
Count int
line int
}
func (c ASTBlank) String() string { return strings.Repeat("\n", c.Count) }
func (c ASTBlank) Line() int { return c.line }
type ASTHost struct {
IP net.IP
Aliases []string
line int
comment *ASTComment
}
func (h ASTHost) String() string {
return h.IP.String() + "\t" + strings.Join(h.Aliases, " ")
}
func (h ASTHost) Line() int { return h.line }
type ASTHosts []ASTHostLine
func (h ASTHosts) String() string {
var strs = make([]string, len(h))
for i := range h {
strs[i] = h[i].String()
}
return strings.Join(strs, "")
}
func (h ASTHosts) StringWOComments() string {
var strs = make([]string, len(h))
for i := range h {
if _, ok := h[i].(ASTComment); ok {
strs[i] = "\n"
continue
}
strs[i] = h[i].String()
}
return strings.Join(strs, "")
}