1 Star 0 Fork 0

jackytse / tabtoy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
checker.go 1.70 KB
一键复制 编辑 原始数据 按行查看 历史
package compiler
import (
"gitee.com/jackytse/tabtoy/v3/model"
"gitee.com/jackytse/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())
}
}
}
}
}
Go
1
https://gitee.com/jackytse/tabtoy.git
git@gitee.com:jackytse/tabtoy.git
jackytse
tabtoy
tabtoy
v0.1.0

搜索帮助