Skip to content

Commit c30b6d6

Browse files
author
José Valim
committed
Rename :end metadata to less ambiguous :closing
Signed-off-by: José Valim <[email protected]>
1 parent b59937b commit c30b6d6

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

lib/elixir/lib/code/formatter.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,7 +1156,7 @@ defmodule Code.Formatter do
11561156
{left_doc, _join, state} =
11571157
args_to_algebra_with_comments(
11581158
left,
1159-
Keyword.delete(meta, :end),
1159+
Keyword.delete(meta, :closing),
11601160
skip_parens?,
11611161
:force_comma,
11621162
join,
@@ -1847,7 +1847,7 @@ defmodule Code.Formatter do
18471847
end
18481848

18491849
defp add_max_line_to_last_clause([{op, meta, args}], max_line) do
1850-
[{op, [end: [line: max_line]] ++ meta, args}]
1850+
[{op, [closing: [line: max_line]] ++ meta, args}]
18511851
end
18521852

18531853
defp add_max_line_to_last_clause([clause | clauses], max_line) do
@@ -2239,7 +2239,7 @@ defmodule Code.Formatter do
22392239
end
22402240

22412241
defp end_line(meta) do
2242-
meta[:end][:line] || @min_line
2242+
meta[:closing][:line] || @min_line
22432243
end
22442244

22452245
## Algebra helpers

lib/elixir/src/elixir_parser.yrl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -653,12 +653,12 @@ line_from_location({Line, _Column, _}) -> Line.
653653
is_eol({_, _, Eol}) -> is_integer(Eol) and (Eol > 0).
654654

655655
end_meta(Token) ->
656-
[{format, block}, {'end', meta_from_location(?location(Token))}].
656+
[{format, block}, {closing, meta_from_location(?location(Token))}].
657657

658-
meta_from_token_with_end(Begin, End) ->
658+
meta_from_token_with_closing(Begin, End) ->
659659
case ?formatter_metadata() of
660660
true ->
661-
[{'end', meta_from_location(?location(End))} | meta_from_token(Begin)];
661+
[{closing, meta_from_location(?location(End))} | meta_from_token(Begin)];
662662
false ->
663663
meta_from_token(Begin)
664664
end.
@@ -740,7 +740,7 @@ eol_pair(Left, Right) ->
740740
true ->
741741
[
742742
{eol, is_eol(?location(Left)) and is_eol(?location(Right))},
743-
{'end', meta_from_location(?location(Right))}
743+
{closing, meta_from_location(?location(Right))}
744744
];
745745
false ->
746746
[]
@@ -828,7 +828,7 @@ build_identifier({_, Location, Identifier}, Args) ->
828828
build_fn(Fn, Stab, End) ->
829829
case check_stab(Stab, none) of
830830
stab ->
831-
Meta = eol_op(?location(Fn)) ++ meta_from_token_with_end(Fn, End),
831+
Meta = eol_op(?location(Fn)) ++ meta_from_token_with_closing(Fn, End),
832832
{fn, Meta, collect_stab(Stab, [], [])};
833833
block ->
834834
return_error(meta_from_token(Fn), "expected anonymous functions to be defined with -> inside: ", "'fn'")
@@ -902,7 +902,7 @@ charlist_part({Begin, End, Tokens}) ->
902902
Form = string_tokens_parse(Tokens),
903903
Meta =
904904
case ?formatter_metadata() of
905-
true -> [{'end', meta_from_location(End)} | meta_from_location(Begin)];
905+
true -> [{closing, meta_from_location(End)} | meta_from_location(Begin)];
906906
false -> meta_from_location(Begin)
907907
end,
908908
{{'.', Meta, ['Elixir.Kernel', to_string]}, Meta, [Form]}.
@@ -915,7 +915,7 @@ string_part({Begin, End, Tokens}) ->
915915
Form = string_tokens_parse(Tokens),
916916
Meta =
917917
case ?formatter_metadata() of
918-
true -> [{'end', meta_from_location(End)} | meta_from_location(Begin)];
918+
true -> [{closing, meta_from_location(End)} | meta_from_location(Begin)];
919919
false -> meta_from_location(Begin)
920920
end,
921921
{'::', Meta, [{{'.', Meta, ['Elixir.Kernel', to_string]}, Meta, [Form]}, {binary, Meta, nil}]}.
@@ -943,7 +943,7 @@ build_stab(Stab) ->
943943
build_stab(Before, Stab, After) ->
944944
case build_stab(Stab) of
945945
{'__block__', Meta, Block} ->
946-
{'__block__', Meta ++ meta_from_token_with_end(Before, After), Block};
946+
{'__block__', Meta ++ meta_from_token_with_closing(Before, After), Block};
947947
Other ->
948948
Other
949949
end.

lib/elixir/test/elixir/code_test.exs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -252,25 +252,27 @@ defmodule CodeTest do
252252
assert string_to_quoted.(":one") == {:__block__, [line: 1], [:one]}
253253

254254
args = [[{:__block__, [original: '1', line: 1], [1]}]]
255-
assert string_to_quoted.("[1]") == {:__block__, [eol: false, end: [line: 1], line: 1], args}
255+
256+
assert string_to_quoted.("[1]") ==
257+
{:__block__, [eol: false, closing: [line: 1], line: 1], args}
256258

257259
args = [{{:__block__, [line: 1], [:ok]}, {:__block__, [line: 1], [:test]}}]
258260

259261
assert string_to_quoted.("{:ok, :test}") ==
260-
{:__block__, [eol: false, end: [line: 1], line: 1], args}
262+
{:__block__, [eol: false, closing: [line: 1], line: 1], args}
261263

262264
assert string_to_quoted.(~s("""\nhello\n""")) ==
263265
{:__block__, [format: :bin_heredoc, line: 1], ["hello\n"]}
264266

265267
assert string_to_quoted.("'''\nhello\n'''") ==
266268
{:__block__, [format: :list_heredoc, line: 1], ['hello\n']}
267269

268-
left = {:__block__, [original: '1', line: 1, end: [line: 1], line: 1], [1]}
270+
left = {:__block__, [original: '1', line: 1, closing: [line: 1], line: 1], [1]}
269271
right = {:__block__, [format: :string, line: 1], ["hello"]}
270272
args = [{:->, [line: 1], [[left], right]}]
271273

272274
assert string_to_quoted.(~s[fn (1) -> "hello" end]) ==
273-
{:fn, [end: [line: 1], line: 1], args}
275+
{:fn, [closing: [line: 1], line: 1], args}
274276
end
275277

276278
test "adds newlines information to blocks when :formatter_metadata (private) is given" do
@@ -285,11 +287,11 @@ defmodule CodeTest do
285287
"""
286288

287289
args = [
288-
{:one, [eol: false, end: [line: 1], line: 1], []},
289-
{:two, [newlines: 0, eol: false, end: [line: 1], line: 1], []},
290-
{:three, [newlines: 1, eol: false, end: [line: 2], line: 2], []},
291-
{:four, [newlines: 2, eol: false, end: [line: 4], line: 4], []},
292-
{:five, [newlines: 3, eol: false, end: [line: 7], line: 7], []}
290+
{:one, [eol: false, closing: [line: 1], line: 1], []},
291+
{:two, [newlines: 0, eol: false, closing: [line: 1], line: 1], []},
292+
{:three, [newlines: 1, eol: false, closing: [line: 2], line: 2], []},
293+
{:four, [newlines: 2, eol: false, closing: [line: 4], line: 4], []},
294+
{:five, [newlines: 3, eol: false, closing: [line: 7], line: 7], []}
293295
]
294296

295297
assert Code.string_to_quoted!(file, formatter_metadata: true) == {:__block__, [], args}

0 commit comments

Comments
 (0)