mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-21 04:40:08 -04:00
feat(php): add highlight tests
This commit is contained in:
parent
68ba579eb6
commit
3400788705
5 changed files with 251 additions and 0 deletions
|
|
@ -216,6 +216,7 @@
|
||||||
|
|
||||||
(named_label_statement) @label
|
(named_label_statement) @label
|
||||||
|
|
||||||
|
|
||||||
; Keywords
|
; Keywords
|
||||||
[
|
[
|
||||||
"and"
|
"and"
|
||||||
|
|
|
||||||
173
tests/query/highlights/php/keywords.php
Normal file
173
tests/query/highlights/php/keywords.php
Normal file
|
|
@ -0,0 +1,173 @@
|
||||||
|
<?php
|
||||||
|
//^^^ @punctuation.bracket
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
//^^^^^ @keyword
|
||||||
|
// ^^^^^^^^^^^^ @variable.parameter
|
||||||
|
// ^ @operator
|
||||||
|
// ^ @number
|
||||||
|
// ^ @punctuation.delimiter
|
||||||
|
|
||||||
|
include "file.php";
|
||||||
|
//^^^^^ @keyword.import
|
||||||
|
// ^^^^^^^^^ @string
|
||||||
|
include_once "file.php";
|
||||||
|
//^^^^^^^^^^ @keyword.import
|
||||||
|
require "file.php";
|
||||||
|
//^^^^^ @keyword.import
|
||||||
|
require_once "file.php";
|
||||||
|
//^^^^^^^^^^ @keyword.import
|
||||||
|
|
||||||
|
namespace A\B;
|
||||||
|
//^^^^^^^ @keyword
|
||||||
|
// ^^^ @module
|
||||||
|
|
||||||
|
if ($a and $b or $c xor $d) {} elseif ($b) {} else {}
|
||||||
|
// <- @keyword.conditional
|
||||||
|
// ^^^ @keyword.operator
|
||||||
|
// ^^ @keyword.operator
|
||||||
|
// ^^^ @keyword.operator
|
||||||
|
// ^^^^^^ @keyword.conditional
|
||||||
|
// ^^^^ @keyword.conditional
|
||||||
|
|
||||||
|
for ($i = 0; $i < 1; $i++) { continue; }
|
||||||
|
// <- @keyword.repeat
|
||||||
|
// ^ @operator
|
||||||
|
// ^^ @operator
|
||||||
|
// ^^^^^^^^ @keyword.repeat
|
||||||
|
|
||||||
|
while ($b) {}
|
||||||
|
//^^^ @keyword.repeat
|
||||||
|
|
||||||
|
do { } while ($c);
|
||||||
|
// <- @keyword.repeat
|
||||||
|
// ^^^^^ @keyword.repeat
|
||||||
|
|
||||||
|
foreach ($foos as $foo) {}
|
||||||
|
//^^^^^ @keyword.repeat
|
||||||
|
// ^^ @keyword.operator
|
||||||
|
|
||||||
|
try {} catch (Exception $e) {} finally {}
|
||||||
|
//^ @keyword.exception
|
||||||
|
// ^^^^^ @keyword.exception
|
||||||
|
// ^^^^^^^^^ @type
|
||||||
|
// ^^^^^^^ @keyword.exception
|
||||||
|
|
||||||
|
function a() {}
|
||||||
|
//^^^^^^ @keyword.function
|
||||||
|
// ^ @function
|
||||||
|
|
||||||
|
abstract class A
|
||||||
|
//^^^^^^ @keyword.modifier
|
||||||
|
// ^^^^^ @keyword
|
||||||
|
// ^ @type
|
||||||
|
{
|
||||||
|
private const BAR = 1;
|
||||||
|
//^^^^^^^ @keyword.modifier
|
||||||
|
// ^^^^^ @keyword.modifier
|
||||||
|
// ^^^ @constant
|
||||||
|
protected readonly static $a;
|
||||||
|
//^^^^^^^^^ @keyword.modifier
|
||||||
|
// ^^^^^^^^ @keyword.modifier
|
||||||
|
// ^^^^^^ @keyword.modifier
|
||||||
|
// ^^ @property
|
||||||
|
final public $b;
|
||||||
|
//^^^^^ @keyword.modifier
|
||||||
|
public static function foo(): static {}
|
||||||
|
//^^^^^^ @keyword.modifier
|
||||||
|
// ^^^^^^ @keyword.modifier
|
||||||
|
// ^^^^^^^^ @keyword.function
|
||||||
|
// ^^^ @function.method
|
||||||
|
// ^^^^^^ @type.builtin
|
||||||
|
public function __construct() {}
|
||||||
|
// ^^^^^^^^^^^ @constructor
|
||||||
|
}
|
||||||
|
|
||||||
|
class B extends A implements T
|
||||||
|
// ^ @type
|
||||||
|
// ^^^^^^^ @keyword
|
||||||
|
// ^ @type
|
||||||
|
// ^^^^^^^^^^ @keyword
|
||||||
|
// ^ @type
|
||||||
|
{
|
||||||
|
use T, U {
|
||||||
|
//^^^ @keyword.import
|
||||||
|
// ^ @punctuation.delimiter
|
||||||
|
U::small insteadof T;
|
||||||
|
// ^ @type
|
||||||
|
// ^^ @operator
|
||||||
|
// ^^^^^ @constant
|
||||||
|
// ^^^^^^^^^ @keyword
|
||||||
|
// ^ @type
|
||||||
|
}
|
||||||
|
public function foo(callable $call): self
|
||||||
|
// ^^^^^^^^ @type.builtin
|
||||||
|
// ^^^^ @type.builtin
|
||||||
|
{
|
||||||
|
$call instanceof Closure;
|
||||||
|
// ^^^^^ @variable
|
||||||
|
// ^^^^^^^^^^ @keyword
|
||||||
|
// ^^^^^^^ @type
|
||||||
|
fn ($a, $b) => $a + $b;
|
||||||
|
// ^^ @keyword.function
|
||||||
|
static $a;
|
||||||
|
// ^^^^^^ @keyword.modifier
|
||||||
|
global $a;
|
||||||
|
// ^^^^^^ @keyword
|
||||||
|
clone $call;
|
||||||
|
// ^^^^^ @keyword
|
||||||
|
match ($a) {
|
||||||
|
// ^^^^^ @keyword.conditional
|
||||||
|
default => "other",
|
||||||
|
// ^^^^^^^ @keyword
|
||||||
|
// ^^ @operator
|
||||||
|
};
|
||||||
|
|
||||||
|
switch ($a) {
|
||||||
|
// ^^^^^^ @keyword.conditional
|
||||||
|
case 'value':
|
||||||
|
// ^^^^ @keyword.conditional
|
||||||
|
break;
|
||||||
|
// ^^^^^ @keyword
|
||||||
|
default:
|
||||||
|
// ^^^^^^^ @keyword
|
||||||
|
}
|
||||||
|
yield $a;
|
||||||
|
// ^^^^^ @keyword.return
|
||||||
|
yield from $a;
|
||||||
|
// ^^^^ @keyword.return
|
||||||
|
return $a;
|
||||||
|
// ^^^^^^ @keyword.return
|
||||||
|
goto a;
|
||||||
|
// ^^^^ @keyword
|
||||||
|
echo "a";
|
||||||
|
// ^^^^ @keyword
|
||||||
|
print "a";
|
||||||
|
// ^^^^^ @keyword
|
||||||
|
print("a");
|
||||||
|
// ^^^^^ @keyword
|
||||||
|
exit;
|
||||||
|
// ^^^^ @keyword
|
||||||
|
exit();
|
||||||
|
// ^^^^ @function.builtin
|
||||||
|
exit(1);
|
||||||
|
// ^^^^ @function.builtin
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Exception("oh");
|
||||||
|
//^^^ @keyword.exception
|
||||||
|
// ^^^ @keyword
|
||||||
|
// ^^^^^^^^^ @constructor
|
||||||
|
|
||||||
|
interface T {}
|
||||||
|
//^^^^^^^ @keyword
|
||||||
|
// ^ @type
|
||||||
|
|
||||||
|
trait T { public function small(): void {} }
|
||||||
|
//^^^ @keyword
|
||||||
|
// ^ @type
|
||||||
|
// ^^^^ @type.builtin
|
||||||
|
enum Foo { case Bar; }
|
||||||
|
//^^ @keyword
|
||||||
|
// ^^^^ @keyword.conditional
|
||||||
26
tests/query/highlights/php/literals.php
Normal file
26
tests/query/highlights/php/literals.php
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
echo <<<OMG
|
||||||
|
// ^^^ @operator
|
||||||
|
// ^^^ @label
|
||||||
|
something
|
||||||
|
OMG;
|
||||||
|
//^ @label
|
||||||
|
|
||||||
|
echo true, TRUE, false, FALSE;
|
||||||
|
// ^^^^ @boolean
|
||||||
|
// ^^^^ @boolean
|
||||||
|
// ^^^^^ @boolean
|
||||||
|
// ^^^^^ @boolean
|
||||||
|
|
||||||
|
echo PI_314;
|
||||||
|
// ^^^^^^ @constant
|
||||||
|
|
||||||
|
echo __DIR__;
|
||||||
|
// ^^^^^^^ @constant.builtin
|
||||||
|
|
||||||
|
echo null, 42, 42.524, "Testing\n";
|
||||||
|
// ^^^^ @constant.builtin
|
||||||
|
// ^^ @number
|
||||||
|
// ^^^^^^ @number.float
|
||||||
|
// ^^ @string.escape
|
||||||
23
tests/query/highlights/php/types.php
Normal file
23
tests/query/highlights/php/types.php
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
function b(int $a, string $b, Person $e): Foo\Dog {}
|
||||||
|
// ^^^ @type.builtin
|
||||||
|
// ^^ @variable
|
||||||
|
// ^^^^^^ @type.builtin
|
||||||
|
// ^^^^^^ @type
|
||||||
|
// ^^^ @module
|
||||||
|
// ^^^ @type
|
||||||
|
|
||||||
|
function a(array $b) {
|
||||||
|
// ^^^^^ @type.builtin
|
||||||
|
echo (int) $foo;
|
||||||
|
// ^^^ @type.builtin
|
||||||
|
}
|
||||||
|
|
||||||
|
class A {
|
||||||
|
public function foo(self $a): self {}
|
||||||
|
// ^^^^ @type.builtin
|
||||||
|
// ^^^^ @type.builtin
|
||||||
|
private function baz(): static {}
|
||||||
|
// ^^^^^^ @type.builtin
|
||||||
|
}
|
||||||
28
tests/query/highlights/php/variables.php
Normal file
28
tests/query/highlights/php/variables.php
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class A {
|
||||||
|
public function foo(self $a): self {
|
||||||
|
// ^ @variable
|
||||||
|
new self();
|
||||||
|
// ^^^^ @constructor
|
||||||
|
new static();
|
||||||
|
// ^^^^^^ @constructor
|
||||||
|
new parent();
|
||||||
|
// ^^^^^^ @constructor
|
||||||
|
$this->foo();
|
||||||
|
// ^^^^ @variable.builtin
|
||||||
|
// ^^ @operator
|
||||||
|
// ^^^ @function.method.call
|
||||||
|
self::foo();
|
||||||
|
// ^^^^ @variable.builtin
|
||||||
|
// ^^^ @function.call
|
||||||
|
static::foo();
|
||||||
|
// ^^^^^^ @variable.builtin
|
||||||
|
parent::foo();
|
||||||
|
// ^^^^^^ @variable.builtin
|
||||||
|
$this->foo;
|
||||||
|
// ^^^ @variable.member
|
||||||
|
$this->foo(a: 5);
|
||||||
|
// ^ @variable.parameter
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue