diff options
author | Björn-Egil Dahlberg <[email protected]> | 2013-04-15 18:09:50 +0200 |
---|---|---|
committer | Björn-Egil Dahlberg <[email protected]> | 2014-01-28 15:56:24 +0100 |
commit | 703a9aa47168f7f8c11bf835502281bd59ba77f7 (patch) | |
tree | 549c87e54ba43eb261b460d4000d9f1e05b20e49 /lib | |
parent | 723fa9efadf7f841e7b835393ce801aa0a03e1cc (diff) | |
download | otp-703a9aa47168f7f8c11bf835502281bd59ba77f7.tar.gz otp-703a9aa47168f7f8c11bf835502281bd59ba77f7.tar.bz2 otp-703a9aa47168f7f8c11bf835502281bd59ba77f7.zip |
Extend erl_parse with the new map syntax
Example how to match or construct:
#{ K1 => V1, K2 => V2 }
How to update:
M#{ K => V }
Diffstat (limited to 'lib')
-rw-r--r-- | lib/stdlib/src/erl_parse.yrl | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/stdlib/src/erl_parse.yrl b/lib/stdlib/src/erl_parse.yrl index 59a05a48ee..5a846266c5 100644 --- a/lib/stdlib/src/erl_parse.yrl +++ b/lib/stdlib/src/erl_parse.yrl @@ -34,6 +34,7 @@ binary_comprehension tuple %struct record_expr record_tuple record_field record_fields +map_expr map_tuple map_field map_fields map_key if_expr if_clause if_clauses case_expr cr_clause cr_clauses receive_expr fun_expr fun_clause fun_clauses atom_or_var integer_or_var try_expr try_catch try_clause try_clauses @@ -59,7 +60,7 @@ char integer float atom string var '*' '/' 'div' 'rem' 'band' 'and' '+' '-' 'bor' 'bxor' 'bsl' 'bsr' 'or' 'xor' '++' '--' -'==' '/=' '=<' '<' '>=' '>' '=:=' '=/=' '<=' +'==' '/=' '=<' '<' '>=' '>' '=:=' '=/=' '<=' '=>' '<<' '>>' '!' '=' '::' '..' '...' 'spec' 'callback' % helper @@ -247,6 +248,7 @@ expr_500 -> expr_600 : '$1'. expr_600 -> prefix_op expr_700 : ?mkop1('$1', '$2'). +expr_600 -> map_expr : '$1'. expr_600 -> expr_700 : '$1'. expr_700 -> function_call : '$1'. @@ -327,6 +329,26 @@ tuple -> '{' exprs '}' : {tuple,?line('$1'),'$2'}. %%struct -> atom tuple : %% {struct,?line('$1'),element(3, '$1'),element(3, '$2')}. +map_expr -> '#' map_tuple : + {map, ?line('$1'),'$2'}. +map_expr -> expr_max '#' map_tuple : + {map, ?line('$2'),'$1','$3'}. +map_expr -> map_expr '#' map_tuple : + {map, ?line('$2'),'$1','$3'}. +map_expr -> map_expr '.' atom : + {map_field, ?line('$2'),'$1','$3'}. + +map_tuple -> '{' '}' : []. +map_tuple -> '{' map_fields '}' : '$2'. + +map_fields -> map_field : ['$1']. +map_fields -> map_field ',' map_fields : ['$1' | '$3']. + +map_field -> map_key '=>' expr : + {map_field,?line('$1'),'$1','$3'}. + +map_key -> expr : '$1'. + %% N.B. This is called from expr_700. %% N.B. Field names are returned as the complete object, even if they are @@ -1060,3 +1082,5 @@ get_attribute(L, Name) -> get_attributes(L) -> erl_scan:attributes_info(L). + +%% vim: ft=erlang |