# --- Rules --- parse : stmt(s?) EOF { $item[1] } stmt : variable ';' { $item[1] } | array ';' { $item[1] } | hash ';' { $item[1] } | arrayelement : term ',' { [ @item[0, 1] ] } | term { [ @item[0, 1] ] } arrayname : ARRAY IDENTIFIER { [ 'array', $item[2] ] } array : arrayname EQUAL arrayelement(s?) { [ @item[2, 4] ] } hashelement : IDENTIFIER HASHASSIGN term ',' { [ @item[0,1,3] ] } | IDENTIFIER HASHASSIGN term { [ @item[0,1,3] ] } hash : HASH IDENTIFIER EQUAL '{' hashelement(s?) '}' { [ @item [0, 2, 5] ] } variablename : VAR IDENTIFIER { [ 'variable', $item[2] ] } variable : variablename EQUAL term { [ @item[0, 2, 4] ] } term : QUOTE IDENTIFIER QUOTE { [ 'identifier', $item[2] ] } | LITERAL { [ 'literal', $item[1] ] } | arrayname { $item[1] } | variablename { $item[1] } #### $VAR1 = [ [ 'hash', 'stuff', [ [ 'hashelement', 'animal', [ 'array', 'pets' ] ], [ 'hashelement', 'age', [ 'literal', '5' ] ], [ 'hashelement', 'name', [ 'identifier', 'fluffy' ] ], [ 'hashelement', 'colour', [ 'variable', 'col' ] ] ] ] ];