aboutsummaryrefslogtreecommitdiffstats
path: root/lib/compiler/src
diff options
context:
space:
mode:
authorBjörn-Egil Dahlberg <[email protected]>2013-10-01 23:15:50 +0200
committerBjörn-Egil Dahlberg <[email protected]>2014-01-28 15:56:27 +0100
commit652ddd4c360cd2cc381ed033915d87d967310a49 (patch)
treeb750543ba423f391628de4e2c93c4f4eee88a892 /lib/compiler/src
parent758702e24f0780130c6b3058426062a3761b7a6e (diff)
downloadotp-652ddd4c360cd2cc381ed033915d87d967310a49.tar.gz
otp-652ddd4c360cd2cc381ed033915d87d967310a49.tar.bz2
otp-652ddd4c360cd2cc381ed033915d87d967310a49.zip
Extend representation for maps in Core Erlang
Diffstat (limited to 'lib/compiler/src')
-rw-r--r--lib/compiler/src/core_parse.hrl6
-rw-r--r--lib/compiler/src/core_parse.yrl19
-rw-r--r--lib/compiler/src/core_pp.erl7
3 files changed, 23 insertions, 9 deletions
diff --git a/lib/compiler/src/core_parse.hrl b/lib/compiler/src/core_parse.hrl
index c134747991..40c3ae4582 100644
--- a/lib/compiler/src/core_parse.hrl
+++ b/lib/compiler/src/core_parse.hrl
@@ -97,8 +97,10 @@
-record(c_var, {anno=[], name :: cerl:var_name()}).
--record(c_map_pair, {anno=[], key, val}).
+-record(c_map_pair_assoc, {anno=[], key, val}).
+
+-record(c_map_pair_exact, {anno=[], key, val}).
-record(c_map, {anno=[],
var=#c_literal{val=[]} :: #c_var{} | #c_literal{},
- es :: [#c_map_pair{}]}).
+ es :: [#c_map_pair_assoc{}|#c_map_pair_exact{}]}).
diff --git a/lib/compiler/src/core_parse.yrl b/lib/compiler/src/core_parse.yrl
index b072950eeb..82ba11b0fc 100644
--- a/lib/compiler/src/core_parse.yrl
+++ b/lib/compiler/src/core_parse.yrl
@@ -46,7 +46,7 @@ receive_expr timeout try_expr
sequence catch_expr
variable clause clause_pattern
-map_expr map_pairs map_pair
+map_expr map_pairs map_pair map_pair_assoc map_pair_exact
map_pattern map_pair_patterns map_pair_pattern
annotation anno_fun anno_expression anno_expressions
@@ -58,7 +58,7 @@ Terminals
%% Separators
-'(' ')' '{' '}' '[' ']' '|' ',' '->' '=' '/' '<' '>' ':' '-|' '#' '~'
+'(' ')' '{' '}' '[' ']' '|' ',' '->' '=' '/' '<' '>' ':' '-|' '#' '~' '::'
%% Keywords (atoms are assumed to always be single-quoted).
@@ -190,7 +190,7 @@ map_pair_patterns -> map_pair_pattern : ['$1'].
map_pair_patterns -> map_pair_pattern ',' map_pair_patterns : ['$1' | '$3'].
map_pair_pattern -> '~' '<' anno_pattern ',' anno_pattern '>' :
- #c_map_pair{key='$3',val='$5'}.
+ #c_map_pair_exact{key='$3',val='$5'}.
cons_pattern -> '[' anno_pattern tail_pattern :
#c_cons{hd='$2',tl='$3'}.
@@ -286,14 +286,19 @@ tuple -> '{' anno_expressions '}' : c_tuple('$2').
map_expr -> '~' '{' '}' '~' : #c_map{es=[]}.
map_expr -> '~' '{' map_pairs '}' '~' : #c_map{es='$3'}.
-map_expr -> variable '~' '{' '}' '~' : #c_map{var='$',es=[]}.
+map_expr -> variable '~' '{' '}' '~' : #c_map{var='$1',es=[]}.
map_expr -> variable '~' '{' map_pairs '}' '~' : #c_map{var='$1',es='$4'}.
map_pairs -> map_pair : ['$1'].
map_pairs -> map_pair ',' map_pairs : ['$1' | '$3'].
-map_pair -> '~' '<' anno_expression ',' anno_expression'>' :
- #c_map_pair{key='$3',val='$5'}.
+map_pair -> map_pair_assoc : '$1'.
+map_pair -> map_pair_exact : '$1'.
+
+map_pair_assoc -> '::' '<' anno_expression ',' anno_expression'>' :
+ #c_map_pair_assoc{key='$3',val='$5'}.
+map_pair_exact -> '~' '<' anno_expression ',' anno_expression'>' :
+ #c_map_pair_exact{key='$3',val='$5'}.
cons -> '[' anno_expression tail : c_cons('$2', '$3').
@@ -409,3 +414,5 @@ Erlang code.
tok_val(T) -> element(3, T).
tok_line(T) -> element(2, T).
+
+%% vim: syntax=erlang
diff --git a/lib/compiler/src/core_pp.erl b/lib/compiler/src/core_pp.erl
index c8c59b9246..f775d87507 100644
--- a/lib/compiler/src/core_pp.erl
+++ b/lib/compiler/src/core_pp.erl
@@ -172,7 +172,12 @@ format_1(#c_map{es=Es}, Ctxt) ->
format_hseq(Es, ",", add_indent(Ctxt, 1), fun format/2),
"}~"
];
-format_1(#c_map_pair{key=K,val=V}, Ctxt) ->
+format_1(#c_map_pair_assoc{key=K,val=V}, Ctxt) ->
+ ["::<",
+ format_hseq([K,V], ",", add_indent(Ctxt, 1), fun format/2),
+ ">"
+ ];
+format_1(#c_map_pair_exact{key=K,val=V}, Ctxt) ->
["~<",
format_hseq([K,V], ",", add_indent(Ctxt, 1), fun format/2),
">"