Skip to content

Commit

Permalink
Merge pull request #227 from calebdw/feat-highlights
Browse files Browse the repository at this point in the history
feat(highlights): add missing php keywords with tests
  • Loading branch information
calebdw authored Mar 5, 2024
2 parents 78a78df + ecba0c8 commit 365fd18
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 65 deletions.
113 changes: 95 additions & 18 deletions common/test/highlight/keywords.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
<?php
// <- tag

if ($a) {} elseif ($b) {} else {}
declare(strict_types=1);
// <- keyword

include "file.php";
// <- keyword
include_once "file.php";
// <- keyword

require "file.php";
// <- keyword
require_once "file.php";
// <- keyword

namespace A\B;
// <- keyword

if ($a) {} elseif ($b) {} else {}
// ^ keyword
// ^ keyword
if ($a and $b or $c xor $d) {}
// ^ keyword
// ^ keyword
// ^ keyword

for ($i = 0; $i < 1; $i++) {}
for ($i = 0; $i < 1; $i++) { continue; }
// <- keyword
// ^ keyword

while ($b) {}
// <- keyword
Expand All @@ -23,34 +43,91 @@
// <- keyword
// ^ keyword

try {} catch (Exception $e) {}
try {} catch (Exception $e) {} finally {}
// <- keyword
// ^ keyword
// ^ keyword

function a() {}
// <- keyword

class A {}
abstract class A
// <- keyword
// ^ keyword
{
private const BAR = 1;
// <- keyword
// ^ keyword
protected readonly static $a;
// <- keyword
// ^ keyword
// ^ keyword
final public $b;
// <- keyword
public function foo(): static {}
// <- keyword
// ^ keyword
}

class B extends A implements T
// ^ keyword
// ^ keyword
{
use T, U {
// <- keyword
U::small insteadof T;
// ^ keyword
}
public function foo(callable $call): self
{
$call instanceof Closure;
// ^ keyword
fn ($a, $b) => $a + $b;
// <- keyword
static $a;
// <- keyword
global $a;
// <- keyword
clone $call;
// <- keyword
match ($a) {
// <- keyword
default => "other",
// <- keyword
};

switch ($a) {
// <- keyword
case 'value':
// <- keyword
break;
// <- keyword
default:
// <- keyword
}

yield $a;
// <- keyword

return $a;
// <- keyword
}
}

throw new Exception("oh");
// <- keyword
// ^ keyword

function b(
int $a,
// <- type.builtin

string $b,
// <- type.builtin
interface T {}
// <- keyword

Person $e
// ^ type
): Dog {}
// ^ type
trait T { public function small(): void {} }
// <- keyword
trait U { public function small(): void {} }
// <- keyword

interface T {}
// ^ keyword
goto a;
// <- keyword

trait T {}
// ^ keyword
echo "a";
// <- keyword
18 changes: 18 additions & 0 deletions common/test/highlight/types.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
<?php


function b(
int $a,
// <- type.builtin

string $b,
// <- type.builtin

Person $e
// <- type
): Dog {}
// ^ type

function a(array $b, Something $c) {
// ^ type.builtin
// ^ type
echo (int) $foo;
// ^ type.builtin
}

class A {
public function foo(): self {}
// ^ type
private function baz(): static {}
}
110 changes: 63 additions & 47 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -75,50 +75,66 @@

; Keywords

"abstract" @keyword
"as" @keyword
"break" @keyword
"case" @keyword
"catch" @keyword
"class" @keyword
"const" @keyword
"continue" @keyword
"declare" @keyword
"default" @keyword
"do" @keyword
"echo" @keyword
"else" @keyword
"elseif" @keyword
"enddeclare" @keyword
"endforeach" @keyword
"endif" @keyword
"endswitch" @keyword
"endwhile" @keyword
"extends" @keyword
"final" @keyword
"finally" @keyword
"for" @keyword
"foreach" @keyword
"function" @keyword
"global" @keyword
"if" @keyword
"implements" @keyword
"include_once" @keyword
"include" @keyword
"insteadof" @keyword
"interface" @keyword
"namespace" @keyword
"new" @keyword
"private" @keyword
"protected" @keyword
"public" @keyword
"require_once" @keyword
"require" @keyword
"return" @keyword
"static" @keyword
"switch" @keyword
"throw" @keyword
"trait" @keyword
"try" @keyword
"use" @keyword
"while" @keyword
[
"abstract"
"and"
"as"
"break"
"case"
"catch"
"class"
"clone"
"const"
"continue"
"declare"
"default"
"do"
"echo"
"else"
"elseif"
"enddeclare"
"endfor"
"endforeach"
"endif"
"endswitch"
"endwhile"
; "exit"
"extends"
"final"
"finally"
"fn"
"for"
"foreach"
"function"
"global"
"goto"
"if"
"implements"
"include"
"include_once"
"instanceof"
"insteadof"
"interface"
"match"
"namespace"
"new"
"or"
; "print"
"private"
"protected"
"public"
"readonly"
"require"
"require_once"
"return"
"static"
"switch"
"throw"
"trait"
"try"
"use"
"while"
"xor"
; "yield from"
"yield"
] @keyword

0 comments on commit 365fd18

Please sign in to comment.