aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/src/erl_parse.yrl
diff options
context:
space:
mode:
authorTuncer Ayaz <[email protected]>2010-04-20 20:43:10 +0200
committerTuncer Ayaz <[email protected]>2010-04-20 20:46:24 +0200
commit3829e5facc98f1c1d3113b648c0b9fa7362cad32 (patch)
treec4c7fbc68a246d46270fb4ea0ad8f882b40591e6 /lib/stdlib/src/erl_parse.yrl
parent09ca69e2247860fb5494297279c8819a34777cc6 (diff)
downloadotp-3829e5facc98f1c1d3113b648c0b9fa7362cad32.tar.gz
otp-3829e5facc98f1c1d3113b648c0b9fa7362cad32.tar.bz2
otp-3829e5facc98f1c1d3113b648c0b9fa7362cad32.zip
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 <[email protected]>
Diffstat (limited to 'lib/stdlib/src/erl_parse.yrl')
-rw-r--r--lib/stdlib/src/erl_parse.yrl4
1 files changed, 4 insertions, 0 deletions
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'.