From fa96e91b3063183c020f9f13c81c85f5aba2bf87 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Tue, 29 Oct 2019 17:24:04 -0400 Subject: [PATCH] More PHP highlighting --- src/Row.php | 54 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/src/Row.php b/src/Row.php index 5fac9cf..baf96c6 100644 --- a/src/Row.php +++ b/src/Row.php @@ -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; - } }