hasUnrecoverableSyntaxError()) { return false; } $line = $buffer->getText(); if ($readline->isCommand($line) && !$readline->isInOpenStringOrComment($line)) { return false; } // Don't reject when there are truly unclosed brackets before // cursor (more opens than closes). In that case, the user is // still typing inside a bracket pair and the unclosed-brackets // action should handle continuation instead. if ($this->hasOpenBracketsBeforeCursor($buffer)) { return false; } $readline->setInputFrameError(true); $terminal->bell(); return true; } /** * Check if text before cursor has more opening brackets than closing. */ private function hasOpenBracketsBeforeCursor(Buffer $buffer): bool { $text = $buffer->getBeforeCursor(); if (\trim($text) === '') { return false; } $tokens = @\token_get_all(' 1, ')' => -1, '[' => 1, ']' => -1, '{' => 1, '}' => -1]; foreach ($tokens as $token) { if (\is_string($token) && isset($pairs[$token])) { $depth += $pairs[$token]; } } return $depth > 0; } /** * {@inheritdoc} */ public function getName(): string { return 'reject-syntax-error'; } }