@@ -439,6 +439,27 @@ module E = struct
439439 field ~loc ~attrs (sub.expr sub e) (map_loc sub lid)
440440 | Pexp_setfield (e1 , lid , e2 ) ->
441441 setfield ~loc ~attrs (sub.expr sub e1) (map_loc sub lid) (sub.expr sub e2)
442+ | Pexp_index (e1 , e2 , e3 ) -> (
443+ (* Map back to Array.get/Array.set for parsetree0 compatibility *)
444+ let container = sub.expr sub e1 in
445+ let index = sub.expr sub e2 in
446+ match e3 with
447+ | None ->
448+ (* Read: Array.get(container, index) *)
449+ let array_get =
450+ ident ~loc
451+ (mknoloc (Longident. Ldot (Longident. Lident " Array" , " get" )))
452+ in
453+ apply ~loc ~attrs array_get [(Nolabel , container); (Nolabel , index)]
454+ | Some value ->
455+ (* Write: Array.set(container, index, value) *)
456+ let array_set =
457+ ident ~loc
458+ (mknoloc (Longident. Ldot (Longident. Lident " Array" , " set" )))
459+ in
460+ let value_expr = sub.expr sub value in
461+ apply ~loc ~attrs array_set
462+ [(Nolabel , container); (Nolabel , index); (Nolabel , value_expr)])
442463 | Pexp_array el -> array ~loc ~attrs (List. map (sub.expr sub) el)
443464 | Pexp_ifthenelse (e1 , e2 , e3 ) ->
444465 ifthenelse ~loc ~attrs (sub.expr sub e1) (sub.expr sub e2)
0 commit comments