forked from davyxu/tabtoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.go
82 lines (58 loc) · 1.7 KB
/
checker.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package compiler
import (
"github.com/davyxu/tabtoy/v3/model"
"github.com/davyxu/tabtoy/v3/report"
)
func checkRepeat(globals *model.Globals) {
for _, tab := range globals.Datas.AllTables() {
// 遍历输入数据的每一列
for _, header := range tab.Headers {
// 输入的列头,为空表示改列被注释
if header.TypeInfo == nil {
continue
}
// 这列需要建立索引
if header.TypeInfo.MakeIndex {
checker := map[string]*model.Cell{}
for row := 1; row < len(tab.Rows); row++ {
inputCell := tab.GetCell(row, header.Cell.Col)
// 这行被注释,无效行
if inputCell == nil {
break
}
if _, ok := checker[inputCell.Value]; ok {
report.ReportError("DuplicateValueInMakingIndex", inputCell.String())
} else {
checker[inputCell.Value] = inputCell
}
}
}
}
}
}
// 枚举值的解析是放在输出端处理的, 例如json中, 所以在这里提前检查
func checkEnumValue(globals *model.Globals) {
for _, tab := range globals.Datas.AllTables() {
// 遍历输入数据的每一列
for _, header := range tab.Headers {
// 输入的列头,为空表示改列被注释
if header.TypeInfo == nil {
continue
}
if !globals.Types.IsEnumKind(header.TypeInfo.FieldType) {
continue
}
for row := 1; row < len(tab.Rows); row++ {
inputCell := tab.GetCell(row, header.Cell.Col)
// 这行被注释,无效行
if inputCell == nil {
break
}
resolvedType := globals.Types.ResolveEnumValue(header.TypeInfo.FieldType, inputCell.Value)
if resolvedType == "" {
report.ReportError("UnknownEnumValue", header.TypeInfo.FieldType, inputCell.String())
}
}
}
}
}