Skip to content

Commit 5d1d3f2

Browse files
author
José Valim
committed
Merge pull request #922 from bellthoven/fix_function_calls
Allow 'foo . (42)' calls
2 parents 01cc9ed + 9016a18 commit 5d1d3f2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 8 additions & 0 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

lib/elixir/test/erlang/function_test.erl

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ 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+
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+
91113
%% Partial application
92114

93115
require_partial_application_test() ->
@@ -96,4 +118,4 @@ require_partial_application_test() ->
96118

97119
import_partial_application_test() ->
98120
{ Fun, _ } = eval("is_atom(&1)"),
99-
Fun = fun erlang:is_atom/1.
121+
Fun = fun erlang:is_atom/1.

0 commit comments

Comments
 (0)