Compare commits

..

No commits in common. "c928be2d73e6dbe4508831ce1db95e4c8c765de3" and "608fe6cc628de887d4754798c2d99541953c2ee2" have entirely different histories.

4 changed files with 11 additions and 167 deletions

View File

@ -3,12 +3,7 @@
namespace Aviat\Kilo;
class FileType {
/**
* Create the FileType object from the filename
*
* @param string|null $filename
* @return self
*/
public static function from(?string $filename): self
{
$syntax = self::getSyntaxFromFilename((string)$filename);
@ -16,12 +11,6 @@ class FileType {
return new self($syntax->filetype, $syntax);
}
/**
* Create the Syntax object from the filename
*
* @param string $filename
* @return Syntax
*/
private static function getSyntaxFromFilename(string $filename): Syntax
{
$ext = strstr(basename($filename), '.');
@ -29,16 +18,9 @@ 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'],
operators: ['[[', ']]'],
slcs: '#',
mcs: '',
mce: '',
highlightNumbers: false,
),
'.php', 'kilo' => Syntax::new(
'PHP',
@ -67,7 +49,6 @@ class FileType {
'.css', '.less', '.sass', '.scss' => Syntax::new(
'CSS',
slcs: '',
hasCommonOperators: false,
),
'.go' => Syntax::new(
'Go',
@ -115,12 +96,6 @@ class FileType {
'usize', '&str', 'Copy', 'Drop', 'From', 'Into', 'None', 'Self', 'Send', 'Some',
'Sync', 'bool', 'char', 'i128', 'u128', 'Box', 'Err', 'Ord', 'Vec', 'dyn', 'f32',
'f64', 'i16', 'i32', 'i64', 'str', 'u16', 'u32', 'u64', 'Eq', 'Fn', 'Ok', 'i8', 'u8',
'&mut self', '&mut', '&self', 'self',
],
[
'...', '=>', '..', '>>=', '<<=', '--', '%=', '>>', ':=', '++', '/=', '<<', '>=',
'<-', '^=', '*=', '<=', '||', '|=', '-=', '!=', '==', '&&', '&=', '+=', '..=',
'.',
],
hasCharType: true,
highlightCharacters: true,

View File

@ -11,6 +11,8 @@ use Aviat\Kilo\Enum\RawKeyCode;
* @property-read string $chars
*/
class Row {
// use Traits\MagicProperties;
/**
* The version of the row to be displayed (where tabs are converted to display spaces)
*/
@ -168,11 +170,6 @@ class Row {
$this->update();
}
/**
* Set the contents of the Row
*
* @param string $chars
*/
public function setChars(string $chars): void
{
$this->chars = $chars;
@ -260,7 +257,7 @@ class Row {
|| $this->highlightString($i, $syntax)
|| $this->highlightOperators($i, $syntax)
|| $this->highlightCommonDelimeters($i)
|| $this->highlightCommonOperators($i, $syntax)
|| $this->highlightCommonOperators($i)
|| $this->highlightNumber($i, $syntax)
) {
continue;
@ -277,17 +274,10 @@ class Row {
}
}
/**
* Highlight number literals
*
* @param int $i
* @param Syntax $opts
* @return bool
*/
protected function highlightNumber(int &$i, Syntax $opts): bool
{
$char = $this->render[$i];
if ($opts->numbers() && is_digit($char) && $this->hl[$i] === Highlight::NORMAL)
if ($opts->numbers() && is_digit($char))
{
if ($i > 0)
{
@ -321,18 +311,9 @@ class Row {
return false;
}
/**
* Highlight keywords and/or operators
*
* @param int $i
* @param array $keywords
* @param int $syntaxType
* @param bool $requireSeparator
* @return bool
*/
protected function highlightWord(int &$i, array $keywords, int $syntaxType, bool $requireSeparator = true): bool
protected function highlightWord(int &$i, array $keywords, int $syntaxType): bool
{
if ($i > 0 && $requireSeparator)
if ($i > 0)
{
$prevChar = $this->render[$i - 1];
if ( ! is_separator($prevChar))
@ -360,14 +341,6 @@ class Row {
return false;
}
/**
* Highlight a single-char character from a list of provided keywords
*
* @param int $i
* @param array $chars
* @param int $syntaxType
* @return bool
*/
protected function highlightChar(int &$i, array $chars, int $syntaxType): bool
{
if ($this->hl[$i] !== Highlight::NORMAL)
@ -388,56 +361,23 @@ class Row {
return false;
}
/**
* Highlight primary keywords
*
* @param int $i
* @param Syntax $opts
* @return bool
*/
protected function highlightPrimaryKeywords(int &$i, Syntax $opts): bool
{
return $this->highlightWord($i, $opts->keywords1, Highlight::KEYWORD1);
}
/**
* Highlight secondary keywords
*
* @param int $i
* @param Syntax $opts
* @return bool
*/
protected function highlightSecondaryKeywords(int &$i, Syntax $opts): bool
{
return $this->highlightWord($i, $opts->keywords2, Highlight::KEYWORD2);
}
/**
* Highlight language-specific operators
*
* @param int $i
* @param Syntax $opts
* @return bool
*/
protected function highlightOperators(int &$i, Syntax $opts): bool
{
return $this->highlightWord($i, $opts->operators, Highlight::OPERATOR, false);
return $this->highlightWord($i, $opts->operators, Highlight::OPERATOR);
}
/**
* Highlight common single-character operators
*
* @param int $i
* @param Syntax $opts
* @return bool
*/
protected function highlightCommonOperators(int &$i, Syntax $opts): bool
protected function highlightCommonOperators(int &$i): bool
{
if ( ! $opts->commonOperators())
{
return false;
}
return $this->highlightChar(
$i,
['+', '-', '*', '/', '<', '^', '>', '%', '=', ':', ',', ';', '&', '~', '!', '|', '.'],
@ -445,12 +385,6 @@ class Row {
);
}
/**
* Highlight brackets and braces
*
* @param int $i
* @return bool
*/
protected function highlightCommonDelimeters(int &$i): bool
{
return $this->highlightChar(
@ -460,13 +394,6 @@ class Row {
);
}
/**
* Highlight character literals
*
* @param int $i
* @param Syntax $opts
* @return bool
*/
protected function highlightCharacter(int &$i, Syntax $opts): bool
{
if (($i + 1) >= $this->rsize)
@ -499,13 +426,6 @@ class Row {
return false;
}
/**
* Highlight single-line comments
*
* @param int $i
* @param Syntax $opts
* @return bool
*/
protected function highlightComment(int &$i, Syntax $opts): bool
{
if ( ! $opts->comments())
@ -527,13 +447,6 @@ class Row {
return false;
}
/**
* Highlight quote-delimited string literals
*
* @param int $i
* @param Syntax $opts
* @return bool
*/
protected function highlightString(int &$i, Syntax $opts): bool
{
$char = $this->render[$i];
@ -577,9 +490,6 @@ class Row {
return false;
}
/**
* Highlight PHP code based on pre-parsed tokens
*/
protected function highlightPHP(): void
{
$rowNum = $this->idx + 1;

View File

@ -19,7 +19,6 @@ class Syntax {
bool $highlightComments = true,
bool $hasCharType = false,
bool $highlightCharacters = false,
bool $hasCommonOperators = true,
): self
{
return new self(
@ -35,21 +34,12 @@ class Syntax {
$highlightCharacters,
$highlightStrings,
$highlightComments,
$hasCommonOperators,
);
}
public static function default(): self
{
return self::new(
'No filetype', slcs:
'', mcs:
'', mce:
'',
highlightNumbers: false,
highlightStrings: false,
hasCommonOperators: false,
);
return self::new('No filetype', slcs: '', mcs: '', mce: '', highlightNumbers: false, highlightStrings: false);
}
private function __construct(
@ -65,7 +55,7 @@ class Syntax {
public string $singleLineCommentStart,
/** Syntax to start a multi-line comment */
public string $multiLineCommentStart,
/** Syntax to end a multi-line comment */
/** Syntax to end a multi-line commment */
public string $multiLineCommentEnd,
/** Should we highlight numbers? */
private bool $highlightNumbers,
@ -77,8 +67,6 @@ class Syntax {
private bool $highlightStrings,
/** should we highlight comments? */
private bool $highlightComments,
/** should we highlight common operators? */
private bool $hasCommonOperators,
) {}
public function numbers(): bool
@ -112,9 +100,4 @@ class Syntax {
{
return $this->highlightComments && strlen($this->singleLineCommentStart) !== 0;
}
public function commonOperators(): bool
{
return $this->hasCommonOperators;
}
}

View File

@ -1,24 +0,0 @@
<?php declare(strict_types=1);
namespace Aviat\Kilo\Tests\Type;
use Aviat\Kilo\Type\Point;
use PHPUnit\Framework\TestCase;
class PointTest extends TestCase {
public function testNewPoint(): void
{
$p = Point::new(1, 2);
$this->assertEquals(1, $p->x);
$this->assertEquals(2, $p->y);
}
public function testPointFrom(): void
{
$p = Point::new(3, 7);
$p2 = Point::from($p);
$this->assertEquals($p->x, $p2->x);
$this->assertEquals($p->y, $p2->y);
}
}