Skip to content

Commit ccbc8ce

Browse files
committed
Up
1 parent 8d25c68 commit ccbc8ce

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

lib/elixir/lib/macro.ex

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,18 +2386,13 @@ defmodule Macro do
23862386
"""
23872387
@doc since: "1.14.0"
23882388
@spec inspect_atom(:literal | :key | :remote_call, atom, keyword) :: binary
2389-
def inspect_atom(source_format, atom, opts \\ []) do
2390-
opts = Keyword.validate!(opts, [:escape])
2389+
def inspect_atom(source_format, atom, opts \\ [])
23912390

2392-
escape = Keyword.get(opts, :escape, &inspect_atom_escape/2)
2393-
do_inspect_atom(source_format, atom, escape)
2394-
end
2395-
2396-
def do_inspect_atom(:literal, atom, _escape) when is_nil(atom) or is_boolean(atom) do
2391+
def inspect_atom(:literal, atom, _opts) when is_nil(atom) or is_boolean(atom) do
23972392
Atom.to_string(atom)
23982393
end
23992394

2400-
def do_inspect_atom(:literal, atom, escape) when is_atom(atom) do
2395+
def inspect_atom(:literal, atom, opts) when is_atom(atom) do
24012396
binary = Atom.to_string(atom)
24022397

24032398
case classify_atom(atom) do
@@ -2409,31 +2404,31 @@ defmodule Macro do
24092404
end
24102405

24112406
:quoted ->
2412-
escaped = escape.(binary, ?")
2407+
escaped = inspect_atom_escape(opts, binary, ?")
24132408
IO.iodata_to_binary([?:, ?", escaped, ?"])
24142409

24152410
_ ->
24162411
":" <> binary
24172412
end
24182413
end
24192414

2420-
def do_inspect_atom(:key, atom, escape) when is_atom(atom) do
2415+
def inspect_atom(:key, atom, opts) when is_atom(atom) do
24212416
binary = Atom.to_string(atom)
24222417

24232418
case classify_atom(atom) do
24242419
:alias ->
24252420
IO.iodata_to_binary([?", binary, ?", ?:])
24262421

24272422
:quoted ->
2428-
escaped = escape.(binary, ?")
2423+
escaped = inspect_atom_escape(opts, binary, ?")
24292424
IO.iodata_to_binary([?", escaped, ?", ?:])
24302425

24312426
_ ->
24322427
IO.iodata_to_binary([binary, ?:])
24332428
end
24342429
end
24352430

2436-
def do_inspect_atom(:remote_call, atom, escape) when is_atom(atom) do
2431+
def inspect_atom(:remote_call, atom, opts) when is_atom(atom) do
24372432
binary = Atom.to_string(atom)
24382433

24392434
case inner_classify(atom) do
@@ -2445,16 +2440,20 @@ defmodule Macro do
24452440
if type in [:not_callable, :alias] do
24462441
binary
24472442
else
2448-
escape.(binary, ?")
2443+
inspect_atom_escape(opts, binary, ?")
24492444
end
24502445

24512446
IO.iodata_to_binary([?", escaped, ?"])
24522447
end
24532448
end
24542449

2455-
defp inspect_atom_escape(string, char) do
2456-
{escaped, _} = Code.Identifier.escape(string, char)
2457-
escaped
2450+
defp inspect_atom_escape(opts, string, char) do
2451+
if escape = opts[:escape] do
2452+
escape.(string, char)
2453+
else
2454+
{escaped, _} = Code.Identifier.escape(string, char)
2455+
escaped
2456+
end
24582457
end
24592458

24602459
# Classifies the given atom into one of the following categories:

0 commit comments

Comments
 (0)