Ugly progress commit
This commit is contained in:
parent
0877bcd6dd
commit
da2bec354a
108
src/Row.php
108
src/Row.php
@ -35,8 +35,9 @@ class Row {
|
||||
T_DNUMBER => Highlight::NUMBER,
|
||||
T_LNUMBER => Highlight::NUMBER,
|
||||
|
||||
// Simple string literals
|
||||
// String literals
|
||||
T_CONSTANT_ENCAPSED_STRING => Highlight::STRING,
|
||||
T_ENCAPSED_AND_WHITESPACE => Highlight::STRING,
|
||||
|
||||
// Simple variables
|
||||
T_VARIABLE => Highlight::VARIABLE,
|
||||
@ -133,6 +134,15 @@ class Row {
|
||||
|
||||
// Not string literals, but identifiers, keywords, etc.
|
||||
// T_STRING => Highlight::KEYWORD2,
|
||||
|
||||
// Type casts
|
||||
T_ARRAY_CAST => Highlight::KEYWORD2,
|
||||
T_BOOL_CAST => Highlight::KEYWORD2,
|
||||
T_DOUBLE_CAST => Highlight::KEYWORD2,
|
||||
T_INT_CAST => Highlight::KEYWORD2,
|
||||
T_OBJECT_CAST => Highlight::KEYWORD2,
|
||||
T_STRING_CAST => Highlight::KEYWORD2,
|
||||
T_UNSET_CAST => Highlight::KEYWORD2,
|
||||
];
|
||||
|
||||
private array $phpCharacterHighlightMap = [
|
||||
@ -445,10 +455,6 @@ class Row {
|
||||
}
|
||||
|
||||
$tokens = $this->parent->syntax->tokens[$rowNum];
|
||||
if (empty($tokens))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$inComment = ($this->idx > 0 && $this->parent->rows[$this->idx - 1]->hlOpenComment);
|
||||
|
||||
@ -456,6 +462,28 @@ class Row {
|
||||
// multiples of the same tokens can be effectively matched
|
||||
$offset = 0;
|
||||
|
||||
// There will be no tokens if a line is empty, or if in a multi-line comment
|
||||
if (empty($tokens))
|
||||
{
|
||||
if ($inComment && $this->rsize > 0)
|
||||
{
|
||||
while ($offset < $this->rsize)
|
||||
{
|
||||
if (substr($this->render, $offset, 2) === '*/')
|
||||
{
|
||||
array_replace_range($this->hl, $offset, 2, Highlight::ML_COMMENT);
|
||||
break;
|
||||
}
|
||||
|
||||
$this->hl[$offset] = Highlight::ML_COMMENT;
|
||||
$offset++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($tokens as $token)
|
||||
{
|
||||
if ($offset >= $this->rsize)
|
||||
@ -463,9 +491,33 @@ class Row {
|
||||
break;
|
||||
}
|
||||
|
||||
// A multi-line comment can end in the middle of a line...
|
||||
while ($inComment)
|
||||
{
|
||||
if ($token['type'] === T_WHITESPACE)
|
||||
{
|
||||
$char = $token['char'];
|
||||
$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;
|
||||
array_replace_range($this->hl, $offset, 2, Highlight::ML_COMMENT);
|
||||
$offset += 2;
|
||||
}
|
||||
|
||||
$this->hl[$offset] = Highlight::ML_COMMENT;
|
||||
$offset++;
|
||||
continue;
|
||||
}
|
||||
|
||||
$char = $token['char'];
|
||||
$charLen = strlen($char);
|
||||
if ($charLen === 0)
|
||||
if ($charLen === 0 || $offset >= $this->rsize)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@ -474,24 +526,9 @@ class Row {
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$charEnd = $charStart + $charLen;
|
||||
|
||||
// Comments
|
||||
if ($inComment)
|
||||
{
|
||||
if (substr($this->render, $offset, 2) === '*/')
|
||||
{
|
||||
$inComment = FALSE;
|
||||
array_replace_range($this->hl, $offset, 2, Highlight::ML_COMMENT);
|
||||
$offset += 2;
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->hl[$offset] = Highlight::ML_COMMENT;
|
||||
$offset++;
|
||||
continue;
|
||||
}
|
||||
// Start of multiline comment/single line comment
|
||||
if (in_array($token['type'], [T_DOC_COMMENT, T_COMMENT], TRUE))
|
||||
{
|
||||
// Single line comments
|
||||
@ -511,12 +548,12 @@ class Row {
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Highlight specific tokens
|
||||
if (($token['typeName'] !== 'RAW') && array_key_exists($token['type'], $this->phpTokenHighlightMap))
|
||||
if ($token['typeName'] !== 'RAW')
|
||||
{
|
||||
if (array_key_exists($token['type'], $this->phpTokenHighlightMap))
|
||||
{
|
||||
$hl = $this->phpTokenHighlightMap[$token['type']];
|
||||
array_replace_range($this->hl, $charStart, $charLen, $hl);
|
||||
@ -524,16 +561,27 @@ class Row {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Highlight raw characters
|
||||
if (($token['typeName'] === 'RAW') && array_key_exists($token['char'], $this->phpCharacterHighlightMap))
|
||||
// Types/identifiers/keywords that don't have their own token
|
||||
if ($token['type'] === T_STRING)
|
||||
{
|
||||
$hl = $this->phpCharacterHighlightMap[$token['char']];
|
||||
if (in_array($token['char'], $this->parent->syntax->keywords2, TRUE))
|
||||
{
|
||||
array_replace_range($this->hl, $charStart, $charLen, Highlight::KEYWORD2);
|
||||
$offset = $charEnd;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Highlight raw characters
|
||||
if (($token['typeName'] === 'RAW') && array_key_exists(trim($token['char']), $this->phpCharacterHighlightMap))
|
||||
{
|
||||
$hl = $this->phpCharacterHighlightMap[trim($token['char'])];
|
||||
array_replace_range($this->hl, $charStart, $charLen, $hl);
|
||||
$offset = $charEnd;
|
||||
continue;
|
||||
}
|
||||
|
||||
$offset++;
|
||||
}
|
||||
|
||||
$changed = $this->hlOpenComment !== $inComment;
|
||||
|
Loading…
Reference in New Issue
Block a user