2019-10-24 16:58:52 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
2019-11-08 16:27:08 -05:00
|
|
|
namespace Aviat\Kilo;
|
2019-10-24 16:58:52 -04:00
|
|
|
|
|
|
|
class Syntax {
|
2019-10-29 17:02:03 -04:00
|
|
|
// Tokens for PHP files
|
|
|
|
public array $tokens = [];
|
|
|
|
|
2021-03-05 21:11:27 -05:00
|
|
|
public static function new(
|
|
|
|
string $name,
|
|
|
|
array $keywords1 = [],
|
|
|
|
array $keywords2 = [],
|
2021-04-09 21:19:46 -04:00
|
|
|
array $operators = [],
|
2021-03-05 21:11:27 -05:00
|
|
|
string $slcs = '//',
|
|
|
|
string $mcs = '/*',
|
|
|
|
string $mce = '*/',
|
2021-04-09 19:40:28 -04:00
|
|
|
bool $highlightNumbers = true,
|
|
|
|
bool $highlightStrings = true,
|
|
|
|
bool $highlightComments = true,
|
|
|
|
bool $hasCharType = false,
|
|
|
|
bool $highlightCharacters = false,
|
2021-04-14 17:19:01 -04:00
|
|
|
bool $hasCommonOperators = true,
|
2021-03-05 21:11:27 -05:00
|
|
|
): self
|
2019-10-24 16:58:52 -04:00
|
|
|
{
|
2021-04-09 19:40:28 -04:00
|
|
|
return new self(
|
|
|
|
$name,
|
|
|
|
$keywords1,
|
|
|
|
$keywords2,
|
2021-04-09 21:19:46 -04:00
|
|
|
$operators,
|
2021-04-09 19:40:28 -04:00
|
|
|
$slcs,
|
|
|
|
$mcs,
|
|
|
|
$mce,
|
|
|
|
$highlightNumbers,
|
|
|
|
$hasCharType,
|
|
|
|
$highlightCharacters,
|
|
|
|
$highlightStrings,
|
|
|
|
$highlightComments,
|
2021-04-14 17:19:01 -04:00
|
|
|
$hasCommonOperators,
|
2021-04-09 19:40:28 -04:00
|
|
|
);
|
2019-10-24 16:58:52 -04:00
|
|
|
}
|
|
|
|
|
2021-03-16 18:37:53 -04:00
|
|
|
public static function default(): self
|
|
|
|
{
|
2021-04-14 17:19:01 -04:00
|
|
|
return self::new('No filetype', slcs: '', mcs: '', mce: '', highlightNumbers: false, highlightStrings: false, hasCommonOperators: false);
|
2021-03-16 18:37:53 -04:00
|
|
|
}
|
|
|
|
|
2021-03-05 21:11:27 -05:00
|
|
|
private function __construct(
|
|
|
|
/** The name of the programming language */
|
|
|
|
public string $filetype,
|
|
|
|
/** Primary set of language keywords */
|
|
|
|
public array $keywords1,
|
|
|
|
/** Secondary set of language keywords */
|
|
|
|
public array $keywords2,
|
2021-04-09 21:19:46 -04:00
|
|
|
/** Operators for the current language */
|
|
|
|
public array $operators,
|
2021-03-05 21:11:27 -05:00
|
|
|
/** Syntax to start a single line comment */
|
|
|
|
public string $singleLineCommentStart,
|
|
|
|
/** Syntax to start a multi-line comment */
|
|
|
|
public string $multiLineCommentStart,
|
|
|
|
/** Syntax to end a multi-line commment */
|
2021-03-05 21:16:39 -05:00
|
|
|
public string $multiLineCommentEnd,
|
2021-04-09 19:40:28 -04:00
|
|
|
/** Should we highlight numbers? */
|
|
|
|
private bool $highlightNumbers,
|
|
|
|
/** Does this language have a character type, separate from strings? */
|
|
|
|
private bool $hasCharType,
|
|
|
|
/** Should we highlight chars? */
|
|
|
|
private bool $highlightCharacters,
|
|
|
|
/** should we highlight Strings? */
|
|
|
|
private bool $highlightStrings,
|
|
|
|
/** should we highlight comments? */
|
|
|
|
private bool $highlightComments,
|
2021-04-14 17:19:01 -04:00
|
|
|
/** should we highlight common operators? */
|
|
|
|
private bool $hasCommonOperators,
|
2021-03-05 21:11:27 -05:00
|
|
|
) {}
|
2021-04-09 19:40:28 -04:00
|
|
|
|
|
|
|
public function numbers(): bool
|
|
|
|
{
|
|
|
|
return $this->highlightNumbers;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function strings(): bool
|
|
|
|
{
|
|
|
|
return $this->highlightStrings;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function hasChar(): bool
|
|
|
|
{
|
|
|
|
return $this->hasCharType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function characters(): bool
|
|
|
|
{
|
|
|
|
return $this->hasCharType && $this->highlightCharacters;
|
|
|
|
}
|
|
|
|
|
2021-04-14 13:15:31 -04:00
|
|
|
public function mlComments(): bool
|
|
|
|
{
|
|
|
|
return $this->highlightComments
|
|
|
|
&& strlen($this->multiLineCommentStart) !== 0
|
|
|
|
&& strlen($this->multiLineCommentStart) !== 0;
|
|
|
|
}
|
|
|
|
|
2021-04-09 19:40:28 -04:00
|
|
|
public function comments(): bool
|
|
|
|
{
|
2021-04-14 13:15:31 -04:00
|
|
|
return $this->highlightComments && strlen($this->singleLineCommentStart) !== 0;
|
2021-04-09 19:40:28 -04:00
|
|
|
}
|
2021-04-14 17:19:01 -04:00
|
|
|
|
|
|
|
public function commonOperators(): bool
|
|
|
|
{
|
|
|
|
return $this->hasCommonOperators;
|
|
|
|
}
|
2019-10-24 16:58:52 -04:00
|
|
|
}
|