@@ -18,11 +18,12 @@ defmodule IEx.Server do
18
18
19
19
defp do_loop ( config ) do
20
20
counter = config . counter
21
- code = config . cache ++ io_get ( config )
21
+ code = config . cache
22
+ line = io_get ( config )
22
23
23
24
new_config =
24
25
try do
25
- eval ( code , counter , config )
26
+ eval ( code , line , counter , config )
26
27
rescue
27
28
exception ->
28
29
print_stacktrace System . stacktrace , fn ->
@@ -49,9 +50,24 @@ defmodule IEx.Server do
49
50
# to re-raise it.
50
51
#
51
52
# Returns updated config.
52
- defp eval ( code , line , config ) do
53
- file = "iex"
54
- case :elixir_translator . forms ( code , line , file , [ ] ) do
53
+ #
54
+ # The first two clauses provide support for the break-trigger allowing to
55
+ # break out from a pending incomplete expression. See
56
+ # https://github.com/elixir-lang/elixir/issues/1089 for discussion.
57
+ #
58
+ @ break_trigger '#iex:break\n '
59
+ defp eval ( _ , @ break_trigger , _ , config = IEx.Config [ cache : '' ] ) do
60
+ # do nothing
61
+ config
62
+ end
63
+
64
+ defp eval ( _ , @ break_trigger , line_no , _ ) do
65
+ :elixir_errors . parse_error ( line_no , "iex" , 'incomplete expression' , [ ] )
66
+ end
67
+
68
+ defp eval ( code_so_far , latest_input , line_no , config ) do
69
+ code = code_so_far ++ latest_input
70
+ case :elixir_translator . forms ( code , line_no , "iex" , [ ] ) do
55
71
{ :ok , forms } ->
56
72
{ result , new_binding , scope } =
57
73
:elixir . eval_forms ( forms , config . binding , config . scope )
@@ -62,14 +78,14 @@ defmodule IEx.Server do
62
78
update_history ( config . cache ( code ) . scope ( nil ) )
63
79
config . update_counter ( & 1 + 1 ) . cache ( '' ) . binding ( new_binding ) . scope ( scope )
64
80
65
- { :error , { line , error , token } } ->
81
+ { :error , { line_no , error , token } } ->
66
82
if token == [ ] do
67
83
# Update config.cache so that IEx continues to add new input to
68
84
# the unfinished expression in `code`
69
85
config . cache ( code )
70
86
else
71
87
# Encountered malformed expression
72
- :elixir_errors . parse_error ( line , file , error , token )
88
+ :elixir_errors . parse_error ( line_no , "iex" , error , token )
73
89
end
74
90
end
75
91
end
0 commit comments