Add a closing parenthesis

@param object  $node   The node to monkey patch.
@param array   $parent The parent array.
@param integer $index  The index of node in parent children.
@return boolean        Returns `true` if succeed, `false` otherwise.
513436
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;
    }
691252
protected function _processTree($parent)
    {
        $alphanum = '[\\\a-zA-Z0-9_\\x7f-\\xff]';
        $regex = "/(?<!\:|\\\$|\>|{$alphanum})(\s*)((?:exit|die)\s*)([\(|;])/m";

        foreach ($parent->tree as $node) {
            if ($node->processable && $node->type === 'code') {
                $node->body = preg_replace_callback($regex, function ($matches) {
                    return $matches[1] . '\Kahlan\Plugin\Quit::quit' . ($matches[3] === '(' ? '(' : '();');
                }, $node->body);
            }
            if (!empty($node->tree)) {
                $this->_processTree($node);
            }
        }
    }
159351
public function set_parent(Node_Container $parent=null)
	{
		$this->parent = $parent;

		if($parent instanceof Node_Container_Document)
			$this->root = $parent;
		else
			$this->root = $parent->root();
	}
699364
public static function nodesTreeList($parentId = 0, $level = 0, $shiftPrefix = '. ')
    {
        if (!isset(static::$_nodesTreeList[$parentId][$level][$shiftPrefix])) {
            $tree = [];
            $list = [];

            $parentNode = static::node($parentId);
            if (!empty($parentNode)) {
                $grandParentId = $parentNode['parent_id'];
                $grandParentNode = static::node($grandParentId);
                $nodePath = (empty($grandParentNode->nodePath)
                             ? '' : $grandParentNode->nodePath . '/'
                         ) . $parentNode['slug'];
                $list[$parentId] = str_repeat($shiftPrefix, $level) . $nodePath;
                $tree[$parentId] = str_repeat($shiftPrefix, $level) . $parentNode['slug'];
                static::saveNodePath($parentId, $nodePath);
            }

            $children = static::nodeChildren($parentId);
            foreach ($children as $child) {
                static::$_nodes[$child['id']] = $child;
                $list += static::nodesTreeList($child->id, $level+1, $shiftPrefix);
                $tree += static::nodesTree($child->id, $level+1, $shiftPrefix);
            }
            static::$_nodesTree[$parentId][$level][$shiftPrefix] = $tree;
            static::$_nodesTreeList[$parentId][$level][$shiftPrefix] = $list;
        }    
        return static::$_nodesTreeList[$parentId][$level][$shiftPrefix];
    }
1061999
private function appendDocument(\DOMNode $parentNode, \DOMNode $importedParent)
    {
        foreach ($importedParent->childNodes as $childNode) {
            $parentNode->appendChild($parentNode->ownerDocument->importNode($childNode, true));
        }
    }
1350414
protected function encloseBlock($node) {
    if ($node && !($node instanceof StatementBlockNode)) {
      $blockNode = new StatementBlockNode();
      $blockNode->append([Token::openBrace(), clone $node, Token::closeBrace()]);
      $node->replaceWith($blockNode);
    }
  }
677098
public static function add($parent = false)
    {
        $db = Database::connection();
        $treeNodeParentID = 0;
        $treeID = 0;
        $treeNodeDisplayOrder = 0;
        $inheritPermissionsFromTreeNodeID = 0;
        if (is_object($parent)) {
            $treeNodeParentID = $parent->getTreeNodeID();
            $treeID = $parent->getTreeID();
            $inheritPermissionsFromTreeNodeID = $parent->getTreeNodePermissionsNodeID();
            $treeNodeDisplayOrder = (int) $db->fetchColumn('select count(treeNodeDisplayOrder) from TreeNodes where treeNodeParentID = ?', [$treeNodeParentID]);
            $parent->updateDateModified();
        } else {
            $parent = null;
        }

        $treeNodeTypeHandle = uncamelcase(strrchr(get_called_class(), '\\'));

        $dateModified = Core::make('date')->toDB();
        $dateCreated = Core::make('date')->toDB();

        $type = TreeNodeType::getByHandle($treeNodeTypeHandle);
        $db->executeQuery(
            'insert into TreeNodes (treeNodeTypeID, treeNodeParentID, treeNodeDisplayOrder, inheritPermissionsFromTreeNodeID, dateModified, dateCreated, treeID) values (?, ?, ?, ?, ?, ?, ?)',
            [
                $type->getTreeNodeTypeID(),
                $treeNodeParentID,
                $treeNodeDisplayOrder,
                $inheritPermissionsFromTreeNodeID,
                $dateModified,
                $dateCreated,
                $treeID,
            ]
        );
        $id = $db->lastInsertId();
        $node = self::getByID($id);

        if (!$inheritPermissionsFromTreeNodeID) {
            $node->setTreeNodePermissionsToOverride();
        }

        if ($parent !== null && $parent->childNodesLoaded) {
            $parent->childNodes[] = $node;
        }

        return $node;
    }
147282
public function AddParent($parent)
    {
        $parent = str_replace("::", "\\", $parent);
        
        $this->parents[$parent] = $parent;
        $this->has_parent = true;
        
        return $this;
    }
287117
public function moveAsLastChildOf(NodeInterface $parentNode)
	{
		$this->validateAddingChildren($parentNode);

		$pos = $parentNode->getRightValue();
		$level = $parentNode->getLevel() + 1;
		$this->move($pos, $level);

		return $this;
	}
1017295
public function moveTo($id, $parent_id) {
        $pk = $this->getRepository()->getPrimaryKey();
        $node = $this->getNode($id);

        if (!$node || $node[$this->getConfig('parentField')] == $parent_id) {
            return false;
        }

        $left = $this->getConfig('leftField');
        $right = $this->getConfig('rightField');
        $data = [];

        // Remove the node and reset others
        $this->_removeNode($id, $node[$left]);

        // Insert into parent
        if ($parent_id && ($parentNode = $this->getNode($parent_id))) {
            $data = [
                $left => $parentNode[$right],
                $right => $parentNode[$right] + 1
            ];

        // Or the root
        } else if ($lastNode = $this->getLastNode()) {
            $data = [
                $left => $lastNode[$right] + 1,
                $right => $lastNode[$right] + 2
            ];
        }

        // Move it
        $this->_moveNode(function(Query $query) use ($pk, $id) {
            $query->where($pk, $id);
        }, $data + [
            $this->getConfig('parentField') => $parent_id
        ]);

        $this->_insertNode($id, $data[$left]);

        return true;
    }
779287
public function invoke($node, NodeInterface $parent): void
    {
        if (! $node instanceof Node\Expr || ! $parent instanceof VariableLikeInterface) {
            throw new Exception('ValueNodeParser is made to parse a expression node');
        }
    }
1344697
public function pExpr_Closure(Expr\Closure $node)
    {
        return sprintf(
            "%s%s %s(%s)%s%s %s%s\n%s",
            ($node->static ? 'static ' : ''),
            $this->color('function', SyntaxHighlighterConfig::TYPE_KEYWORD),
            ($node->byRef ? '&' : ''),
            $this->pCommaSeparated($node->params),
            (!empty($node->uses) ? ' use(' . $this->pCommaSeparated($node->uses) . ')': ''),
            (null !== $node->returnType ? ' : ' . $this->pType($node->returnType) : ''),
            $this->color('{', SyntaxHighlighterConfig::TYPE_BRACE),
            $this->pStmts($node->stmts),
            $this->color('}', SyntaxHighlighterConfig::TYPE_BRACE)
        );
    }
883352
protected function collapseTokenTree($node)
    {
        $text = '';
        foreach ($node['children'] as $c) {
            if (is_string($c)) {
                $text .= Utils::escapeString($c);
            } else {
                $text .= $this->collapseTokenTree($c);
            }
        }
        $tokenName = $node['token_name'];
        $token = array($node['token_name'], $text, true);

        $token_ = $this->ruleMapperFilter(array($token));
        $token = $token_[0];

        if (isset($this->filters[$tokenName])) {
            foreach ($this->filters[$tokenName] as $filter) {
                $token = call_user_func($filter[1], $token);
            }
        }
        list($tokenName, $text,) = $token;
        return ($tokenName === null) ? $text : Utils::tagBlock($tokenName, $text);
    }
792156
def move_node(self, parent, from_index, to_index):
        

        # TODO: Should be refactored once this ticket is fixed:
        # https://bugreports.qt-project.org/browse/PYSIDE-78
        if not from_index >= 0 or \
                not from_index < parent.children_count() or \
                not to_index >= 0 or \
                not to_index < parent.children_count():
            return False

        parent_index = self.get_node_index(parent)
        self.beginRemoveRows(parent_index, from_index, from_index)
        child = parent.remove_child(from_index)
        self.endRemoveRows()

        start_index = parent.children_count() - 1
        end_index = to_index - 1

        tail = []
        for i in range(start_index, end_index, -1):
            self.beginRemoveRows(parent_index, i, i)
            tail.append(parent.remove_child(i))
            self.endRemoveRows()
        tail = list(reversed(tail))
        tail.insert(0, child)

        for node in tail:
            row = parent.children_count()
            self.beginInsertRows(parent_index, row, row)
            parent.add_child(node)
            self.endInsertRows()

        return True
58558
public function set_parent(navigation_node $parent) {
        // Set the parent (thats the easy part)
        $this->parent = $parent;
        // Check if this node is active (this is checked during construction)
        if ($this->isactive) {
            // Force all of the parent nodes open so you can see this node
            $this->parent->force_open();
            // Make all parents inactive so that its clear where we are.
            $this->parent->make_inactive();
        }
    }
1152430
private function _processParenthesisClose($token) {
		$this->statementStack->getCurrentStackItem()->openParentheses -= 1;

		// Decrease the number of opened brackets
		if ($this->_inFuncCall) {
			$this->_fcLeftParenthesis -= 1;
		} elseif ($this->_inControlStatement || $this->_inFunctionStatement) {
			$this->_csLeftParenthesis -= 1;
		}
		// If 0 we are not in the call anymore
		if ($this->_fcLeftParenthesis === 0) {
			$this->_inFuncCall = false;
			array_pop($this->_currentFuncCall);
		}
		// If 0 we are not in the statement anymore
		if ($this->_csLeftParenthesis === 0) {
			if ($this->_inControlStatement) {
				$this->_inControlStatement = false;
				$this->_justAfterControlStmt = true;
				$this->_checkNeedBraces();
			} elseif ($this->_inFunctionStatement && !$this->_inInterface) {
				$this->_inFunctionStatement = false;
				$this->_justAfterFuncStmt = true;
			}
		}

		// We the count arrive to 0 we probably have something to do
		if ($this->statementStack->getCurrentStackItem()->openParentheses === 0) {

			// We are in a array declaration, we unstack
			if ($this->statementStack->getCurrentStackItem()->type === StatementItem::TYPE_ARRAY && $this->statementStack->getCurrentStackItem()->name !== 'square_bracket_open') {
				$this->statementStack->pop();
			}
		}
	}
840776
public function insertAtIndex(ResourceNode $node, $index)
    {
        //throw new \Exception($index);
        $this->om->startFlushSuite();

        if ($index > $node->getIndex()) {
            $this->shiftLeftAt($node->getParent(), $index);
            $node->setIndex($index);
        } else {
            $this->shiftRightAt($node->getParent(), $index);
            $node->setIndex($index);
        }

        $this->om->persist($node);
        $this->om->forceFlush();
        $this->reorder($node->getParent());
        $this->om->endFlushSuite();
    }