-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (44 loc) · 943 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
package main
import (
Alpha "alpha/alpha"
"alpha/alpha/io"
"alpha/alpha/std/color"
"fmt"
"os"
"strings"
)
var AcceptedSuffix []string = []string{
".sundi",
".sdi",
".alpha",
".alp",
}
func IsCorrectFileExtension(value string) bool {
for _, suffix := range AcceptedSuffix {
if strings.HasSuffix(value, suffix) {
return true
}
}
return false
}
func main() {
// fmt.Println(Alpha.VARIABLE_DEFINE_PATTERN)
args_len := len(io.Args)
if args_len == 0 {
fmt.Println("No arguments presented")
os.Exit(0)
}
path := io.Args[0]
if !io.FileExists(path) {
color.Printf("&4error&r: file not found '%s'\n", path)
os.Exit(-1)
}
content := io.Readfile(path)
if !IsCorrectFileExtension(path) {
accepted := strings.Join(AcceptedSuffix, ", ")
color.Printf("&4error&r: invalid file extension, accepted extensions %s\n", accepted)
os.Exit(-1)
}
instance := Alpha.NewInstance(content, path)
instance.Execute()
}