protected function parse(array $structure, int $offset = null)
    {
        $result = [];
        $current = $offset ?? 0;

        $count_structure = 0;
        foreach ($structure as $registry_group) {
            if (is_array($registry_group)) {
                $buffer = [];
                do {
                    try {
                        $rec = $this->parse($registry_group, $current);
                        $nested = (count($registry_group) > 1)
                            ? [$rec['registries']]
                            : $rec['registries'];
                        $buffer = array_merge($buffer, $nested);
                        $current = $rec['offset'];
                    } catch (ParseException $e) {
                        if (count($buffer) === 0) {
                            throw $e;
                        } else {
                            $first = $registry_group[0];
                            if (is_string($first)) {
                                $first = explode(' ', $first);
                            }
                            $in_first = array_intersect(
                                $first,
                                $e->getRegistries()
                            );
                            if (count($in_first) === 0) {
                                throw $e;
                            }
                            break;
                        }
                    }
                } while ($current < count($this->registries));
                $nested = (count($registry_group) > 1)
                    ? $buffer
                    : [$buffer];
                $result = array_merge($result, $nested);
            } else {
                $types = explode(' ', $registry_group);
                $registry = $this->pregRegistry($current, $types);

                if ($registry !== null) {
                    $result[] = $registry;
                    $current++;
                } elseif (count($result) === 0 || $count_structure > 0) {
                    throw new ParseException(
                        $this->config,
                        $types,
                        $current + 1
                    );
                }
            }
            $count_structure++;
        }

        return [
            'offset' => $current,
            'registries' => $result,
        ];
    }