diff options
author | Hans Bolinder <[email protected]> | 2016-06-09 10:10:04 +0200 |
---|---|---|
committer | Hans Bolinder <[email protected]> | 2016-06-09 10:10:04 +0200 |
commit | 6c6cdb99b2f80630816089ad5f75d8a81266b5cc (patch) | |
tree | 3676db6a83474555078212cb3d70f11497734e7e /lib/edoc/src | |
parent | 6fe86a5858d2894887ea4c0f343c2c38283cf556 (diff) | |
parent | 5e7542d6f7cd1964839f6214915c7f9b7d7f8866 (diff) | |
download | otp-6c6cdb99b2f80630816089ad5f75d8a81266b5cc.tar.gz otp-6c6cdb99b2f80630816089ad5f75d8a81266b5cc.tar.bz2 otp-6c6cdb99b2f80630816089ad5f75d8a81266b5cc.zip |
Merge branch 'hasse/edoc/fix_maps_type/PR-1014'
* hasse/edoc/fix_maps_type/PR-1014:
edoc: Fix new Maps syntax
Diffstat (limited to 'lib/edoc/src')
-rw-r--r-- | lib/edoc/src/edoc_layout.erl | 24 | ||||
-rw-r--r-- | lib/edoc/src/edoc_parser.yrl | 17 | ||||
-rw-r--r-- | lib/edoc/src/edoc_scanner.erl | 2 | ||||
-rw-r--r-- | lib/edoc/src/edoc_specs.erl | 6 | ||||
-rw-r--r-- | lib/edoc/src/edoc_types.erl | 4 | ||||
-rw-r--r-- | lib/edoc/src/edoc_types.hrl | 2 |
6 files changed, 42 insertions, 13 deletions
diff --git a/lib/edoc/src/edoc_layout.erl b/lib/edoc/src/edoc_layout.erl index f723cd8373..e86d090b13 100644 --- a/lib/edoc/src/edoc_layout.erl +++ b/lib/edoc/src/edoc_layout.erl @@ -898,8 +898,20 @@ t_map(Es) -> Fs = get_elem(map_field, Es), ["#{"] ++ seq(fun t_map_field/1, Fs, ["}"]). -t_map_field(#xmlElement{content = [K,V]}) -> - t_utype_elem(K) ++ [" => "] ++ t_utype_elem(V). +t_map_field(#xmlElement{content = [K,V]}=E) -> + KElem = t_utype_elem(K), + VElem = t_utype_elem(V), + AT = get_attrval(assoc_type, E), + IsAny = fun(["any","()"]) -> true; (_) -> false end, + case AT =:= "assoc" andalso IsAny(KElem) andalso IsAny(VElem) of + true -> "..."; + false -> + AS = case AT of + "assoc" -> " => "; + "exact" -> " := " + end, + KElem ++ [AS] ++ VElem + end. t_record(E, Es) -> Name = ["#"] ++ t_type(get_elem(atom, Es)), @@ -1133,8 +1145,12 @@ ot_tuple(Es) -> ot_map(Es) -> {type,0,map,[ot_map_field(E) || E <- get_elem(map_field,Es)]}. -ot_map_field(#xmlElement{content=[K,V]}) -> - {type,0,map_field_assoc,ot_utype_elem(K), ot_utype_elem(V)}. +ot_map_field(#xmlElement{content=[K,V]}=E) -> + A = case get_attrval(assoc_type, E) of + "assoc" -> map_field_assoc; + "exact" -> map_field_exact + end, + {type,0,A,[ot_utype_elem(K), ot_utype_elem(V)]}. ot_fun(Es) -> Range = ot_utype(get_elem(type, Es)), diff --git a/lib/edoc/src/edoc_parser.yrl b/lib/edoc/src/edoc_parser.yrl index 835e7ccaa6..983e2f8496 100644 --- a/lib/edoc/src/edoc_parser.yrl +++ b/lib/edoc/src/edoc_parser.yrl @@ -36,8 +36,8 @@ Terminals atom float integer var an_var string start_spec start_typedef start_throws start_ref -'(' ')' ',' '.' '=>' '->' '{' '}' '[' ']' '|' '+' ':' '::' '=' '/' '//' '*' -'#' 'where' '<<' '>>' '..' '...'. +'(' ')' ',' '.' '=>' ':=' '->' '{' '}' '[' ']' '|' '+' ':' '::' '=' '/' '//' +'*' '#' 'where' '<<' '>>' '..' '...'. Rootsymbol start. @@ -76,7 +76,15 @@ utype_map_fields -> '$empty' : []. utype_map_fields -> utype_map_field : ['$1']. utype_map_fields -> utype_map_fields ',' utype_map_field : ['$3' | '$1']. -utype_map_field -> utype '=>' utype : #t_map_field{ k_type = '$1', v_type = '$3'}. +utype_map_field -> utype '=>' utype : #t_map_field{assoc_type = assoc, + k_type = '$1', + v_type = '$3'}. +utype_map_field -> utype ':=' utype : #t_map_field{assoc_type = exact, + k_type = '$1', + v_type = '$3'}. +utype_map_field -> '...' : #t_map_field{assoc_type = assoc, + k_type = any(), + v_type = any()}. utype_tuple -> '{' utypes '}' : lists:reverse('$2'). @@ -346,6 +354,9 @@ all_vars([#t_var{} | As]) -> all_vars(As) -> As =:= []. +any() -> + #t_type{name = #t_name{name = any}, args = []}. + %% --------------------------------------------------------------------- %% @doc EDoc type specification parsing. Parses the content of diff --git a/lib/edoc/src/edoc_scanner.erl b/lib/edoc/src/edoc_scanner.erl index 36423d63f8..f1d5e1d4b9 100644 --- a/lib/edoc/src/edoc_scanner.erl +++ b/lib/edoc/src/edoc_scanner.erl @@ -146,6 +146,8 @@ scan1([$>,$>|Cs], Toks, Pos) -> scan1(Cs, [{'>>',Pos}|Toks], Pos); scan1([$-,$>|Cs], Toks, Pos) -> scan1(Cs, [{'->',Pos}|Toks], Pos); +scan1([$:,$=|Cs], Toks, Pos) -> + scan1(Cs, [{':=',Pos}|Toks], Pos); scan1([$:,$:|Cs], Toks, Pos) -> scan1(Cs, [{'::',Pos}|Toks], Pos); scan1([$/,$/|Cs], Toks, Pos) -> diff --git a/lib/edoc/src/edoc_specs.erl b/lib/edoc/src/edoc_specs.erl index faee8adf7b..c15dfd328f 100644 --- a/lib/edoc/src/edoc_specs.erl +++ b/lib/edoc/src/edoc_specs.erl @@ -369,11 +369,11 @@ d2e({type,_,map,any}, _Prec) -> d2e({type,_,map,Es}, _Prec) -> #t_map{types = d2e(Es) }; d2e({type,_,map_field_assoc,[K,V]}, Prec) -> - T = #t_map_field{k_type = d2e(K), v_type=d2e(V) }, + T = #t_map_field{assoc_type = assoc, k_type = d2e(K), v_type=d2e(V) }, {P,_R} = erl_parse:type_preop_prec('#'), maybe_paren(P, Prec, T); -d2e({type,_,map_field_exact,K,V}, Prec) -> - T = #t_map_field{k_type = d2e(K), v_type=d2e(V) }, +d2e({type,_,map_field_exact,[K,V]}, Prec) -> + T = #t_map_field{assoc_type = exact, k_type = d2e(K), v_type=d2e(V) }, {P,_R} = erl_parse:type_preop_prec('#'), maybe_paren(P, Prec, T); d2e({type,_,tuple,Ts0}, _Prec) -> diff --git a/lib/edoc/src/edoc_types.erl b/lib/edoc/src/edoc_types.erl index 65fba61a72..5bb68e79fb 100644 --- a/lib/edoc/src/edoc_types.erl +++ b/lib/edoc/src/edoc_types.erl @@ -89,8 +89,8 @@ to_xml(#t_fun{args = As, range = T}, Env) -> wrap_utype(T, Env)]}; to_xml(#t_map{ types = Ts}, Env) -> {map, map(fun to_xml/2, Ts, Env)}; -to_xml(#t_map_field{ k_type=K, v_type=V}, Env) -> - {map_field, [wrap_utype(K,Env), wrap_utype(V, Env)]}; +to_xml(#t_map_field{assoc_type = AT, k_type=K, v_type=V}, Env) -> + {map_field, [{assoc_type, AT}], [wrap_utype(K,Env), wrap_utype(V, Env)]}; to_xml(#t_tuple{types = Ts}, Env) -> {tuple, map(fun wrap_utype/2, Ts, Env)}; to_xml(#t_list{type = T}, Env) -> diff --git a/lib/edoc/src/edoc_types.hrl b/lib/edoc/src/edoc_types.hrl index 7fec10d936..3e5e91484f 100644 --- a/lib/edoc/src/edoc_types.hrl +++ b/lib/edoc/src/edoc_types.hrl @@ -157,5 +157,5 @@ -record(t_paren, {a=[], type}). % parentheses -record(t_map, {a=[], types=[]}). --record(t_map_field, {a=[], k_type, v_type}). +-record(t_map_field, {a=[], assoc_type, k_type, v_type}). |