-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.go
51 lines (46 loc) · 995 Bytes
/
parse.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
package main
import (
"io/fs"
"io/ioutil"
"log"
"path/filepath"
"regexp"
)
func parse(model *Model) error {
err := filepath.Walk(*srcDir, func(path string, info fs.FileInfo, err error) error {
c := filepath.ToSlash(path)
b, err := filepath.Match(*srcFilePattern, filepath.Base(c))
if err != nil {
return err
}
if b {
if err := parseFile(path, model); err != nil {
return err
}
}
return nil
})
return err
}
func parseFile(path string, model *Model) error {
filename := filepath.Base(path)
log.Println("parseFile:", path)
data, err := ioutil.ReadFile(path)
if err != nil {
return err
}
//type BoxTableTable struct {
regNs := regexp.MustCompile(*srcStructPattern)
ns := regNs.FindAllStringSubmatch(string(data), -1)
if len(ns) > 0 {
for _, n := range ns {
//name := strings.TrimSpace(n[1])
log.Println("struct:", n, filename)
model.Structs = append(model.Structs, &SrcStruct{
data: n,
file: filename,
})
}
}
return nil
}