-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (48 loc) · 1.18 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
package main
import (
"fmt"
"io"
"os"
"github.com/elkrammer/irule-validator/config"
"github.com/elkrammer/irule-validator/lexer"
"github.com/elkrammer/irule-validator/parser"
"github.com/elkrammer/irule-validator/repl"
"github.com/spf13/pflag"
)
func main() {
config.SetupFlags()
args := pflag.Args()
if len(args) == 0 {
config.DebugMode = true
repl.Start(os.Stdin, os.Stdout)
return
}
filename := args[0]
content, err := os.ReadFile(filename)
if err != nil {
fmt.Printf("Error reading file :%v\n", err)
os.Exit(1)
}
if config.DebugMode {
fmt.Printf("DEBUG: Input content:\n%s\n", string(content))
}
l := lexer.New(string(content))
p := parser.New(l)
p.ParseProgram()
errors := p.Errors()
if len(errors) > 0 {
fmt.Printf("❌ Errors parsing irule %v\n", filename)
if config.PrintErrors || config.DebugMode {
printParserErrors(os.Stdout, p.Errors())
}
os.Exit(1)
}
// You can add further processing of the parsed program here if needed
fmt.Printf("✅ Successfully parsed irule %v\n", filename)
}
func printParserErrors(out io.Writer, errors []string) {
for _, msg := range errors {
io.WriteString(out, msg)
io.WriteString(out, "\n")
}
}