protected function _addClosingParenthesis($pos, $index, $parent)
    {
        $count = 0;
        $nodes = $parent->tree;
        $total = count($nodes);

        for ($i = $index; $i < $total; $i++) {
            $node = $nodes[$i];

            if (!$node->processable || $node->type !== 'code') {
                if (!$node->close) {
                    continue;
                }
                $code = &$node->close;
            } else {
                $code = &$node->body;
            }

            $len = strlen($code);

            while ($pos < $len) {
                if ($count === 0 && $code[$pos] === ';') {
                    $code = substr_replace($code, ');', $pos, 1);
                    return true;
                } elseif ($code[$pos] === '(') {
                    $count++;
                } elseif ($code[$pos] === ')') {
                    $count--;
                    if ($count === 0) {
                        $code = substr_replace($code, $code[$pos] . ')', $pos, 1);
                        return true;
                    }
                }
                $pos++;
            }
            $pos = 0;
        }
        return false;
    }