-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (77 loc) · 1.71 KB
/
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
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
package main
import (
"flag"
"fmt"
"github.com/fatih/color"
"io/ioutil"
"nlang/commands"
"nlang/commandsForVars"
"nlang/vars"
"regexp"
"strings"
)
func main() {
path := flag.String("p", "", "a path to nlang file")
flag.Parse()
if *path == "" {
color.Red("Path is empty")
} else {
data, err := ioutil.ReadFile(*path)
if err != nil {
fmt.Println(err)
}
code := regexp.MustCompile("[ ;]").Split(string(data), -1)
i := 0
for i < len(code)-1 {
code[i] = strings.TrimSpace(code[i])
if code[i] == "log" {
if code[i+1] == "%" {
commandsForVars.Log(code[i+2])
} else {
commands.Log(code[i+1])
}
i += 2
} else if code[i] == "add" {
if code[i+1] == "%" {
commandsForVars.Add(code[i+2], code[i+3], code[i+4])
} else {
commands.Add(code[i+1], code[i+2], code[i+3])
}
i++
} else if code[i] == "wait" {
if code[i+2] == "%" {
commandsForVars.Wait(code[i+2])
} else {
commands.Wait(code[i+1])
}
i++
} else if code[i] == "subtract" {
if code[i+2] == "%" {
commandsForVars.Subtract(code[i+2], code[i+3], code[i+4])
} else {
commands.Subtract(code[i+1], code[i+2], code[i+3])
}
i++
} else if code[i] == "multiply" {
if code[i+1] == "%" {
commandsForVars.Multiply(code[i+2], code[i+3], code[i+4])
} else {
commands.Multiply(code[i+1], code[i+2], code[i+3])
}
i++
} else if code[i] == "divide" {
if code[i+1] == "%" {
commandsForVars.Divide(code[i+2], code[i+3], code[i+4])
} else {
commands.Divide(code[i+1], code[i+2], code[i+3])
}
i++
} else if code[i+1] == "<-" {
vars.VariableString(code[i], code[i+2])
i += 2
} else {
i++
}
}
}
}