From f672cf1c429c7500fe07b3c0f10971c4b15b17ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Fri, 27 Dec 2024 15:05:47 +0700 Subject: [PATCH 1/3] Remove duplicated metadata in nested call AST --- lib/elixir/src/elixir_parser.yrl | 4 +++- lib/elixir/test/elixir/kernel/parser_test.exs | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/elixir/src/elixir_parser.yrl b/lib/elixir/src/elixir_parser.yrl index c4969f2ba44..f48a6f309a4 100644 --- a/lib/elixir/src/elixir_parser.yrl +++ b/lib/elixir/src/elixir_parser.yrl @@ -905,7 +905,9 @@ extract_identifier({Kind, _, Identifier}) when build_nested_parens(Dot, Args1, {Args2Meta, Args2}, {BlockMeta, Block}) -> Identifier = build_parens(Dot, Args1, {[], []}), - Meta = BlockMeta ++ Args2Meta ++ ?meta(Identifier), + % Take line and column meta from the call target node + LocationMeta = [{Key, Value} || {Key, Value} <- ?meta(Identifier), Key == line orelse Key == column], + Meta = BlockMeta ++ Args2Meta ++ LocationMeta, {Identifier, Meta, append_non_empty(Args2, Block)}. build_parens(Expr, {ArgsMeta, Args}, {BlockMeta, Block}) -> diff --git a/lib/elixir/test/elixir/kernel/parser_test.exs b/lib/elixir/test/elixir/kernel/parser_test.exs index b25fc686e13..8527e6caa1d 100644 --- a/lib/elixir/test/elixir/kernel/parser_test.exs +++ b/lib/elixir/test/elixir/kernel/parser_test.exs @@ -646,6 +646,10 @@ defmodule Kernel.ParserTest do assert string_to_quoted.("foo(\n) do\nend") == {:foo, [do: [line: 2], end: [line: 3], newlines: 1, closing: [line: 2], line: 1], [[do: {:__block__, [], []}]]} + + assert string_to_quoted.("foo(\n)(\n)") == + {{:foo, [newlines: 1, closing: [line: 2], line: 1], []}, + [newlines: 1, closing: [line: 3], line: 1], []} end test "adds opening and closing information for single-expression block" do From a9e92e88d77e8fe4bea6d7811ea24455be187752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Fri, 27 Dec 2024 09:32:00 +0100 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Andrea Leopardi --- lib/elixir/src/elixir_parser.yrl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/elixir/src/elixir_parser.yrl b/lib/elixir/src/elixir_parser.yrl index f48a6f309a4..ec75d6074d7 100644 --- a/lib/elixir/src/elixir_parser.yrl +++ b/lib/elixir/src/elixir_parser.yrl @@ -905,8 +905,8 @@ extract_identifier({Kind, _, Identifier}) when build_nested_parens(Dot, Args1, {Args2Meta, Args2}, {BlockMeta, Block}) -> Identifier = build_parens(Dot, Args1, {[], []}), - % Take line and column meta from the call target node - LocationMeta = [{Key, Value} || {Key, Value} <- ?meta(Identifier), Key == line orelse Key == column], + %% Take line and column meta from the call target node + LocationMeta = lists:filter(fun({Key, _}) -> Key == line orelse Key == column end, ?meta(Identifier)) Meta = BlockMeta ++ Args2Meta ++ LocationMeta, {Identifier, Meta, append_non_empty(Args2, Block)}. From 7e69abe4bf4351d7d948d48ab2e395369a41728b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Fri, 27 Dec 2024 15:34:16 +0700 Subject: [PATCH 3/3] Up --- lib/elixir/src/elixir_parser.yrl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/elixir/src/elixir_parser.yrl b/lib/elixir/src/elixir_parser.yrl index ec75d6074d7..5c0ff0cd8a3 100644 --- a/lib/elixir/src/elixir_parser.yrl +++ b/lib/elixir/src/elixir_parser.yrl @@ -906,7 +906,7 @@ extract_identifier({Kind, _, Identifier}) when build_nested_parens(Dot, Args1, {Args2Meta, Args2}, {BlockMeta, Block}) -> Identifier = build_parens(Dot, Args1, {[], []}), %% Take line and column meta from the call target node - LocationMeta = lists:filter(fun({Key, _}) -> Key == line orelse Key == column end, ?meta(Identifier)) + LocationMeta = lists:filter(fun({Key, _}) -> Key == line orelse Key == column end, ?meta(Identifier)), Meta = BlockMeta ++ Args2Meta ++ LocationMeta, {Identifier, Meta, append_non_empty(Args2, Block)}.