Skip to content

Commit 72001bb

Browse files
committed
Fix UndefVarError: key not defined
Part of #2
1 parent 70f9d26 commit 72001bb

File tree

6 files changed

+407
-116
lines changed

6 files changed

+407
-116
lines changed

src/DebuggerFramework.jl

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -224,91 +224,91 @@ module DebuggerFramework
224224
promptname(level, name) = "$level|$name > "
225225
function RunDebugger(stack, repl = Base.active_repl, terminal = Base.active_repl.t)
226226

227-
state = DebuggerState(stack, 1, repl, nothing, Dict{Symbol, Any}(), nothing, terminal)
228-
229-
# Setup debug panel
230-
panel = LineEdit.Prompt(promptname(state.level, "debug");
231-
prompt_prefix="\e[38;5;166m",
232-
prompt_suffix=Base.text_colors[:white],
233-
on_enter = s->true)
234-
235-
panel.hist = REPL.REPLHistoryProvider(Dict{Symbol,Any}(:debug => panel))
236-
Base.REPL.history_reset_state(panel.hist)
237-
238-
search_prompt, skeymap = Base.LineEdit.setup_search_keymap(panel.hist)
239-
search_prompt.complete = Base.REPL.LatexCompletions()
240-
241-
state.main_mode = panel
242-
243-
panel.on_done = (s,buf,ok)->begin
244-
line = String(take!(buf))
245-
old_level = state.level
246-
if !ok || strip(line) == "q"
247-
LineEdit.transition(s, :abort)
248-
LineEdit.reset_state(s)
249-
return false
250-
end
251-
if isempty(strip(line)) && length(panel.hist.history) > 0
252-
command = panel.hist.history[end]
253-
else
254-
command = strip(line)
255-
end
256-
do_print_status = true
257-
cmd1 = split(command,' ')[1]
258-
do_print_status = try
259-
execute_command(state, state.stack[state.level], Val{Symbol(cmd1)}(), command)
260-
catch err
261-
isa(err, AbstractDiagnostic) || rethrow(err)
262-
caught = false
263-
for interp_idx in length(state.top_interp.stack):-1:1
264-
if process_exception!(state.top_interp.stack[interp_idx], err, interp_idx == length(top_interp.stack))
265-
interp = state.top_interp = state.top_interp.stack[interp_idx]
266-
resize!(state.top_interp.stack, interp_idx)
267-
caught = true
268-
break
269-
end
270-
end
271-
!caught && rethrow(err)
272-
display_diagnostic(STDERR, state.interp.code, err)
273-
println(STDERR)
274-
LineEdit.reset_state(s)
275-
return true
276-
end
277-
if old_level != state.level
278-
panel.prompt = promptname(state.level,"debug")
279-
end
280-
LineEdit.reset_state(s)
281-
if isempty(state.stack)
282-
LineEdit.transition(s, :abort)
283-
LineEdit.reset_state(s)
284-
return false
285-
end
286-
if do_print_status
287-
print_status(Base.pipe_writer(terminal), state)
288-
end
289-
return true
290-
end
291-
292-
const repl_switch = Dict{Any,Any}(
293-
'`' => function (s,args...)
294-
if isempty(s) || position(LineEdit.buffer(s)) == 0
295-
prompt = language_specific_prompt(state, state.stack[1])
296-
buf = copy(LineEdit.buffer(s))
297-
LineEdit.transition(s, prompt) do
298-
LineEdit.state(s, prompt).input_buffer = buf
299-
end
300-
else
301-
LineEdit.edit_insert(s,key)
302-
end
303-
end
304-
)
305-
306-
state.standard_keymap = Dict{Any,Any}[skeymap, LineEdit.history_keymap, LineEdit.default_keymap, LineEdit.escape_defaults]
307-
panel.keymap_dict = LineEdit.keymap([repl_switch;state.standard_keymap])
308-
309-
# Skip evaluated values (e.g. constants)
310-
print_status(Base.pipe_writer(terminal), state)
311-
Base.REPL.run_interface(terminal, LineEdit.ModalInterface([panel,search_prompt]))
227+
state = DebuggerState(stack, 1, repl, nothing, Dict{Symbol, Any}(), nothing, terminal)
228+
229+
# Setup debug panel
230+
panel = LineEdit.Prompt(promptname(state.level, "debug");
231+
prompt_prefix="\e[38;5;166m",
232+
prompt_suffix=Base.text_colors[:white],
233+
on_enter = s->true)
234+
235+
panel.hist = REPL.REPLHistoryProvider(Dict{Symbol,Any}(:debug => panel))
236+
Base.REPL.history_reset_state(panel.hist)
237+
238+
search_prompt, skeymap = Base.LineEdit.setup_search_keymap(panel.hist)
239+
search_prompt.complete = Base.REPL.LatexCompletions()
240+
241+
state.main_mode = panel
242+
243+
panel.on_done = (s,buf,ok)->begin
244+
line = String(take!(buf))
245+
old_level = state.level
246+
if !ok || strip(line) == "q"
247+
LineEdit.transition(s, :abort)
248+
LineEdit.reset_state(s)
249+
return false
250+
end
251+
if isempty(strip(line)) && length(panel.hist.history) > 0
252+
command = panel.hist.history[end]
253+
else
254+
command = strip(line)
255+
end
256+
do_print_status = true
257+
cmd1 = split(command,' ')[1]
258+
do_print_status = try
259+
execute_command(state, state.stack[state.level], Val{Symbol(cmd1)}(), command)
260+
catch err
261+
isa(err, AbstractDiagnostic) || rethrow(err)
262+
caught = false
263+
for interp_idx in length(state.top_interp.stack):-1:1
264+
if process_exception!(state.top_interp.stack[interp_idx], err, interp_idx == length(top_interp.stack))
265+
interp = state.top_interp = state.top_interp.stack[interp_idx]
266+
resize!(state.top_interp.stack, interp_idx)
267+
caught = true
268+
break
269+
end
270+
end
271+
!caught && rethrow(err)
272+
display_diagnostic(STDERR, state.interp.code, err)
273+
println(STDERR)
274+
LineEdit.reset_state(s)
275+
return true
276+
end
277+
if old_level != state.level
278+
panel.prompt = promptname(state.level,"debug")
279+
end
280+
LineEdit.reset_state(s)
281+
if isempty(state.stack)
282+
LineEdit.transition(s, :abort)
283+
LineEdit.reset_state(s)
284+
return false
285+
end
286+
if do_print_status
287+
print_status(Base.pipe_writer(terminal), state)
288+
end
289+
return true
290+
end
291+
292+
const key = '`'
293+
const repl_switch = Dict{Any,Any}(
294+
key => function (s,args...)
295+
if isempty(s) || position(LineEdit.buffer(s)) == 0
296+
prompt = language_specific_prompt(state, state.stack[1])
297+
buf = copy(LineEdit.buffer(s))
298+
LineEdit.transition(s, prompt) do
299+
LineEdit.state(s, prompt).input_buffer = buf
300+
end
301+
else
302+
LineEdit.edit_insert(s,key)
303+
end
304+
end
305+
)
306+
307+
state.standard_keymap = Dict{Any,Any}[skeymap, LineEdit.history_keymap, LineEdit.default_keymap, LineEdit.escape_defaults]
308+
panel.keymap_dict = LineEdit.keymap([repl_switch;state.standard_keymap])
309+
310+
print_status(Base.pipe_writer(terminal), state)
311+
Base.REPL.run_interface(terminal, LineEdit.ModalInterface([panel,search_prompt]))
312312
end
313313

314314
end # module

test/calc/lsrp.multiout

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,214 @@
1+
++++++++++++++++++++++++++++++++++++++++++++++++++
2+
|In statement 1
3+
|1 1 + (9 * (7 / 2))
4+
|2 _1 * 2
5+
|3 _1 + _2
6+
|
7+
|About to run: 7 / 2
8+
|1|debug >
9+
--------------------------------------------------
10+
|AAAAAAAAAAAAAA
11+
|BBCCCCCCCCCCCCCCCCC
12+
|DDCCCCCC
13+
|DDCCCCCCC
14+
|
15+
|CCCCCCCCCCCCCCCCCCC
16+
|EEEEEEEEEE
17+
++++++++++++++++++++++++++++++++++++++++++++++++++
18+
|In statement 1
19+
|1 1 + (9 * (7 / 2))
20+
|2 _1 * 2
21+
|3 _1 + _2
22+
|
23+
|About to run: 7 / 2
24+
|1|debug > s
25+
|In statement 1
26+
|1 1 + (9 * (7 / 2))
27+
|2 _1 * 2
28+
|3 _1 + _2
29+
|
30+
|About to run: 9 * 3.5
31+
|1|debug > s
32+
|In statement 1
33+
|1 1 + (9 * (7 / 2))
34+
|2 _1 * 2
35+
|3 _1 + _2
36+
|
37+
|About to run: 1 + 31.5
38+
|1|debug > s
39+
|In statement 2
40+
|1 1 + (9 * (7 / 2))
41+
|2 _1 * 2
42+
|3 _1 + _2
43+
|4 _1 / 3
44+
|
45+
|About to run: 32.5 * 2
46+
|1|debug >
47+
--------------------------------------------------
48+
|AAAAAAAAAAAAAA
49+
|BBCCCCCCCCCCCCCCCCC
50+
|DDCCCCCC
51+
|DDCCCCCCC
52+
|
53+
|CCCCCCCCCCCCCCCCCCC
54+
|EEEEEEEEEEF
55+
|GGGGGGGGGGGGGG
56+
|HHIIIIIIIIIIIIIIIII
57+
|JJIIIIII
58+
|JJIIIIIII
59+
|
60+
|IIIIIIIIIIIIIIIIIIIII
61+
|EEEEEEEEEEF
62+
|GGGGGGGGGGGGGG
63+
|HHIIIIIIIIIIIIIIIII
64+
|JJIIIIII
65+
|JJIIIIIII
66+
|
67+
|IIIIIIIIIIIIIIIIIIIIII
68+
|EEEEEEEEEEF
69+
|GGGGGGGGGGGGGG
70+
|GGFFFFFFFFFFFFFFFFF
71+
|HHIIIIII
72+
|JJIIIIIII
73+
|JJIIIIII
74+
|
75+
|IIIIIIIIIIIIIIIIIIIIII
76+
|EEEEEEEEEE
77+
++++++++++++++++++++++++++++++++++++++++++++++++++
78+
|In statement 1
79+
|1 1 + (9 * (7 / 2))
80+
|2 _1 * 2
81+
|3 _1 + _2
82+
|
83+
|About to run: 7 / 2
84+
|1|debug > s
85+
|In statement 1
86+
|1 1 + (9 * (7 / 2))
87+
|2 _1 * 2
88+
|3 _1 + _2
89+
|
90+
|About to run: 9 * 3.5
91+
|1|debug > s
92+
|In statement 1
93+
|1 1 + (9 * (7 / 2))
94+
|2 _1 * 2
95+
|3 _1 + _2
96+
|
97+
|About to run: 1 + 31.5
98+
|1|debug > s
99+
|In statement 2
100+
|1 1 + (9 * (7 / 2))
101+
|2 _1 * 2
102+
|3 _1 + _2
103+
|4 _1 / 3
104+
|
105+
|About to run: 32.5 * 2
106+
|1|calc > _1
107+
|32.5
108+
|
109+
|1|debug >
110+
--------------------------------------------------
111+
|AAAAAAAAAAAAAA
112+
|BBCCCCCCCCCCCCCCCCC
113+
|DDCCCCCC
114+
|DDCCCCCCC
115+
|
116+
|CCCCCCCCCCCCCCCCCCC
117+
|EEEEEEEEEEF
118+
|GGGGGGGGGGGGGG
119+
|HHIIIIIIIIIIIIIIIII
120+
|JJIIIIII
121+
|JJIIIIIII
122+
|
123+
|IIIIIIIIIIIIIIIIIIIII
124+
|EEEEEEEEEEF
125+
|GGGGGGGGGGGGGG
126+
|HHIIIIIIIIIIIIIIIII
127+
|JJIIIIII
128+
|JJIIIIIII
129+
|
130+
|IIIIIIIIIIIIIIIIIIIIII
131+
|EEEEEEEEEEF
132+
|GGGGGGGGGGGGGG
133+
|GGFFFFFFFFFFFFFFFFF
134+
|HHIIIIII
135+
|JJIIIIIII
136+
|JJIIIIII
137+
|
138+
|IIIIIIIIIIIIIIIIIIIIII
139+
|KKKKKKKKKII
140+
|IIII
141+
|
142+
|EEEEEEEEEE
143+
++++++++++++++++++++++++++++++++++++++++++++++++++
144+
|In statement 1
145+
|1 1 + (9 * (7 / 2))
146+
|2 _1 * 2
147+
|3 _1 + _2
148+
|
149+
|About to run: 7 / 2
150+
|1|debug > s
151+
|In statement 1
152+
|1 1 + (9 * (7 / 2))
153+
|2 _1 * 2
154+
|3 _1 + _2
155+
|
156+
|About to run: 9 * 3.5
157+
|1|debug > s
158+
|In statement 1
159+
|1 1 + (9 * (7 / 2))
160+
|2 _1 * 2
161+
|3 _1 + _2
162+
|
163+
|About to run: 1 + 31.5
164+
|1|debug > s
165+
|In statement 2
166+
|1 1 + (9 * (7 / 2))
167+
|2 _1 * 2
168+
|3 _1 + _2
169+
|4 _1 / 3
170+
|
171+
|About to run: 32.5 * 2
172+
|1|calc > _1
173+
|32.5
174+
|
175+
|1|calc > _1
176+
|32.5
177+
|
178+
|1|calc >
179+
--------------------------------------------------
180+
|AAAAAAAAAAAAAA
181+
|BBCCCCCCCCCCCCCCCCC
182+
|DDCCCCCC
183+
|DDCCCCCCC
184+
|
185+
|CCCCCCCCCCCCCCCCCCC
186+
|EEEEEEEEEEF
187+
|GGGGGGGGGGGGGG
188+
|HHIIIIIIIIIIIIIIIII
189+
|JJIIIIII
190+
|JJIIIIIII
191+
|
192+
|IIIIIIIIIIIIIIIIIIIII
193+
|EEEEEEEEEEF
194+
|GGGGGGGGGGGGGG
195+
|HHIIIIIIIIIIIIIIIII
196+
|JJIIIIII
197+
|JJIIIIIII
198+
|
199+
|IIIIIIIIIIIIIIIIIIIIII
200+
|EEEEEEEEEEF
201+
|GGGGGGGGGGGGGG
202+
|GGFFFFFFFFFFFFFFFFF
203+
|HHIIIIII
204+
|JJIIIIIII
205+
|JJIIIIII
206+
|
207+
|IIIIIIIIIIIIIIIIIIIIII
208+
|KKKKKKKKKII
209+
|IIII
210+
|
211+
|KKKKKKKKKII
212+
|IIII
213+
|
214+
|KKKKKKKKK

0 commit comments

Comments
 (0)