Skip to content

Commit 9016a18

Browse files
author
Gustavo Dutra
committed
Allow multiple lines 'foo . ()' calls
1 parent bd6f27a commit 9016a18

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ tokenize("..." ++ Rest, Line, Scope, Tokens) ->
211211
tokenize(Rest, Line, Scope, [Token|Tokens]);
212212

213213
% ## Containers
214+
215+
tokenize([$.,T|Tail], Line, Scope, Tokens) when ?is_space(T) ->
216+
case [T|Tail] of
217+
[$\r,$\n|Rest] -> tokenize([$.|Rest], Line + 1, Scope, Tokens);
218+
[$\n|Rest] -> tokenize([$.|Rest], Line + 1, Scope, Tokens);
219+
[_|Rest] -> tokenize([$.|Rest], Line, Scope, Tokens)
220+
end;
221+
214222
tokenize(".<<>>" ++ Rest, Line, Scope, Tokens) ->
215223
handle_call_identifier(Rest, Line, '<<>>', Scope, Tokens);
216224

@@ -232,13 +240,8 @@ tokenize([$.,T|Rest], Line, Scope, Tokens) when ?comp1(T); ?op1(T); T == $& ->
232240
% Dot call
233241

234242
% ## Exception for .( as it needs to be treated specially in the parser
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));
243+
tokenize([$.,$(|Rest], Line, Scope, Tokens) ->
244+
tokenize([$(|Rest], Line, Scope, add_token_with_nl({ dot_call_op, Line, '.' }, Tokens));
242245

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

lib/elixir/test/erlang/function_test.erl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ function_call_without_assigning_with_spaces_test() ->
101101
function_call_with_assignment_and_spaces_test() ->
102102
{3, [{a,_},{c,3}]} = eval("a = fn x -> x + 2 end; c = a . (1)").
103103

104+
function_call_with_multiple_spaces_test() ->
105+
{3, _} = eval("a = fn a, b -> a + b end; a . (1,2)").
106+
107+
function_call_with_multiline_test() ->
108+
{3, _} = eval("a = fn a, b -> a + b end; a . \n (1,2)").
109+
110+
function_call_with_tabs_test() ->
111+
{3, _} = eval("a = fn a, b -> a + b end; a .\n\t(1,2)").
112+
104113
%% Partial application
105114

106115
require_partial_application_test() ->

0 commit comments

Comments
 (0)