From 4703b64dc87465e0d505b9997ca5e91f5cb12002 Mon Sep 17 00:00:00 2001 From: Andrey Tsirulev Date: Sun, 3 Aug 2014 01:58:09 +0400 Subject: Allow Name/Arity syntax in maps inside attributes Currently Name/Arity syntax is supported in list and tuple terms. This change makes it possible to use this syntax in map terms for consistency and convenience. Example: -custom(#{test1 => init/2, test2 => [val/1, val/2]}). --- lib/stdlib/src/erl_parse.yrl | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'lib/stdlib/src') diff --git a/lib/stdlib/src/erl_parse.yrl b/lib/stdlib/src/erl_parse.yrl index e1ae3b7aea..039cc88b9c 100644 --- a/lib/stdlib/src/erl_parse.yrl +++ b/lib/stdlib/src/erl_parse.yrl @@ -753,6 +753,9 @@ attribute_farity({cons,L,H,T}) -> attribute_farity({tuple,L,Args0}) -> Args = attribute_farity_list(Args0), {tuple,L,Args}; +attribute_farity({map,L,Args0}) -> + Args = attribute_farity_map(Args0), + {map,L,Args}; attribute_farity({op,L,'/',{atom,_,_}=Name,{integer,_,_}=Arity}) -> {tuple,L,[Name,Arity]}; attribute_farity(Other) -> Other. @@ -760,6 +763,14 @@ attribute_farity(Other) -> Other. attribute_farity_list(Args) -> [attribute_farity(A) || A <- Args]. +attribute_farity_map(Args) -> + [attribute_farity_map_field(A) || A <- Args]. + +attribute_farity_map_field({map_field_assoc,L,K,V}) -> + {map_field_assoc,L,attribute_farity(K),attribute_farity(V)}; +attribute_farity_map_field({map_field_exact,L,K,V}) -> + {map_field_exact,L,attribute_farity(K),attribute_farity(V)}. + -spec error_bad_decl(integer(), attributes()) -> no_return(). error_bad_decl(L, S) -> -- cgit v1.2.3 From 588df549e708b68ffb2b1becb5efecd20a7e6224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Tue, 30 Sep 2014 14:42:37 +0200 Subject: stdlib: Refactor Maps farity attributes --- lib/stdlib/src/erl_parse.yrl | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'lib/stdlib/src') diff --git a/lib/stdlib/src/erl_parse.yrl b/lib/stdlib/src/erl_parse.yrl index 039cc88b9c..1d70b1286f 100644 --- a/lib/stdlib/src/erl_parse.yrl +++ b/lib/stdlib/src/erl_parse.yrl @@ -763,13 +763,9 @@ attribute_farity(Other) -> Other. attribute_farity_list(Args) -> [attribute_farity(A) || A <- Args]. +%% It is not meaningful to have farity keys. attribute_farity_map(Args) -> - [attribute_farity_map_field(A) || A <- Args]. - -attribute_farity_map_field({map_field_assoc,L,K,V}) -> - {map_field_assoc,L,attribute_farity(K),attribute_farity(V)}; -attribute_farity_map_field({map_field_exact,L,K,V}) -> - {map_field_exact,L,attribute_farity(K),attribute_farity(V)}. + [{Op,L,K,attribute_farity(V)} || {Op,L,K,V} <- Args]. -spec error_bad_decl(integer(), attributes()) -> no_return(). -- cgit v1.2.3 From 4196af1031b1cb9e410de77118a52bfbc3363b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn-Egil=20Dahlberg?= Date: Tue, 30 Sep 2014 15:26:09 +0200 Subject: stdlib: erl_parse abstract Maps --- lib/stdlib/src/erl_parse.yrl | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib/stdlib/src') diff --git a/lib/stdlib/src/erl_parse.yrl b/lib/stdlib/src/erl_parse.yrl index 1d70b1286f..1d4a2a1fef 100644 --- a/lib/stdlib/src/erl_parse.yrl +++ b/lib/stdlib/src/erl_parse.yrl @@ -961,7 +961,9 @@ abstract([H|T], L, none=E) -> abstract(List, L, E) when is_list(List) -> abstract_list(List, [], L, E); abstract(Tuple, L, E) when is_tuple(Tuple) -> - {tuple,L,abstract_tuple_list(tuple_to_list(Tuple), L, E)}. + {tuple,L,abstract_tuple_list(tuple_to_list(Tuple), L, E)}; +abstract(Map, L, E) when is_map(Map) -> + {map,L,abstract_map_fields(maps:to_list(Map),L,E)}. abstract_list([H|T], String, L, E) -> case is_integer(H) andalso H >= 0 andalso E(H) of @@ -986,6 +988,9 @@ abstract_tuple_list([H|T], L, E) -> abstract_tuple_list([], _L, _E) -> []. +abstract_map_fields(Fs,L,E) -> + [{map_field_assoc,L,abstract(K,L,E),abstract(V,L,E)}||{K,V}<-Fs]. + abstract_byte(Byte, L) when is_integer(Byte) -> {bin_element, L, {integer, L, Byte}, default, default}; abstract_byte(Bits, L) -> -- cgit v1.2.3