-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
74 lines (63 loc) · 1.22 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
package main
import (
"fmt"
kol "kol/cli"
"log"
"os"
"github.com/urfave/cli/v2"
)
func main() {
app := &cli.App{
Name: "Kol",
Usage: "A compiler/interpreter for the best language",
Commands: []*cli.Command{
{
Name: "interpret",
Aliases: []string{"i"},
Usage: "Start Interpreter",
Action: func(cCtx *cli.Context) error {
startInterpreter(cCtx.Args().First())
return nil
},
},
{
Name: "compile",
Aliases: []string{"c"},
Usage: "Start Compiler",
Action: func(cCtx *cli.Context) error {
startCompiler(cCtx.Args().First())
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func startInterpreter(fileName string) {
if len(fileName) == 0 {
kol.StartInterpretedRepl()
return
}
content, err := os.ReadFile(fileName)
if err != nil {
fmt.Printf("Encountered Error: %s\n", err)
return
}
text := string(content)
kol.StartInterpreter(text)
}
func startCompiler(fileName string) {
if len(fileName) == 0 {
kol.StartCompiledRepl()
return
}
content, err := os.ReadFile(fileName)
if err != nil {
fmt.Printf("Encountered Error: %s\n", err)
return
}
text := string(content)
kol.StartCompiler(text)
}