Skip to content

Commit 0115b1c

Browse files
committed
Add parser source highlighting
1 parent be1addf commit 0115b1c

4 files changed

Lines changed: 37 additions & 15 deletions

File tree

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<meta-storm xmlns="meta-storm">
33
<definitions>
4+
<classMethod class="\TypeLang\Parser\ParserInterface"
5+
method="parse"
6+
argument="0">
7+
<languageInjection language="InjectablePHP" />
8+
</classMethod>
9+
10+
<classMethod class="\TypeLang\Parser\Parser"
11+
method="parse"
12+
argument="0">
13+
<languageInjection language="InjectablePHP" />
14+
</classMethod>
415

5-
<classConstructor class="\TypeLang\Parser\ParserInterface"
6-
argument="1">
16+
<classMethod class="\TypeLang\Parser\InMemoryCachedParser"
17+
method="parse"
18+
argument="0">
719
<languageInjection language="InjectablePHP" />
8-
</classConstructor>
20+
</classMethod>
921

10-
<classConstructor class="\TypeLang\Parser\Parser"
11-
argument="1">
22+
<classMethod class="\TypeLang\Parser\ParserInterface"
23+
method="parseTolerant"
24+
argument="0">
1225
<languageInjection language="InjectablePHP" />
13-
</classConstructor>
26+
</classMethod>
1427

15-
<classConstructor class="\TypeLang\Parser\InMemoryCachedParser"
16-
argument="1">
28+
<classMethod class="\TypeLang\Parser\Parser"
29+
method="parseTolerant"
30+
argument="0">
1731
<languageInjection language="InjectablePHP" />
18-
</classConstructor>
32+
</classMethod>
1933

34+
<classMethod class="\TypeLang\Parser\InMemoryCachedParser"
35+
method="parseTolerant"
36+
argument="0">
37+
<languageInjection language="InjectablePHP" />
38+
</classMethod>
2039
</definitions>
2140
</meta-storm>

libs/parser/src/InMemoryCachedParser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace TypeLang\Parser;
66

7+
use JetBrains\PhpStorm\Language;
78
use Phplrt\Contracts\Source\SourceExceptionInterface;
89
use Phplrt\Contracts\Source\SourceFactoryInterface;
910
use Phplrt\Source\SourceFactory;
@@ -32,7 +33,7 @@ public function __construct(
3233
* @throws SourceExceptionInterface
3334
* @throws \Throwable
3435
*/
35-
public function parse(mixed $source): TypeNode
36+
public function parse(#[Language('PHP')] mixed $source): TypeNode
3637
{
3738
$instance = $this->sources->create($source);
3839

@@ -44,7 +45,7 @@ public function parse(mixed $source): TypeNode
4445
* @throws SourceExceptionInterface
4546
* @throws \Throwable
4647
*/
47-
public function parseTolerant(mixed $source): ParsedResult
48+
public function parseTolerant(#[Language('PHP')] mixed $source): ParsedResult
4849
{
4950
$instance = $this->sources->create($source);
5051

libs/parser/src/Parser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace TypeLang\Parser;
66

7+
use JetBrains\PhpStorm\Language;
78
use Phplrt\Contracts\Parser\ParserRuntimeExceptionInterface;
89
use Phplrt\Contracts\Source\ReadableInterface;
910
use Phplrt\Contracts\Source\SourceExceptionInterface;
@@ -49,14 +50,14 @@ public function withFeatures(bool ...$features): self
4950
);
5051
}
5152

52-
public function parse(mixed $source): TypeNode
53+
public function parse(#[Language('PHP')] mixed $source): TypeNode
5354
{
5455
$result = $this->execute($this->strict, $source);
5556

5657
return $result->type;
5758
}
5859

59-
public function parseTolerant(mixed $source): ParsedResult
60+
public function parseTolerant(#[Language('PHP')] mixed $source): ParsedResult
6061
{
6162
return $this->execute($this->tolerant, $source);
6263
}

libs/parser/src/ParserInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace TypeLang\Parser;
66

7+
use JetBrains\PhpStorm\Language;
78
use TypeLang\Node\Type\TypeNode;
89
use TypeLang\Parser\Exception\ParserExceptionInterface;
910

@@ -33,7 +34,7 @@ interface ParserInterface
3334
* @throws ParserExceptionInterface in case of parsing exception occurs
3435
* @throws \Throwable in case of internal error occurs
3536
*/
36-
public function parse(mixed $source): TypeNode;
37+
public function parse(#[Language('PHP')] mixed $source): TypeNode;
3738

3839
/**
3940
* Parses as much of the provided source code as possible and returns
@@ -74,5 +75,5 @@ public function parse(mixed $source): TypeNode;
7475
* @throws ParserExceptionInterface in case of parsing exception occurs
7576
* @throws \Throwable in case of internal error occurs
7677
*/
77-
public function parseTolerant(mixed $source): ParsedResult;
78+
public function parseTolerant(#[Language('PHP')] mixed $source): ParsedResult;
7879
}

0 commit comments

Comments
 (0)