Skip to content

Commit 003ef33

Browse files
committed
Fix #iex:break as part of multi-line prompts, closes #14992
1 parent 028cdbb commit 003ef33

File tree

1 file changed

+41
-46
lines changed

1 file changed

+41
-46
lines changed

lib/iex/lib/iex/evaluator.ex

Lines changed: 41 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -71,61 +71,56 @@ defmodule IEx.Evaluator do
7171

7272
def parse(input, opts, []), do: parse(input, opts, {[], :other})
7373

74-
def parse(@break_trigger, opts, _parser_state) do
75-
:elixir_errors.parse_error(
76-
[line: opts[:line]],
77-
opts[:file],
78-
"incomplete expression",
79-
"",
80-
{~c"", Keyword.get(opts, :line, 1), Keyword.get(opts, :column, 1), 0}
81-
)
82-
end
83-
8474
def parse(input, opts, {buffer, last_op}) do
8575
input = buffer ++ input
8676
file = Keyword.get(opts, :file, "nofile")
8777
line = Keyword.get(opts, :line, 1)
8878
column = Keyword.get(opts, :column, 1)
8979

90-
result =
91-
with {:ok, tokens} <- :elixir.string_to_tokens(input, line, column, file, opts),
92-
{:ok, adjusted_tokens, adjusted_op} <-
93-
adjust_operator(tokens, line, column, file, opts, last_op),
94-
{:ok, forms} <- :elixir.tokens_to_quoted(adjusted_tokens, file, opts) do
95-
last_op =
96-
case forms do
97-
{:=, _, [_, _]} -> :match
98-
_ -> :other
99-
end
100-
101-
forms =
102-
if adjusted_op != nil do
103-
quote do
104-
IEx.Evaluator.assert_no_error!()
105-
unquote(forms)
80+
if List.ends_with?(input, @break_trigger) do
81+
triplet = {~c"", line, column, 0}
82+
:elixir_errors.parse_error([line: line], file, "incomplete expression", "", triplet)
83+
else
84+
result =
85+
with {:ok, tokens} <- :elixir.string_to_tokens(input, line, column, file, opts),
86+
{:ok, adjusted_tokens, adjusted_op} <-
87+
adjust_operator(tokens, line, column, file, opts, last_op),
88+
{:ok, forms} <- :elixir.tokens_to_quoted(adjusted_tokens, file, opts) do
89+
last_op =
90+
case forms do
91+
{:=, _, [_, _]} -> :match
92+
_ -> :other
10693
end
107-
else
108-
forms
109-
end
11094

111-
{:ok, forms, last_op}
112-
end
95+
forms =
96+
if adjusted_op != nil do
97+
quote do
98+
IEx.Evaluator.assert_no_error!()
99+
unquote(forms)
100+
end
101+
else
102+
forms
103+
end
104+
105+
{:ok, forms, last_op}
106+
end
113107

114-
case result do
115-
{:ok, forms, last_op} ->
116-
{:ok, forms, {[], last_op}}
117-
118-
{:error, {_, _, ""}} ->
119-
{:incomplete, {input, last_op}}
120-
121-
{:error, {location, error, token}} ->
122-
:elixir_errors.parse_error(
123-
location,
124-
file,
125-
error,
126-
token,
127-
{input, line, column, 0}
128-
)
108+
case result do
109+
{:ok, forms, last_op} ->
110+
{:ok, forms, {[], last_op}}
111+
112+
{:error, {_, _, ""}} ->
113+
{:incomplete, {input, last_op}}
114+
115+
{:error, {location, error, token}} ->
116+
:elixir_errors.parse_error(
117+
location,
118+
file,
119+
error,
120+
token,
121+
{input, line, column, 0}
122+
)
123+
end
129124
end
130125
end
131126

0 commit comments

Comments
 (0)