Skip to content

Commit bd6f27a

Browse files
author
Gustavo Dutra
committed
Allow 'foo . (42)' calls
1 parent f9e74f9 commit bd6f27a

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,13 @@ tokenize([$.,T|Rest], Line, Scope, Tokens) when ?comp1(T); ?op1(T); T == $& ->
232232
% Dot call
233233

234234
% ## Exception for .( as it needs to be treated specially in the parser
235-
tokenize([$.,$(|Rest], Line, Scope, Tokens) ->
236-
tokenize([$(|Rest], Line, Scope, add_token_with_nl({ dot_call_op, Line, '.' }, Tokens));
235+
tokenize([$.,T1,T2|T], Line, Scope, Tokens) when T1 == $( ; (T1 == $\s andalso T2 == $() ->
236+
Rest = case T1 of
237+
$( -> [T1,T2|T];
238+
% Ignores the space
239+
$\s -> [T2|T]
240+
end,
241+
tokenize(Rest, Line, Scope, add_token_with_nl({ dot_call_op, Line, '.' }, Tokens));
237242

238243
tokenize([$.,H|T], Line, #scope{file=File} = Scope, Tokens) when ?is_quote(H) ->
239244
case elixir_interpolation:extract(Line, File, true, T, H) of

lib/elixir/test/erlang/function_test.erl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,19 @@ function_calls_with_multiple_args_with_line_breaks_test() ->
8888
function_calls_with_parenthesis_test() ->
8989
{3, [{a,_},{b,1}]} = eval("a = (fn x -> x + 2 end).(b = 1)").
9090

91+
function_call_with_a_single_space_test() ->
92+
{3, _} = eval("a = fn a, b -> a + b end; a. (1,2)"),
93+
{3, _} = eval("a = fn a, b -> a + b end; a .(1,2)").
94+
95+
function_call_with_spaces_test() ->
96+
{3, _} = eval("a = fn a, b -> a + b end; a . (1,2)").
97+
98+
function_call_without_assigning_with_spaces_test() ->
99+
{3, _} = eval("(fn a, b -> a + b end) . (1,2)").
100+
101+
function_call_with_assignment_and_spaces_test() ->
102+
{3, [{a,_},{c,3}]} = eval("a = fn x -> x + 2 end; c = a . (1)").
103+
91104
%% Partial application
92105

93106
require_partial_application_test() ->
@@ -96,4 +109,4 @@ require_partial_application_test() ->
96109

97110
import_partial_application_test() ->
98111
{ Fun, _ } = eval("is_atom(&1)"),
99-
Fun = fun erlang:is_atom/1.
112+
Fun = fun erlang:is_atom/1.

0 commit comments

Comments
 (0)