-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (49 loc) · 1.15 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
package main
import (
"fmt"
logger "github.com/sirupsen/logrus"
"leango/Logger"
"leango/Token"
"log"
"os"
"strings"
)
func checkErr(e error) {
if e != nil {
panic(e)
}
}
func Split(r rune) bool {
return r == ' ' || r == '\t'
}
func parseFile(filePath string) {
var tokens []string
var tokenFunctions map[string]func([]string, int) = Token.Handler()
data, err := os.ReadFile(filePath)
checkErr(err)
lines := strings.Split(string(data), "\n")
for idxLine, line := range lines {
if line != "" {
tokens = strings.FieldsFunc(line, Split)
for idx, token := range tokens {
_, varNameExists := tokenFunctions[token]
if idx > 0 && varNameExists {
Logger.Fatal(idxLine, "you can't name a variable with the same name as a type")
}
if Token.IsTokenAvailable(token) {
tokenFunctions[token](tokens, idx+1)
}
}
}
}
Token.ShowVariables()
}
func main() {
if len(os.Args) != 2 {
log.Default().Fatal("not enough arguments\n./leango [filepath]")
}
if !strings.HasSuffix(os.Args[1], ".leango") {
logger.WithFields(logger.Fields{}).Fatal(fmt.Sprintf("incorrect file extension [%s]", os.Args[1]))
}
parseFile(os.Args[1])
}