forked from davyxu/tabtoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tab_index.go
75 lines (52 loc) · 1.4 KB
/
tab_index.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
package compiler
import (
"github.com/adamluo159/tabtoy/v3/model"
"path/filepath"
"sort"
"strings"
)
func parseIndexRow(tab *model.DataTable, symbols *model.TypeTable) (pragmaList []*model.IndexDefine) {
for row := 1; row < len(tab.Rows); row++ {
var pragma model.IndexDefine
if !ParseRow(&pragma, tab, row, symbols) {
continue
}
if pragma.Kind == model.TableKind_Type {
pragma.TableType = "TypeDefine"
}
if pragma.TableType == "" {
_, name := filepath.Split(pragma.TableFileName)
pragma.TableType = strings.TrimSuffix(name, filepath.Ext(pragma.TableFileName))
}
pragmaList = append(pragmaList, &pragma)
}
return
}
func LoadIndexTable(globals *model.Globals, fileName string) error {
if fileName == "" {
return nil
}
// 加载原始数据
tabs, err := LoadDataTable(globals.IndexGetter, fileName, "IndexDefine", "IndexDefine", globals.Types)
if err != nil {
return err
}
var pragmaList []*model.IndexDefine
for _, tab := range tabs {
pragmaList = append(pragmaList, parseIndexRow(tab, globals.Types)...)
}
// 按表类型排序,保证类型表先读取
sort.Slice(pragmaList, func(i, j int) bool {
a := pragmaList[i]
b := pragmaList[j]
if a.Kind != b.Kind {
return a.Kind < b.Kind
}
if a.TableType != b.TableType {
return a.TableType < b.TableType
}
return a.TableFileName < b.TableFileName
})
globals.IndexList = pragmaList
return nil
}