-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
41 lines (39 loc) · 898 Bytes
/
main.go
File metadata and controls
41 lines (39 loc) · 898 Bytes
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
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"strconv"
"hrm/compiler"
)
func main() {
// Enter level number and path to level source code
// Optionally include -debug flag (for development/testing)
var debug bool
flag.BoolVar(&debug, "debug", false, "Enable compiler debug mode.")
flag.Parse()
if len(flag.Args()) != 2 {
fmt.Printf("Usage: hrm <level> <source path>\n")
os.Exit(1)
}
level, err := strconv.Atoi(flag.Arg(0))
if err != nil {
fmt.Printf("Level must be a positive integer.\n")
os.Exit(1)
}
// Handle reading file source
path := flag.Arg(1)
bytes, err := ioutil.ReadFile(path)
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
source := string(bytes)
if len(source) == 0 {
fmt.Printf("No data read from '%s'.\n", path)
os.Exit(1)
}
// Test level by compiling and comparing with expected values
hrm.TestLevel(level, source, debug)
}