Remove redundant method
All checks were successful
timw4mail/php-kilo/pipeline/head This commit looks good
All checks were successful
timw4mail/php-kilo/pipeline/head This commit looks good
This commit is contained in:
parent
52875f348f
commit
5746d15117
@ -16,6 +16,12 @@ class FileType {
|
||||
$ext = strstr(basename($filename), '.');
|
||||
$ext = ($ext !== FALSE) ? $ext : '';
|
||||
return match ($ext) {
|
||||
'.sh', '.bash' => Syntax::new(
|
||||
'Shell',
|
||||
slcs: '#',
|
||||
mcs: '',
|
||||
mce: '',
|
||||
),
|
||||
'.php', 'kilo' => Syntax::new(
|
||||
'PHP',
|
||||
),
|
||||
|
155
src/Row.php
155
src/Row.php
@ -152,7 +152,80 @@ class Row {
|
||||
public function highlight(): void
|
||||
{
|
||||
$this->render = tabs_to_spaces($this->chars);
|
||||
$this->highlightGeneral();
|
||||
$this->hl = array_fill(0, $this->rsize, Highlight::NORMAL);
|
||||
|
||||
if ($this->parent->fileType->name === 'PHP')
|
||||
{
|
||||
$this->highlightPHP();
|
||||
return;
|
||||
}
|
||||
|
||||
$syntax = $this->parent->fileType->syntax;
|
||||
|
||||
$mcs = $syntax->multiLineCommentStart;
|
||||
$mce = $syntax->multiLineCommentEnd;
|
||||
|
||||
$mcsLen = strlen($mcs);
|
||||
$mceLen = strlen($mce);
|
||||
|
||||
$inString = '';
|
||||
$inComment = ($this->idx > 0 && $this->parent->rows[$this->idx - 1]->hlOpenComment);
|
||||
|
||||
$i = 0;
|
||||
|
||||
while ($i < $this->rsize)
|
||||
{
|
||||
// Multi-line comments
|
||||
if ($mcsLen > 0 && $mceLen > 0 && $inString === '')
|
||||
{
|
||||
if ($inComment)
|
||||
{
|
||||
$this->hl[$i] = Highlight::ML_COMMENT;
|
||||
if (substr($this->render, $i, $mceLen) === $mce)
|
||||
{
|
||||
array_replace_range($this->hl, $i, $mceLen, Highlight::ML_COMMENT);
|
||||
$i += $mceLen;
|
||||
$inComment = FALSE;
|
||||
continue;
|
||||
}
|
||||
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (substr($this->render, $i, $mcsLen) === $mcs)
|
||||
{
|
||||
array_replace_range($this->hl, $i, $mcsLen, Highlight::ML_COMMENT);
|
||||
$i += $mcsLen;
|
||||
$inComment = TRUE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
$this->highlightComment($i, $syntax)
|
||||
|| $this->highlightMultilineComments($i, $syntax)
|
||||
|| $this->highlightPrimaryKeywords($i, $syntax)
|
||||
|| $this->highlightSecondaryKeywords($i, $syntax)
|
||||
|| $this->highlightOperators($i, $syntax)
|
||||
|| $this->highlightCommonOperators($i)
|
||||
|| $this->highlightCommonDelimeters($i)
|
||||
|| $this->highlightCharacter($i, $syntax)
|
||||
|| $this->highlightString($i, $syntax)
|
||||
|| $this->highlightNumber($i, $syntax)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$changed = $this->hlOpenComment !== $inComment;
|
||||
$this->hlOpenComment = $inComment;
|
||||
if ($changed && $this->idx + 1 < $this->parent->numRows)
|
||||
{
|
||||
$this->parent->rows[$this->idx + 1]->highlight();
|
||||
}
|
||||
}
|
||||
|
||||
protected function highlightNumber(int &$i, Syntax $opts): bool
|
||||
@ -280,7 +353,7 @@ class Row {
|
||||
if ($opts->characters() && $char === "'")
|
||||
{
|
||||
$offset = ($nextChar === '\\') ? $i + 2 : $i + 1;
|
||||
$closingIndex = strpos($this->render, "'", $i + 1);
|
||||
$closingIndex = strpos($this->render, "'", $offset);
|
||||
if ($closingIndex === false)
|
||||
{
|
||||
return false;
|
||||
@ -394,84 +467,6 @@ class Row {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function highlightGeneral(): void
|
||||
{
|
||||
$this->hl = array_fill(0, $this->rsize, Highlight::NORMAL);
|
||||
|
||||
if ($this->parent->fileType->name === 'PHP')
|
||||
{
|
||||
$this->highlightPHP();
|
||||
return;
|
||||
}
|
||||
|
||||
$syntax = $this->parent->fileType->syntax;
|
||||
|
||||
$mcs = $syntax->multiLineCommentStart;
|
||||
$mce = $syntax->multiLineCommentEnd;
|
||||
|
||||
$mcsLen = strlen($mcs);
|
||||
$mceLen = strlen($mce);
|
||||
|
||||
$inString = '';
|
||||
$inComment = ($this->idx > 0 && $this->parent->rows[$this->idx - 1]->hlOpenComment);
|
||||
|
||||
$i = 0;
|
||||
|
||||
while ($i < $this->rsize)
|
||||
{
|
||||
// Multi-line comments
|
||||
if ($mcsLen > 0 && $mceLen > 0 && $inString === '')
|
||||
{
|
||||
if ($inComment)
|
||||
{
|
||||
$this->hl[$i] = Highlight::ML_COMMENT;
|
||||
if (substr($this->render, $i, $mceLen) === $mce)
|
||||
{
|
||||
array_replace_range($this->hl, $i, $mceLen, Highlight::ML_COMMENT);
|
||||
$i += $mceLen;
|
||||
$inComment = FALSE;
|
||||
continue;
|
||||
}
|
||||
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (substr($this->render, $i, $mcsLen) === $mcs)
|
||||
{
|
||||
array_replace_range($this->hl, $i, $mcsLen, Highlight::ML_COMMENT);
|
||||
$i += $mcsLen;
|
||||
$inComment = TRUE;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
$this->highlightComment($i, $syntax)
|
||||
|| $this->highlightMultilineComments($i, $syntax)
|
||||
|| $this->highlightPrimaryKeywords($i, $syntax)
|
||||
|| $this->highlightSecondaryKeywords($i, $syntax)
|
||||
|| $this->highlightOperators($i, $syntax)
|
||||
|| $this->highlightCommonOperators($i)
|
||||
|| $this->highlightCommonDelimeters($i)
|
||||
|| $this->highlightCharacter($i, $syntax)
|
||||
|| $this->highlightString($i, $syntax)
|
||||
|| $this->highlightNumber($i, $syntax)
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$changed = $this->hlOpenComment !== $inComment;
|
||||
$this->hlOpenComment = $inComment;
|
||||
if ($changed && $this->idx + 1 < $this->parent->numRows)
|
||||
{
|
||||
$this->parent->rows[$this->idx + 1]->highlight();
|
||||
}
|
||||
}
|
||||
|
||||
protected function highlightPHP(): void
|
||||
{
|
||||
$rowNum = $this->idx + 1;
|
||||
|
Loading…
Reference in New Issue
Block a user