Skip to content

Commit d61a825

Browse files
committed
Remove IExTokenMissingError and clean up the code
1 parent a63e4da commit d61a825

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

lib/iex/lib/iex/server.ex

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# IEx needs to treat TokenMissingError error in a special way, so this one is
2-
# used only to distinguish from TokenMissingError in the rescue clause
3-
defexception IExTokenMissingError, [message: nil]
4-
51
defmodule IEx.Server do
62
@moduledoc false
73

@@ -28,29 +24,28 @@ defmodule IEx.Server do
2824
# a special way (to allow for continuation of an expression on the next
2925
# line in IEx). In case of any other error, we let :elixir_translator
3026
# to re-raise it.
31-
{ result, new_binding, scope } =
32-
case :elixir_translator.forms(code, counter, file, []) do
33-
{ :ok, forms } ->
27+
case :elixir_translator.forms(code, counter, "iex", []) do
28+
{ :ok, forms } ->
29+
{ result, new_binding, scope } =
3430
:elixir.eval_forms(forms, config.binding, config.scope)
3531

36-
{ :error, { line, error, token } } ->
37-
if token == [] do
38-
# Let the rescue clause catch this error to wait for more input
39-
raise IExTokenMissingError[]
40-
else
41-
# Encountered malformed expression
42-
:elixir_translator.parse_error(line, file, error, token)
43-
end
44-
end
45-
46-
io_put result
47-
48-
config = config.result(result)
49-
update_history(config.cache(code).scope(nil))
50-
config.update_counter(&1+1).cache('').binding(new_binding).scope(scope)
32+
io_put result
33+
34+
config = config.result(result)
35+
update_history(config.cache(code).scope(nil))
36+
config.update_counter(&1+1).cache('').binding(new_binding).scope(scope)
37+
38+
{ :error, { line, error, token } } ->
39+
if token == [] do
40+
# Update config.cache so that IEx continues to add new input to
41+
# the unfinished expression in `code`
42+
config.cache(code)
43+
else
44+
# Encountered malformed expression
45+
:elixir_translator.parse_error(line, file, error, token)
46+
end
47+
end
5148
rescue
52-
IExTokenMissingError ->
53-
config.cache(code)
5449
exception ->
5550
print_stacktrace System.stacktrace, fn ->
5651
"** (#{inspect exception.__record__(:name)}) #{exception.message}"

0 commit comments

Comments
 (0)