Skip to content

Commit

Permalink
Merge branch 'maint'
Browse files Browse the repository at this point in the history
  • Loading branch information
frazze-jobb committed Nov 26, 2024
2 parents 75fb9ac + 9279c67 commit 7d0ed8d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 18 deletions.
39 changes: 25 additions & 14 deletions lib/stdlib/src/edlin_context.erl
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,24 @@ get_context([$(|Bef], CR) ->
[] -> {term}; % parenthesis
"fun" -> {fun_};
_ ->
{_, Mod} = over_module(Bef1, Fun),
case Mod of
"shell" -> {term};
"shell_default" -> {term};
case erl_scan:string(Fun) of
{ok, [{var, _, _}], _} -> {term};
_ ->
case CR#context.parameter_count+1 == length(CR#context.arguments) of
true ->
%% N arguments N-1 commas, this means that we have an argument
%% still being worked on.
{function, Mod, Fun, lists:droplast(CR#context.arguments),
lists:last(CR#context.arguments),CR#context.nestings};
{_, Mod} = over_module(Bef1, Fun),
case Mod of
"shell" -> {term};
"shell_default" -> {term};
_ ->
{function, Mod, Fun, CR#context.arguments,
[], CR#context.nestings}
case CR#context.parameter_count+1 == length(CR#context.arguments) of
true ->
%% N arguments N-1 commas, this means that we have an argument
%% still being worked on.
{function, Mod, Fun, lists:droplast(CR#context.arguments),
lists:last(CR#context.arguments),CR#context.nestings};
_ ->
{function, Mod, Fun, CR#context.arguments,
[], CR#context.nestings}
end
end
end
end;
Expand Down Expand Up @@ -228,8 +232,15 @@ get_context([$:|Bef2], _) ->
end;
get_context([$/|Bef1], _) ->
{Bef2, Fun} = edlin_expand:over_word(Bef1),
{_, Mod} = over_module(Bef2, Fun),
{fun_, Mod, Fun};
case Fun of
[] -> {term};
_ ->
{_, Mod} = over_module(Bef2, Fun),
case Mod of
[] -> {term};
_ -> {fun_, Mod, Fun}
end
end;
get_context([$>,$-|_Bef2], #context{arguments = Args} = CR) ->
%% Inside a function
case CR#context.parameter_count+1 == length(Args) of
Expand Down
12 changes: 8 additions & 4 deletions lib/stdlib/src/edlin_expand.erl
Original file line number Diff line number Diff line change
Expand Up @@ -738,11 +738,15 @@ shell(Fun) ->

-doc false.
shell_default_or_bif(Fun) ->
{ok, [{atom, _, Fun1}], _} = erl_scan:string(Fun),
case lists:member(Fun1, [E || {E,_}<-get_exports(shell_default)]) of
true -> "shell_default";
_ -> bif(Fun)
case erl_scan:string(Fun) of
{ok, [{var, _, _}], _} -> [];
{ok, [{atom, _, Fun1}], _} ->
case lists:member(Fun1, [E || {E,_}<-get_exports(shell_default)]) of
true -> "shell_default";
_ -> bif(Fun)
end
end.

-doc false.
bif(Fun) ->
{ok, [{atom, _, Fun1}], _} = erl_scan:string(Fun),
Expand Down
4 changes: 4 additions & 0 deletions lib/stdlib/test/edlin_context_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,8 @@ get_context(_Config) ->
{term,[],[]} = edlin_context:get_context(lists:reverse("begin {hej, svej} = {")),
{fun_} = edlin_context:get_context(lists:reverse("fun(")),
{fun_} = edlin_context:get_context(lists:reverse("maps:map(fun(")),
{term} = edlin_context:get_context(lists:reverse("/")),
{term} = edlin_context:get_context(lists:reverse("Foo/")),
{fun_, "user_defined", "a"} = edlin_context:get_context(lists:reverse("a/")),
{term} = edlin_context:get_context(lists:reverse("Foo(")),
ok.

0 comments on commit 7d0ed8d

Please sign in to comment.