2019-10-10 12:28:46 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
|
2019-11-08 16:27:08 -05:00
|
|
|
namespace Aviat\Kilo;
|
2019-10-10 12:28:46 -04:00
|
|
|
|
|
|
|
use FFI;
|
|
|
|
|
2019-11-08 16:27:08 -05:00
|
|
|
use Aviat\Kilo\Enum\{
|
|
|
|
C,
|
|
|
|
Color,
|
|
|
|
Highlight,
|
|
|
|
};
|
2019-10-10 12:28:46 -04:00
|
|
|
|
2019-10-24 10:58:38 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
2019-11-08 16:27:08 -05:00
|
|
|
// ! Terminal size
|
2019-10-24 10:58:38 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @TODO fix
|
|
|
|
*/
|
|
|
|
function get_cursor_position()
|
2019-10-10 15:49:01 -04:00
|
|
|
{
|
2019-10-24 10:58:38 -04:00
|
|
|
write_stdout("\x1b[999C\x1b[999B");
|
|
|
|
write_stdout("\x1b[6n");
|
2019-10-10 12:28:46 -04:00
|
|
|
|
2019-10-24 10:58:38 -04:00
|
|
|
$rows = 0;
|
|
|
|
$cols = 0;
|
2019-10-11 16:32:47 -04:00
|
|
|
|
2019-10-24 10:58:38 -04:00
|
|
|
$buffer = read_stdout();
|
2019-10-14 16:21:41 -04:00
|
|
|
|
2019-10-24 10:58:38 -04:00
|
|
|
$res = sscanf($buffer, '\x1b[%d;%dR', $rows, $cols);
|
2019-10-14 16:21:41 -04:00
|
|
|
|
2019-10-24 10:58:38 -04:00
|
|
|
if ($res === -1 || $buffer[0] !== '\x1b' || $buffer[1] !== '[')
|
|
|
|
{
|
|
|
|
die('Failed to get screen size');
|
|
|
|
}
|
|
|
|
|
|
|
|
return [$rows, $cols];
|
2019-10-14 16:21:41 -04:00
|
|
|
}
|
|
|
|
|
2019-10-24 10:58:38 -04:00
|
|
|
function get_window_size()
|
2019-10-14 16:21:41 -04:00
|
|
|
{
|
2019-10-24 12:00:14 -04:00
|
|
|
$ffi = get_ffi();
|
2019-10-14 16:21:41 -04:00
|
|
|
|
2019-10-24 10:58:38 -04:00
|
|
|
$ws = $ffi->new('struct winsize');
|
2019-10-24 12:00:14 -04:00
|
|
|
$res = $ffi->ioctl(C::STDOUT_FILENO, C::TIOCGWINSZ, FFI::addr($ws));
|
2019-10-14 16:21:41 -04:00
|
|
|
|
2019-10-24 10:58:38 -04:00
|
|
|
if ($res === -1 || $ws->ws_col === 0)
|
|
|
|
{
|
|
|
|
return get_cursor_position();
|
|
|
|
}
|
|
|
|
|
|
|
|
return [$ws->ws_row, $ws->ws_col];
|
2019-10-14 16:21:41 -04:00
|
|
|
}
|
|
|
|
|
2019-10-24 10:58:38 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// ! C function/macro equivalents
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-10-22 16:16:28 -04:00
|
|
|
/**
|
|
|
|
* Do bit twiddling to convert a letter into
|
2019-10-24 10:58:38 -04:00
|
|
|
* its Ctrl-letter equivalent ordinal ascii value
|
2019-10-22 16:16:28 -04:00
|
|
|
*
|
|
|
|
* @param string $char
|
|
|
|
* @return int
|
|
|
|
*/
|
2019-10-11 16:32:47 -04:00
|
|
|
function ctrl_key(string $char): int
|
|
|
|
{
|
2019-10-24 10:58:38 -04:00
|
|
|
if ( ! is_ascii($char))
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-10-24 12:00:14 -04:00
|
|
|
// b1,100,001 (a) & b0,011,111 (0x1f) = b0,000,001 (SOH)
|
|
|
|
// b1,100,010 (b) & b0,011,111 (0x1f) = b0,000,010 (STX)
|
|
|
|
// ...and so on
|
2019-10-11 16:32:47 -04:00
|
|
|
return ord($char) & 0x1f;
|
2019-10-22 17:50:35 -04:00
|
|
|
}
|
2019-10-23 13:34:40 -04:00
|
|
|
|
2019-10-24 12:00:14 -04:00
|
|
|
/**
|
|
|
|
* Does the one-character string contain an ascii ordinal value?
|
|
|
|
*
|
|
|
|
* @param string $single_char
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-10-24 10:58:38 -04:00
|
|
|
function is_ascii(string $single_char): bool
|
2019-10-23 13:34:40 -04:00
|
|
|
{
|
|
|
|
if (strlen($single_char) > 1)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ord($single_char) < 0x80;
|
|
|
|
}
|
|
|
|
|
2019-10-24 12:00:14 -04:00
|
|
|
/**
|
|
|
|
* Does the one-character string contain an ascii control character?
|
|
|
|
*
|
|
|
|
* @param string $char
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-10-24 10:58:38 -04:00
|
|
|
function is_cntrl(string $char): bool
|
2019-10-23 13:34:40 -04:00
|
|
|
{
|
|
|
|
$c = ord($char);
|
2019-10-24 10:58:38 -04:00
|
|
|
return is_ascii($char) && ( $c < 0x20 || $c === 0x7f );
|
2019-10-23 13:34:40 -04:00
|
|
|
}
|
|
|
|
|
2019-10-24 12:00:14 -04:00
|
|
|
/**
|
|
|
|
* Does the one-character string contain an ascii number?
|
|
|
|
*
|
|
|
|
* @param string $char
|
|
|
|
* @return bool
|
|
|
|
*/
|
2019-10-24 10:58:38 -04:00
|
|
|
function is_digit(string $char): bool
|
2019-10-23 13:34:40 -04:00
|
|
|
{
|
|
|
|
$c = ord($char);
|
2019-10-24 10:58:38 -04:00
|
|
|
return is_ascii($char) && ( $c > 0x2f && $c < 0x3a );
|
|
|
|
}
|
|
|
|
|
2019-10-24 16:22:52 -04:00
|
|
|
/**
|
|
|
|
* Does the one-character string contain ascii whitespace?
|
|
|
|
*
|
|
|
|
* @param string $char
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function is_space(string $char): bool
|
|
|
|
{
|
|
|
|
$ws = [' ', "\t", "\n", "\r", "\xa", "\xb", "\xc"];
|
|
|
|
return is_ascii($char) && in_array($char, $ws, TRUE);
|
|
|
|
}
|
|
|
|
|
2019-10-24 10:58:38 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// ! Helper functions
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2019-10-24 12:00:14 -04:00
|
|
|
/**
|
|
|
|
* A 'singleton' function to replace a global variable
|
|
|
|
*
|
|
|
|
* @return FFI
|
|
|
|
*/
|
|
|
|
function get_ffi(): FFI
|
|
|
|
{
|
|
|
|
static $ffi;
|
|
|
|
|
|
|
|
if ($ffi === NULL)
|
|
|
|
{
|
|
|
|
$ffi = FFI::load(__DIR__ . '/ffi.h');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $ffi;
|
|
|
|
}
|
|
|
|
|
2019-10-24 16:22:52 -04:00
|
|
|
/**
|
|
|
|
* Does the one-character string contain a character that separates tokens?
|
|
|
|
*
|
|
|
|
* @param string $char
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
function is_separator(string $char): bool
|
|
|
|
{
|
|
|
|
if ( ! is_ascii($char))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// `strpos` is used instead of `strchr`/`strstr` as we don't care about the actual match
|
|
|
|
// while `strchr` would match the C version, it also returns the match
|
|
|
|
$isSep = (strpos(',.()+-/*=~%<>[];', $char) !== FALSE);
|
|
|
|
|
|
|
|
return is_space($char) || $char === "\0" || $isSep;
|
|
|
|
}
|
|
|
|
|
2019-10-24 12:00:14 -04:00
|
|
|
/**
|
|
|
|
* Pull input from the stdin stream.
|
|
|
|
*
|
|
|
|
* @param int $len
|
|
|
|
* @return string
|
|
|
|
*/
|
2019-10-24 10:58:38 -04:00
|
|
|
function read_stdin(int $len = 128): string
|
|
|
|
{
|
|
|
|
$handle = fopen('php://stdin', 'rb');
|
|
|
|
$input = fread($handle, $len);
|
|
|
|
fclose($handle);
|
|
|
|
|
|
|
|
return $input;
|
|
|
|
}
|
|
|
|
|
2019-10-24 12:00:14 -04:00
|
|
|
/**
|
|
|
|
* Write to the stdout stream
|
|
|
|
*
|
|
|
|
* @param string $str
|
|
|
|
* @param int|NULL $len
|
|
|
|
* @return int
|
|
|
|
*/
|
2019-10-24 10:58:38 -04:00
|
|
|
function write_stdout(string $str, int $len = NULL): int
|
|
|
|
{
|
|
|
|
$handle = fopen('php://stdout', 'ab');
|
|
|
|
$res = (is_int($len))
|
|
|
|
? fwrite($handle, $str, $len)
|
|
|
|
: fwrite($handle, $str);
|
|
|
|
|
|
|
|
fclose($handle);
|
|
|
|
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
|
|
|
function read_stdout(int $len = 128): string
|
|
|
|
{
|
|
|
|
$handle = fopen('php://stdout', 'rb');
|
|
|
|
$input = fread($handle, $len);
|
|
|
|
|
|
|
|
$input = rtrim($input);
|
|
|
|
fclose($handle);
|
|
|
|
|
|
|
|
return $input;
|
2019-10-23 13:34:40 -04:00
|
|
|
}
|
2019-10-24 12:00:14 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces a slice of an array with the same value
|
|
|
|
*
|
|
|
|
* @param array $array The array to update
|
|
|
|
* @param int $offset The index of the first location to update
|
|
|
|
* @param int $length The number of indices to update
|
|
|
|
* @param mixed $value The value to replace in the range
|
|
|
|
*/
|
|
|
|
function array_replace_range(array &$array, int $offset, int $length, $value):void
|
|
|
|
{
|
2019-10-30 14:21:10 -04:00
|
|
|
if ($length === 1)
|
|
|
|
{
|
|
|
|
$array[$offset] = $value;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-10-25 15:35:20 -04:00
|
|
|
$replacement = array_fill(0, $length, $value);
|
|
|
|
array_splice($array, $offset, $length, $replacement);
|
|
|
|
|
|
|
|
/* $end = $offset + $length;
|
2019-10-24 12:00:14 -04:00
|
|
|
for ($i = $offset; $i < $end; $i++)
|
|
|
|
{
|
|
|
|
$array[$i] = $value;
|
2019-10-25 15:35:20 -04:00
|
|
|
} */
|
2019-10-24 12:00:14 -04:00
|
|
|
}
|
2019-10-24 16:57:27 -04:00
|
|
|
|
2019-10-29 17:02:03 -04:00
|
|
|
/**
|
|
|
|
* Get the ASCII color escape number for the specified syntax type
|
|
|
|
*
|
|
|
|
* @param int $hl
|
|
|
|
* @return int
|
|
|
|
*/
|
2019-10-24 16:57:27 -04:00
|
|
|
function syntax_to_color(int $hl): int
|
|
|
|
{
|
2019-10-25 15:35:20 -04:00
|
|
|
$map = [
|
2019-11-06 16:11:38 -05:00
|
|
|
Highlight::COMMENT => Color::FG_CYAN,
|
|
|
|
Highlight::ML_COMMENT => Color::FG_BRIGHT_BLACK,
|
|
|
|
Highlight::KEYWORD1 => Color::FG_YELLOW,
|
|
|
|
Highlight::KEYWORD2 => Color::FG_GREEN,
|
|
|
|
Highlight::STRING => Color::FG_MAGENTA,
|
|
|
|
Highlight::NUMBER => Color::FG_RED,
|
|
|
|
Highlight::OPERATOR => Color::FG_BRIGHT_GREEN,
|
|
|
|
Highlight::VARIABLE => Color::FG_BRIGHT_CYAN,
|
|
|
|
Highlight::DELIMITER => Color::FG_BLUE,
|
|
|
|
Highlight::INVALID => Color::BG_BRIGHT_RED,
|
|
|
|
Highlight::MATCH => Color::INVERT,
|
2019-10-25 15:35:20 -04:00
|
|
|
];
|
|
|
|
|
|
|
|
return (array_key_exists($hl, $map))
|
|
|
|
? $map[$hl]
|
2019-11-06 16:11:38 -05:00
|
|
|
: Color::FG_WHITE;
|
2019-10-24 16:57:27 -04:00
|
|
|
}
|
2019-10-29 17:02:03 -04:00
|
|
|
|
2019-11-08 16:27:08 -05:00
|
|
|
/**
|
|
|
|
* Replace tabs with the specified number of spaces.
|
|
|
|
*
|
|
|
|
* @param string $str
|
|
|
|
* @param int? $number
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
function tabs_to_spaces(string $str, ?int $number = KILO_TAB_STOP): string
|
2019-11-08 13:28:24 -05:00
|
|
|
{
|
2019-11-08 16:27:08 -05:00
|
|
|
return str_replace("\t", str_repeat(' ', $number), $str);
|
2019-11-08 13:28:24 -05:00
|
|
|
}
|
|
|
|
|
2019-10-29 17:02:03 -04:00
|
|
|
/**
|
|
|
|
* Use 'token_get_all' to get the tokens for a file,
|
|
|
|
* organized by row number
|
|
|
|
*
|
2019-10-30 14:21:10 -04:00
|
|
|
* @param string $code
|
2019-10-29 17:02:03 -04:00
|
|
|
* @return array
|
|
|
|
*/
|
2019-10-30 14:21:10 -04:00
|
|
|
function get_php_tokens(string $code): array
|
2019-10-29 17:02:03 -04:00
|
|
|
{
|
2019-11-08 13:28:24 -05:00
|
|
|
$rawTokens = token_get_all($code);
|
2019-10-29 17:02:03 -04:00
|
|
|
$tokens = [];
|
|
|
|
$lineNum = 1;
|
|
|
|
$line = [];
|
2019-11-08 13:28:24 -05:00
|
|
|
foreach($rawTokens as $t)
|
2019-10-29 17:02:03 -04:00
|
|
|
{
|
2019-11-13 16:26:19 -05:00
|
|
|
if (is_array($t))
|
2019-10-29 17:02:03 -04:00
|
|
|
{
|
2019-11-13 16:26:19 -05:00
|
|
|
[$type, $rawChar, $currentLine] = $t;
|
|
|
|
$char = tabs_to_spaces($rawChar);
|
|
|
|
|
|
|
|
$current = [
|
|
|
|
'type' => $type,
|
|
|
|
'typeName' => token_name($type),
|
|
|
|
'char' => $char,
|
|
|
|
'line' => $currentLine,
|
2019-10-29 17:02:03 -04:00
|
|
|
];
|
2019-11-05 16:56:18 -05:00
|
|
|
|
2019-11-13 16:26:19 -05:00
|
|
|
if ($char === "\n")
|
|
|
|
{
|
|
|
|
$line[] = $current;
|
|
|
|
$tokens[$lineNum] = $line;
|
|
|
|
$lineNum++;
|
|
|
|
$line = [];
|
|
|
|
}
|
2019-11-08 13:28:24 -05:00
|
|
|
|
2019-11-13 16:26:19 -05:00
|
|
|
// Only return the first line of a multi-line token for this line array
|
|
|
|
if ($char !== "\n" && strpos($char, "\n") !== FALSE)
|
2019-10-30 16:36:17 -04:00
|
|
|
{
|
2019-11-13 16:26:19 -05:00
|
|
|
$chars = explode("\n", $char);
|
|
|
|
$current['original'] = [
|
|
|
|
'string' => $char,
|
|
|
|
'lines' => $chars,
|
|
|
|
];
|
|
|
|
$current['char'] = array_shift($chars);
|
2019-11-08 13:28:24 -05:00
|
|
|
|
2019-11-13 16:26:19 -05:00
|
|
|
// Add new lines for additional newline characters
|
|
|
|
$nextLine = $currentLine;
|
|
|
|
foreach ($chars as $char)
|
2019-10-31 19:05:39 -04:00
|
|
|
{
|
2019-11-13 16:26:19 -05:00
|
|
|
$nextLine++;
|
|
|
|
|
|
|
|
if ( ! array_key_exists($nextLine, $tokens))
|
|
|
|
{
|
|
|
|
$tokens[$nextLine] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$tokens[$nextLine][] = [
|
|
|
|
'type' => -1,
|
|
|
|
'typeName' => 'RAW',
|
|
|
|
'char' => $char,
|
|
|
|
];
|
2019-10-31 19:05:39 -04:00
|
|
|
}
|
2019-11-13 16:26:19 -05:00
|
|
|
}
|
2019-11-08 13:28:24 -05:00
|
|
|
|
2019-11-13 16:26:19 -05:00
|
|
|
if ($currentLine !== $lineNum)
|
|
|
|
{
|
|
|
|
$existing = $tokens[$lineNum] ?? [];
|
|
|
|
$tokens[$lineNum] = array_merge($existing, $line);
|
|
|
|
|
|
|
|
$lineNum = $currentLine;
|
|
|
|
$line = [];
|
2019-10-30 16:36:17 -04:00
|
|
|
}
|
2019-11-08 13:28:24 -05:00
|
|
|
|
2019-11-13 16:26:19 -05:00
|
|
|
$line[] = $current;
|
|
|
|
}
|
|
|
|
else if (is_string($t))
|
2019-11-08 13:28:24 -05:00
|
|
|
{
|
2019-11-13 16:26:19 -05:00
|
|
|
// Simple characters, usually delimiters or single character operators
|
|
|
|
$line[] = [
|
|
|
|
'type' => -1,
|
|
|
|
'typeName' => 'RAW',
|
|
|
|
'char' => tabs_to_spaces($t),
|
|
|
|
];
|
2019-10-29 17:02:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 13:28:24 -05:00
|
|
|
$tokens[$lineNum] = array_merge($tokens[$lineNum] ?? [], $line);
|
|
|
|
|
|
|
|
ksort($tokens);
|
2019-10-30 14:21:10 -04:00
|
|
|
|
2019-10-29 17:02:03 -04:00
|
|
|
return $tokens;
|
|
|
|
}
|
2019-11-08 16:27:08 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate/Get the syntax highlighting objects
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2019-11-08 21:48:46 -05:00
|
|
|
function get_file_syntax_map(): array
|
2019-11-08 16:27:08 -05:00
|
|
|
{
|
|
|
|
static $db = [];
|
|
|
|
|
|
|
|
if (count($db) === 0)
|
|
|
|
{
|
|
|
|
$db = [
|
|
|
|
Syntax::new(
|
|
|
|
'C',
|
|
|
|
['.c', '.h', '.cpp'],
|
|
|
|
[
|
|
|
|
'continue', 'typedef', 'switch', 'return', 'static', 'while', 'break', 'struct',
|
|
|
|
'union', 'class', 'else', 'enum', 'for', 'case', 'if',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'#include', 'unsigned', '#define', '#ifndef', 'double', 'signed', '#endif',
|
|
|
|
'#ifdef', 'float', '#error', '#undef', 'long', 'char', 'int', 'void', '#if',
|
|
|
|
],
|
|
|
|
'//',
|
|
|
|
'/*',
|
|
|
|
'*/',
|
|
|
|
Syntax::HIGHLIGHT_NUMBERS | Syntax::HIGHLIGHT_STRINGS,
|
|
|
|
),
|
|
|
|
Syntax::new(
|
|
|
|
'CSS',
|
|
|
|
['.css', '.less', '.sass', 'scss'],
|
|
|
|
[],
|
|
|
|
[],
|
|
|
|
'',
|
|
|
|
'/*',
|
|
|
|
'*/',
|
|
|
|
Syntax::HIGHLIGHT_NUMBERS | Syntax::HIGHLIGHT_STRINGS,
|
|
|
|
),
|
|
|
|
Syntax::new(
|
|
|
|
'JavaScript',
|
|
|
|
['.js', '.jsx', '.ts', '.tsx', '.jsm', '.mjs', '.es'],
|
|
|
|
[
|
|
|
|
'instanceof',
|
|
|
|
'continue',
|
|
|
|
'debugger',
|
|
|
|
'function',
|
|
|
|
'default',
|
|
|
|
'extends',
|
|
|
|
'finally',
|
|
|
|
'delete',
|
|
|
|
'export',
|
|
|
|
'import',
|
|
|
|
'return',
|
|
|
|
'switch',
|
|
|
|
'typeof',
|
|
|
|
'break',
|
|
|
|
'catch',
|
|
|
|
'class',
|
|
|
|
'const',
|
|
|
|
'super',
|
|
|
|
'throw',
|
|
|
|
'while',
|
|
|
|
'yield',
|
|
|
|
'case',
|
|
|
|
'else',
|
|
|
|
'this',
|
|
|
|
'void',
|
|
|
|
'with',
|
|
|
|
'from',
|
|
|
|
'for',
|
|
|
|
'new',
|
|
|
|
'try',
|
|
|
|
'var',
|
|
|
|
'do',
|
|
|
|
'if',
|
|
|
|
'in',
|
|
|
|
'as',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'=>', 'Number', 'String', 'Object', 'Math', 'JSON', 'Boolean',
|
|
|
|
],
|
|
|
|
'//',
|
|
|
|
'/*',
|
|
|
|
'*/',
|
|
|
|
Syntax::HIGHLIGHT_NUMBERS | Syntax::HIGHLIGHT_STRINGS,
|
|
|
|
),
|
|
|
|
Syntax::new(
|
|
|
|
'PHP',
|
|
|
|
['.php', 'kilo'],
|
|
|
|
[
|
|
|
|
'?php', '$this', '__halt_compiler', 'abstract', 'and', 'array', 'as', 'break',
|
|
|
|
'callable', 'case', 'catch', 'class', 'clone', 'const', 'continue', 'declare',
|
|
|
|
'default', 'die', 'do', 'echo', 'else', 'elseif', 'empty', 'enddeclare', 'endfor',
|
|
|
|
'endforeach', 'endif', 'endswitch', 'endwhile', 'eval', 'exit', 'extends',
|
|
|
|
'final', 'finally', 'for', 'foreach', 'function', 'global', 'goto', 'if', 'implements',
|
|
|
|
'include', 'include_once', 'instanceof', 'insteadof', 'interface', 'isset', 'list',
|
|
|
|
'namespace', 'new', 'or', 'print', 'private', 'protected', 'public', 'require', 'require_once',
|
|
|
|
'return', 'static', 'switch', 'throw', 'trait', 'try', 'unset', 'use', 'var', 'while', 'xor',
|
|
|
|
'yield', 'yield from', '__CLASS__', '__DIR__', '__FILE__', '__FUNCTION__', '__LINE__',
|
|
|
|
'__METHOD__', '__NAMESPACE__', '__TRAIT__',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'int', 'float', 'bool', 'string', 'true', 'TRUE', 'false', 'FALSE', 'null', 'NULL',
|
|
|
|
'void', 'iterable', 'object', 'strict_types'
|
|
|
|
],
|
|
|
|
'//',
|
|
|
|
'/*',
|
|
|
|
'*/',
|
|
|
|
Syntax::HIGHLIGHT_NUMBERS | Syntax::HIGHLIGHT_STRINGS,
|
|
|
|
),
|
|
|
|
Syntax::new(
|
|
|
|
'Rust',
|
|
|
|
['.rs'],
|
|
|
|
[
|
|
|
|
'continue', 'return', 'static', 'struct', 'unsafe', 'break', 'const', 'crate',
|
|
|
|
'extern', 'match', 'super', 'trait', 'where', 'else', 'enum', 'false', 'impl',
|
|
|
|
'loop', 'move', 'self', 'type', 'while', 'for', 'let', 'mod', 'pub', 'ref', 'true',
|
|
|
|
'use', 'mut', 'as', 'fn', 'if', 'in',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'DoubleEndedIterator',
|
|
|
|
'ExactSizeIterator',
|
|
|
|
'IntoIterator',
|
|
|
|
'PartialOrd',
|
|
|
|
'PartialEq',
|
|
|
|
'Iterator',
|
|
|
|
'ToString',
|
|
|
|
'Default',
|
|
|
|
'ToOwned',
|
|
|
|
'Extend',
|
|
|
|
'FnOnce',
|
|
|
|
'Option',
|
|
|
|
'String',
|
|
|
|
'AsMut',
|
|
|
|
'AsRef',
|
|
|
|
'Clone',
|
|
|
|
'Debug',
|
|
|
|
'FnMut',
|
|
|
|
'Sized',
|
|
|
|
'Unpin',
|
|
|
|
'array',
|
|
|
|
'isize',
|
|
|
|
'usize',
|
|
|
|
'&str',
|
|
|
|
'Copy',
|
|
|
|
'Drop',
|
|
|
|
'From',
|
|
|
|
'Into',
|
|
|
|
'None',
|
|
|
|
'Self',
|
|
|
|
'Send',
|
|
|
|
'Some',
|
|
|
|
'Sync',
|
|
|
|
'Sync',
|
|
|
|
'bool',
|
|
|
|
'char',
|
|
|
|
'i128',
|
|
|
|
'u128',
|
|
|
|
'Box',
|
|
|
|
'Err',
|
|
|
|
'Ord',
|
|
|
|
'Vec',
|
|
|
|
'dyn',
|
|
|
|
'f32',
|
|
|
|
'f64',
|
|
|
|
'i16',
|
|
|
|
'i32',
|
|
|
|
'i64',
|
|
|
|
'str',
|
|
|
|
'u16',
|
|
|
|
'u32',
|
|
|
|
'u64',
|
|
|
|
'Eq',
|
|
|
|
'Fn',
|
|
|
|
'Ok',
|
|
|
|
'i8',
|
|
|
|
'u8',
|
|
|
|
],
|
|
|
|
'//',
|
|
|
|
'/*',
|
|
|
|
'*/',
|
|
|
|
Syntax::HIGHLIGHT_NUMBERS | Syntax::HIGHLIGHT_STRINGS,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $db;
|
|
|
|
}
|