Skip to content

Commit eea41bc

Browse files
committed
Fix prompt of repl
1 parent fb71ce1 commit eea41bc

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

cmd/ecc/main.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,34 +109,39 @@ func runProgram() {
109109

110110
func startRepl() {
111111
scanner := bufio.NewScanner(os.Stdin)
112-
prompt()
112+
fmt.Print("> ")
113+
114+
var (
115+
err error
116+
tree *parser.Tree
117+
program *vm.Program
118+
out interface{}
119+
)
113120

114121
for scanner.Scan() {
115122
line := scanner.Text()
116123

117-
tree, err := parser.Parse(line)
124+
tree, err = parser.Parse(line)
118125
if err != nil {
119126
fmt.Printf("%v\n", err)
120-
continue
127+
goto prompt
121128
}
122129

123-
program, err := compiler.Compile(tree)
130+
program, err = compiler.Compile(tree)
124131
if err != nil {
125132
fmt.Printf("%v\n", err)
126-
continue
133+
goto prompt
127134
}
128135

129-
out, err := vm.Run(program, nil)
136+
out, err = vm.Run(program, nil)
130137
if err != nil {
131138
fmt.Printf("%v\n", err)
132-
continue
139+
goto prompt
133140
}
134141

135142
fmt.Printf("%v\n", litter.Sdump(out))
136-
prompt()
137-
}
138-
}
139143

140-
func prompt() {
141-
fmt.Print("> ")
144+
prompt:
145+
fmt.Print("> ")
146+
}
142147
}

0 commit comments

Comments
 (0)