From 3829e5facc98f1c1d3113b648c0b9fa7362cad32 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Tue, 20 Apr 2010 20:43:10 +0200 Subject: Support nested record field access without parentheses Original patch from YAMASHINA Hio posted to erlang-patches@ on Tue Jun 12 11:27:53 CEST 2007: http://www.erlang.org/pipermail/erlang-patches/2007-June/000182.html http://fleur.hio.jp/pub/erlang/record2.patch Only had to do minor changes to port the patch to the current R14A development tree. Also added compiler/record_SUITE:nested_access/2 to test nested record access with or without parentheses. With this change the following will work. -record(nrec0, {name = <<"nested0">>}). -record(nrec1, {name = <<"nested1">>, nrec0=#nrec0{}}). -record(nrec2, {name = <<"nested2">>, nrec1=#nrec1{}}). nested_access() -> N0 = #nrec0{}, N1 = #nrec1{}, N2 = #nrec2{}, <<"nested0">> = N0#nrec0.name, <<"nested1">> = N1#nrec1.name, <<"nested2">> = N2#nrec2.name, <<"nested0">> = N1#nrec1.nrec0#nrec0.name, <<"nested0">> = N2#nrec2.nrec1#nrec1.nrec0#nrec0.name, <<"nested1">> = N2#nrec2.nrec1#nrec1.name, <<"nested0">> = ((N2#nrec2.nrec1)#nrec1.nrec0)#nrec0.name, N1a = N2#nrec2.nrec1#nrec1{name = <<"nested1a">>}, <<"nested1a">> = N1a#nrec1.name, N2a = N2#nrec2.nrec1#nrec1.nrec0#nrec0{name = <<"nested0a">>}, N2b = ((N2#nrec2.nrec1)#nrec1.nrec0)#nrec0{name = <<"nested0a">>}, <<"nested0a">> = N2a#nrec0.name, N2a = N2b, ok. Signed-off-by: Tuncer Ayaz --- lib/stdlib/src/erl_parse.yrl | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/stdlib/src') diff --git a/lib/stdlib/src/erl_parse.yrl b/lib/stdlib/src/erl_parse.yrl index 7145cf13fd..69807aad83 100644 --- a/lib/stdlib/src/erl_parse.yrl +++ b/lib/stdlib/src/erl_parse.yrl @@ -335,6 +335,10 @@ record_expr -> expr_max '#' atom '.' atom : {record_field,?line('$2'),'$1',element(3, '$3'),'$5'}. record_expr -> expr_max '#' atom record_tuple : {record,?line('$2'),'$1',element(3, '$3'),'$4'}. +record_expr -> record_expr '#' atom '.' atom : + {record_field,?line('$2'),'$1',element(3, '$3'),'$5'}. +record_expr -> record_expr '#' atom record_tuple : + {record,?line('$2'),'$1',element(3, '$3'),'$4'}. record_tuple -> '{' '}' : []. record_tuple -> '{' record_fields '}' : '$2'. -- cgit v1.2.3