-
Notifications
You must be signed in to change notification settings - Fork 5
/
import.go
45 lines (41 loc) · 934 Bytes
/
import.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
package udwGoParser
import "github.com/tachyon-protocol/udw/udwGoSource/udwGoReader"
func (gofile *file) readImport(r *udwGoReader.Reader) {
r.MustReadMatch([]byte("import"))
r.ReadAllSpace()
if r.IsEof() {
panic(r.GetFileLineInfo() + " unexcept EOF ")
}
b := r.ReadByte()
if b == '(' {
for {
r.ReadAllSpace()
b := r.ReadByte()
if b == ')' {
return
} else {
r.UnreadByte()
gofile.readImportSpec(r)
}
}
} else {
r.UnreadByte()
gofile.readImportSpec(r)
}
}
func (gofile *file) readImportSpec(r *udwGoReader.Reader) {
r.ReadAllSpace()
b := r.ReadByte()
if b == '"' || b == '`' {
r.UnreadByte()
gofile.addImport(string(mustReadGoString(r)), "")
} else if b == '.' {
r.ReadAllSpace()
gofile.addImport(string(mustReadGoString(r)), ".")
} else {
r.UnreadByte()
alias := readIdentifier(r)
r.ReadAllSpace()
gofile.addImport(string(mustReadGoString(r)), string(alias))
}
}