Another ugly progress commit
This commit is contained in:
parent
bb10b69e12
commit
252eddc093
10
kilo
10
kilo
@ -3,12 +3,8 @@
|
|||||||
|
|
||||||
namespace Kilo;
|
namespace Kilo;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
require_once __DIR__ . '/src/functions.php';
|
||||||
// ! App Constants
|
require_once __DIR__ . '/src/hldb.php';
|
||||||
// -----------------------------------------------------------------------------
|
|
||||||
define('KILO_VERSION', '0.1.0');
|
|
||||||
define('KILO_TAB_STOP', 4);
|
|
||||||
define('KILO_QUIT_TIMES', 3);
|
|
||||||
|
|
||||||
// Log notices/errors/warnings to file
|
// Log notices/errors/warnings to file
|
||||||
set_error_handler(static function (int $no, $str, $file, $line, $context) {
|
set_error_handler(static function (int $no, $str, $file, $line, $context) {
|
||||||
@ -24,8 +20,6 @@ set_error_handler(static function (int $no, $str, $file, $line, $context) {
|
|||||||
}, -1);
|
}, -1);
|
||||||
|
|
||||||
// Set up autoloading
|
// Set up autoloading
|
||||||
require_once __DIR__ . '/src/functions.php';
|
|
||||||
require_once __DIR__ . '/src/hldb.php';
|
|
||||||
spl_autoload_register(static function ($class) {
|
spl_autoload_register(static function ($class) {
|
||||||
$parts = explode('\\', $class);
|
$parts = explode('\\', $class);
|
||||||
$file = __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $parts[1] . '.php';
|
$file = __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $parts[1] . '.php';
|
||||||
|
60
src/Row.php
60
src/Row.php
@ -153,6 +153,8 @@ class Row {
|
|||||||
'}' => Highlight::DELIMITER,
|
'}' => Highlight::DELIMITER,
|
||||||
'(' => Highlight::DELIMITER,
|
'(' => Highlight::DELIMITER,
|
||||||
')' => Highlight::DELIMITER,
|
')' => Highlight::DELIMITER,
|
||||||
|
'"' => Highlight::DELIMITER,
|
||||||
|
"'" => Highlight::DELIMITER,
|
||||||
|
|
||||||
// Single character operators
|
// Single character operators
|
||||||
',' => Highlight::OPERATOR,
|
',' => Highlight::OPERATOR,
|
||||||
@ -492,27 +494,22 @@ class Row {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// A multi-line comment can end in the middle of a line...
|
// A multi-line comment can end in the middle of a line...
|
||||||
while ($inComment)
|
if ($inComment)
|
||||||
{
|
{
|
||||||
if ($token['type'] === T_WHITESPACE)
|
// Try looking for the end of the comment first
|
||||||
{
|
$commentEnd = strpos($this->render, '*/');
|
||||||
$char = $token['char'];
|
if ($commentEnd !== FALSE)
|
||||||
$charStart = strpos($this->render, $char, $offset) - 2;
|
|
||||||
$inComment = FALSE;
|
|
||||||
array_replace_range($this->hl, $charStart, 2, Highlight::ML_COMMENT);
|
|
||||||
$offset += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (substr($this->render, $offset, 2) === '*/')
|
|
||||||
{
|
{
|
||||||
$inComment = FALSE;
|
$inComment = FALSE;
|
||||||
array_replace_range($this->hl, $offset, 2, Highlight::ML_COMMENT);
|
array_replace_range($this->hl, 0, $commentEnd, Highlight::ML_COMMENT);
|
||||||
$offset += 2;
|
$offset = $commentEnd + 2;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Otherwise, just set the whole row
|
||||||
|
$this->hl = array_fill(0, $this->rsize, Highlight::ML_COMMENT);
|
||||||
$this->hl[$offset] = Highlight::ML_COMMENT;
|
$this->hl[$offset] = Highlight::ML_COMMENT;
|
||||||
$offset++;
|
break;
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$char = $token['char'];
|
$char = $token['char'];
|
||||||
@ -526,31 +523,26 @@ class Row {
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$charEnd = $charStart + $charLen;
|
||||||
// Probably not great to create a closure in a loop like this, but
|
|
||||||
// this halves the boilerplate for each type of syntax
|
|
||||||
$highlightRange = function (int $hl) use ($charLen, $charStart, &$offset) {
|
|
||||||
array_replace_range($this->hl, $charStart, $charLen, $hl);
|
|
||||||
|
|
||||||
// Update the offset to the end of the current token
|
|
||||||
$offset = $charStart + $charLen;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Start of multiline comment/single line comment
|
// Start of multiline comment/single line comment
|
||||||
if (in_array($token['type'], [T_DOC_COMMENT, T_COMMENT], TRUE))
|
if (in_array($token['type'], [T_DOC_COMMENT, T_COMMENT], TRUE))
|
||||||
{
|
{
|
||||||
// Single line comments
|
// Single line comments
|
||||||
if (strpos($token['char'], '//') !== FALSE)
|
if (strpos($char, '//') !== FALSE)
|
||||||
{
|
{
|
||||||
$highlightRange(Highlight::COMMENT);
|
array_replace_range($this->hl, $charStart, $charLen, Highlight::COMMENT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start of multi-line comment
|
// Start of multi-line comment
|
||||||
$start = strpos($this->render, '/*', $offset);
|
$start = strpos($this->render, '/*', $offset);
|
||||||
$inComment = strpos($this->render, '*/', $offset) === FALSE;
|
if ($start !== FALSE)
|
||||||
array_replace_range($this->hl, $start, strlen($char) - $offset, Highlight::ML_COMMENT);
|
{
|
||||||
$offset = $start + strlen($char) - $offset;
|
$inComment = strpos($this->render, '*/', $offset) === FALSE;
|
||||||
|
array_replace_range($this->hl, $start, $charLen - $offset, Highlight::ML_COMMENT);
|
||||||
|
$offset = $start + $charLen - $offset;
|
||||||
|
}
|
||||||
|
|
||||||
if ($inComment)
|
if ($inComment)
|
||||||
{
|
{
|
||||||
@ -564,7 +556,8 @@ class Row {
|
|||||||
if (array_key_exists($token['type'], $this->phpTokenHighlightMap))
|
if (array_key_exists($token['type'], $this->phpTokenHighlightMap))
|
||||||
{
|
{
|
||||||
$hl = $this->phpTokenHighlightMap[$token['type']];
|
$hl = $this->phpTokenHighlightMap[$token['type']];
|
||||||
$highlightRange($hl);
|
array_replace_range($this->hl, $charStart, $charLen, $hl);
|
||||||
|
$offset = $charEnd;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -573,18 +566,19 @@ class Row {
|
|||||||
{
|
{
|
||||||
if (in_array($token['char'], $this->parent->syntax->keywords2, TRUE))
|
if (in_array($token['char'], $this->parent->syntax->keywords2, TRUE))
|
||||||
{
|
{
|
||||||
$highlightRange(Highlight::KEYWORD2);
|
array_replace_range($this->hl, $charStart, $charLen, Highlight::KEYWORD2);
|
||||||
|
$offset = $charEnd;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Highlight raw characters
|
// Highlight raw characters
|
||||||
if (($token['typeName'] === 'RAW') && array_key_exists(trim($token['char']), $this->phpCharacterHighlightMap))
|
if (($token['typeName'] === 'RAW') && array_key_exists(trim($token['char']), $this->phpCharacterHighlightMap))
|
||||||
{
|
{
|
||||||
$hl = $this->phpCharacterHighlightMap[trim($token['char'])];
|
$hl = $this->phpCharacterHighlightMap[trim($token['char'])];
|
||||||
$highlightRange($hl);
|
array_replace_range($this->hl, $charStart, $charLen, $hl);
|
||||||
|
$offset = $charEnd;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
10
src/constants.php
Normal file
10
src/constants.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Kilo;
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
// ! App Constants
|
||||||
|
// -----------------------------------------------------------------------------
|
||||||
|
define('KILO_VERSION', '0.1.0');
|
||||||
|
define('KILO_TAB_STOP', 4);
|
||||||
|
define('KILO_QUIT_TIMES', 3);
|
@ -4,6 +4,8 @@ namespace Kilo;
|
|||||||
|
|
||||||
use FFI;
|
use FFI;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/constants.php';
|
||||||
|
|
||||||
/** @var FFI\CData $original_termios */
|
/** @var FFI\CData $original_termios */
|
||||||
$original_termios = get_ffi()->new('struct termios');
|
$original_termios = get_ffi()->new('struct termios');
|
||||||
|
|
||||||
|
5
test.php
5
test.php
@ -19,7 +19,7 @@ abstract class Foo implements Ifoo {
|
|||||||
* Docblock comment
|
* Docblock comment
|
||||||
*/
|
*/
|
||||||
class FooBar extends Foo implements Ifoo {
|
class FooBar extends Foo implements Ifoo {
|
||||||
public function bar(int $a, float $b, array $c, callable $d): string
|
public function bar(int $a, float $b, array $c, callable $d, string $e = 'default'): string
|
||||||
{
|
{
|
||||||
$cstr = print_r($c, TRUE);
|
$cstr = print_r($c, TRUE);
|
||||||
$d();
|
$d();
|
||||||
@ -48,6 +48,7 @@ $foobar = new FooBar();
|
|||||||
|
|
||||||
$x = 3;
|
$x = 3;
|
||||||
|
|
||||||
|
# Perl-style comment
|
||||||
$y = [
|
$y = [
|
||||||
1,
|
1,
|
||||||
2,
|
2,
|
||||||
@ -56,7 +57,7 @@ $y = [
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Heredoc
|
Heredoc
|
||||||
*/
|
*/$z = $x + $y;
|
||||||
$sql = <<<SQL
|
$sql = <<<SQL
|
||||||
SELECT * FROM "foo" WHERE "bar"='baz' AND id={$x};
|
SELECT * FROM "foo" WHERE "bar"='baz' AND id={$x};
|
||||||
SQL;
|
SQL;
|
||||||
|
Loading…
Reference in New Issue
Block a user