Scan 提取文件中的变量
(file *model.File)
| 58 | |
| 59 | // Scan 提取文件中的变量 |
| 60 | func (v Variable) Scan(file *model.File) { |
| 61 | |
| 62 | if file == nil { |
| 63 | return |
| 64 | } |
| 65 | |
| 66 | var text string |
| 67 | file.OpenReader(func(reader io.Reader) { |
| 68 | data, _ := io.ReadAll(reader) |
| 69 | text = string(data) |
| 70 | }) |
| 71 | |
| 72 | blockIndex := startReg.FindAllStringIndex(text, -1) |
| 73 | for i, bi := range blockIndex { |
| 74 | end := len(text) |
| 75 | if i+1 < len(blockIndex) { |
| 76 | end = blockIndex[i+1][0] |
| 77 | } |
| 78 | m := startReg.FindStringSubmatch(text[bi[0]:bi[1]]) |
| 79 | var object string |
| 80 | if len(m) == 2 { |
| 81 | object = m[1] |
| 82 | } |
| 83 | if object == "" { |
| 84 | continue |
| 85 | } |
| 86 | for line := range strings.SplitSeq(text[bi[1]:end], "\n") { |
| 87 | match := varReg.FindStringSubmatch(line) |
| 88 | if len(match) == 3 { |
| 89 | if object == "ext" { |
| 90 | v[match[1]] = match[2] |
| 91 | } |
| 92 | v[fmt.Sprintf("%s.%s", object, match[1])] = match[2] |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | } |
no test coverage detected