MCPcopy
hub / github.com/expr-lang/expr / main

Function main

repl/repl.go:28–103  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26}
27
28func main() {
29 env := fuzz.NewEnv()
30 for name := range env {
31 keywords = append(keywords, name)
32 }
33 fn := fuzz.Func()
34 keywords = append(keywords, "fn")
35 home, err := os.UserHomeDir()
36 if err != nil {
37 panic(err)
38 }
39 rl, err := readline.NewEx(&readline.Config{
40 Prompt: "❯ ",
41 AutoComplete: completer{append(builtin.Names, keywords...)},
42 HistoryFile: home + "/.expr_history",
43 })
44 if err != nil {
45 panic(err)
46 }
47 defer rl.Close()
48
49 var memUsage uint64
50 var program *vm.Program
51
52 for {
53 line, err := rl.Readline()
54 if err != nil { // io.EOF when Ctrl-D is pressed
55 break
56 }
57 line = strings.TrimSpace(line)
58
59 switch line {
60 case "":
61 continue
62
63 case "exit":
64 return
65
66 case "mem":
67 fmt.Printf("memory usage: %s\n", humanizeBytes(memUsage))
68 continue
69
70 case "opcodes":
71 if program == nil {
72 fmt.Println("no program")
73 continue
74 }
75 fmt.Println(program.Disassemble())
76 continue
77
78 case "debug":
79 if program == nil {
80 fmt.Println("no program")
81 continue
82 }
83 debug.StartDebugger(program, env)
84 continue
85 }

Callers

nothing calls this directly

Calls 12

DisassembleMethod · 0.95
NewEnvFunction · 0.92
FuncFunction · 0.92
StartDebuggerFunction · 0.92
CompileFunction · 0.92
EnvStruct · 0.92
RunFunction · 0.92
humanizeBytesFunction · 0.85
memoryUsageFunction · 0.85
CloseMethod · 0.80
PrintfMethod · 0.80
PrintlnMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…