factor : factor LBRACK conditional RBRACK

def p_factor_item(self, p):
        """
        factor : factor LBRACK conditional RBRACK
        """

        def resolve_item(obj, index):
            if is_ndarray(obj) or isinstance(obj, (list, tuple)):
                if not isinstance(index, int):
                    raise TypeError("Not a valid array index: '{}'".format(index))

            elif isinstance(obj, dict):
                if not isinstance(index, (six.string_types, int)):
                    raise TypeError("Not a valid dictionary index: '{}'".format(index))

            else:
                raise TypeError("Object does not support indexing: '{}'".format(type(obj)))

            return obj[index]

        p[0] = Instruction('resolve_item(obj, index)', context={
            'resolve_item': resolve_item,
            'obj': p[1],
            'index': p[3]
        })