More PHP highlighting

This commit is contained in:
Timothy Warren 2019-10-29 17:24:04 -04:00
parent 346ef67a08
commit fa96e91b30
1 changed files with 41 additions and 13 deletions

View File

@ -303,13 +303,38 @@ class Row {
$charStart = strpos($this->render, $char, $offset);
$charEnd = $charStart + $charLen;
if ($token['typeName'] === 'RAW')
{
switch($token['char'])
{
case '^':
case '%':
case '+':
case '-':
case '*':
case '/':
case '.':
case '|':
case '~':
case '>':
case '<':
case '=':
case '!':
array_replace_range($this->hl, $charStart, $charLen, Highlight::OPERATOR);
$offset = $charEnd;
continue 2;
}
}
switch ($token['type'])
{
// Number literals
case T_LNUMBER:
array_replace_range($this->hl, $charStart, $charLen, Highlight::NUMBER);
$offset = $charEnd;
continue 2;
// Simple string literals
case T_CONSTANT_ENCAPSED_STRING:
array_replace_range($this->hl, $charStart, $charLen, Highlight::STRING);
$offset = $charEnd;
@ -321,6 +346,7 @@ class Row {
case T_BOOLEAN_OR:
case T_COALESCE:
case T_CONCAT_EQUAL:
case T_DEC:
case T_DIV_EQUAL:
case T_DOUBLE_ARROW:
case T_DOUBLE_COLON:
@ -339,6 +365,7 @@ class Row {
case T_MINUS_EQUAL:
case T_MOD_EQUAL:
case T_MUL_EQUAL:
case T_NS_SEPARATOR:
case T_OBJECT_OPERATOR:
case T_OR_EQUAL:
case T_PAAMAYIM_NEKUDOTAYIM:
@ -354,20 +381,34 @@ class Row {
$offset = $charEnd;
continue 2;
// Simple variables
case T_VARIABLE:
array_replace_range($this->hl, $charStart, $charLen, Highlight::VARIABLE);
$offset = $charEnd;
continue 2;
case T_COMMENT:
case T_DOC_COMMENT:
// TODO
break;
// Not string literals, but identifiers, keywords, etc.
case T_STRING:
if (in_array($char, $this->parent->syntax->keywords2, TRUE))
{
array_replace_range($this->hl, $charStart, $charLen, Highlight::KEYWORD2);
$offset = $charEnd;
continue 2;
}
break;
// Keywords1
case T_ABSTRACT:
case T_AS:
case T_BREAK:
case T_CASE:
case T_CATCH:
case T_CLASS:
case T_DO:
array_replace_range($this->hl, $charStart, $charLen, Highlight::KEYWORD1);
// $keyword = $this->getKeywordFromToken($token['type']);
@ -379,17 +420,4 @@ class Row {
}
}
}
private function getKeywordFromToken(int $token): ?string
{
$map = [
T_ABSTRACT => 'abstract',
T_AS => 'as',
T_BREAK => 'break',
T_CASE => 'case',
T_DO => 'do',
];
return $map[$token] ?? NULL;
}
}