-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
54 lines (45 loc) · 991 Bytes
/
main.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
package main
import (
"fmt"
"io/ioutil"
"os"
)
func main() {
cfg, err := ParseArgs()
if err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
}
// Check if the file exists
if _, err := os.Stat(cfg.InputFilePath); os.IsNotExist(err) {
fmt.Printf("File '%s' does not exist.\n", cfg.InputFilePath)
os.Exit(1)
}
content, err := ioutil.ReadFile(cfg.InputFilePath)
if err != nil {
fmt.Printf("Error reading file: %s\n", err)
os.Exit(1)
}
tokenizer := NewTokenizer(string(content))
ast, err := Parse(tokenizer)
if err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
}
sql, err := GenerateSQL(ast)
if err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
}
file, err := os.Create(cfg.OutputFilePath)
if err != nil {
fmt.Printf("Error creating file '%s': %v\n", cfg.OutputFilePath, err)
os.Exit(1)
}
defer file.Close()
_, err = file.WriteString(sql)
if err != nil {
fmt.Printf("Error writing to file '%s': %v\n", cfg.OutputFilePath, err)
os.Exit(1)
}
}