Make operator highlighting optional
All checks were successful
timw4mail/php-kilo/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2021-04-14 17:19:01 -04:00
parent d0817b62c4
commit e22bb0545d
3 changed files with 24 additions and 3 deletions

View File

@ -18,9 +18,15 @@ class FileType {
return match ($ext) {
'.sh', '.bash' => Syntax::new(
'Shell',
[
'case', 'do', 'done', 'elif', 'else', 'esac', 'fi', 'for', 'function', 'if', 'in',
'select', 'then', 'time', 'until', 'while', 'declare',
],
['set'],
slcs: '#',
mcs: '',
mce: '',
highlightNumbers: false,
),
'.php', 'kilo' => Syntax::new(
'PHP',
@ -49,6 +55,7 @@ class FileType {
'.css', '.less', '.sass', '.scss' => Syntax::new(
'CSS',
slcs: '',
hasCommonOperators: false,
),
'.go' => Syntax::new(
'Go',

View File

@ -257,7 +257,7 @@ class Row {
|| $this->highlightString($i, $syntax)
|| $this->highlightOperators($i, $syntax)
|| $this->highlightCommonDelimeters($i)
|| $this->highlightCommonOperators($i)
|| $this->highlightCommonOperators($i, $syntax)
|| $this->highlightNumber($i, $syntax)
) {
continue;
@ -376,8 +376,13 @@ class Row {
return $this->highlightWord($i, $opts->operators, Highlight::OPERATOR);
}
protected function highlightCommonOperators(int &$i): bool
protected function highlightCommonOperators(int &$i, Syntax $opts): bool
{
if ( ! $opts->commonOperators())
{
return false;
}
return $this->highlightChar(
$i,
['+', '-', '*', '/', '<', '^', '>', '%', '=', ':', ',', ';', '&', '~'],

View File

@ -19,6 +19,7 @@ class Syntax {
bool $highlightComments = true,
bool $hasCharType = false,
bool $highlightCharacters = false,
bool $hasCommonOperators = true,
): self
{
return new self(
@ -34,12 +35,13 @@ class Syntax {
$highlightCharacters,
$highlightStrings,
$highlightComments,
$hasCommonOperators,
);
}
public static function default(): self
{
return self::new('No filetype', slcs: '', mcs: '', mce: '', highlightNumbers: false, highlightStrings: false);
return self::new('No filetype', slcs: '', mcs: '', mce: '', highlightNumbers: false, highlightStrings: false, hasCommonOperators: false);
}
private function __construct(
@ -67,6 +69,8 @@ class Syntax {
private bool $highlightStrings,
/** should we highlight comments? */
private bool $highlightComments,
/** should we highlight common operators? */
private bool $hasCommonOperators,
) {}
public function numbers(): bool
@ -100,4 +104,9 @@ class Syntax {
{
return $this->highlightComments && strlen($this->singleLineCommentStart) !== 0;
}
public function commonOperators(): bool
{
return $this->hasCommonOperators;
}
}