Skip to content

Commit dda2004

Browse files
committed
Remove phplrt dependency and speedup comment lexing
1 parent 4933040 commit dda2004

8 files changed

+124
-168
lines changed

composer.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
"issues": "https://github.com/php-type-language/phpdoc/issues"
1010
},
1111
"require": {
12-
"php": "^8.1",
13-
"phplrt/lexer": "^3.6",
14-
"phplrt/source": "^3.6"
12+
"php": "^8.1"
1513
},
1614
"autoload": {
1715
"psr-4": {

src/Exception/InvalidTagNameException.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace TypeLang\PHPDoc\Exception;
66

7-
use Phplrt\Contracts\Source\ReadableInterface;
8-
97
class InvalidTagNameException extends InvalidTagException
108
{
119
final public const ERROR_CODE_EMPTY = 0x01 + parent::CODE_LAST;
@@ -33,7 +31,7 @@ public static function fromEmptyTag(int $offset = 0): static
3331
*
3432
* @param int<0, max> $offset
3533
*/
36-
public static function fromEmptyTagName(ReadableInterface|string $source, int $offset = 0): static
34+
public static function fromEmptyTagName(string $source, int $offset = 0): static
3735
{
3836
$message = 'Tag name cannot be empty';
3937

@@ -45,7 +43,7 @@ public static function fromEmptyTagName(ReadableInterface|string $source, int $o
4543
*
4644
* @param int<0, max> $offset
4745
*/
48-
public static function fromInvalidTagPrefix(ReadableInterface|string $source, int $offset = 0): static
46+
public static function fromInvalidTagPrefix(string $source, int $offset = 0): static
4947
{
5048
$message = 'The tag name must starts with the "@" character';
5149

src/Exception/ParsingException.php

+5-12
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,24 @@
44

55
namespace TypeLang\PHPDoc\Exception;
66

7-
use Phplrt\Contracts\Source\ReadableInterface;
8-
use Phplrt\Source\Source;
9-
107
class ParsingException extends \RuntimeException implements RuntimeExceptionInterface
118
{
129
final public const ERROR_CODE_INTERNAL = 0x01;
1310

1411
protected const CODE_LAST = self::ERROR_CODE_INTERNAL;
1512

16-
public readonly ReadableInterface $source;
13+
public readonly string $source;
1714

1815
/**
1916
* @param int<0, max> $offset
2017
*/
2118
final public function __construct(
22-
ReadableInterface|string $source,
19+
string $source,
2320
public readonly int $offset = 0,
2421
string $message = "",
2522
int $code = 0,
2623
?\Throwable $previous = null
2724
) {
28-
if (\is_string($source)) {
29-
$source = new Source($source);
30-
}
31-
3225
$this->source = $source;
3326

3427
parent::__construct($message, $code, $previous);
@@ -37,7 +30,7 @@ final public function __construct(
3730
/**
3831
* @param int<0, max> $offset
3932
*/
40-
public static function fromInternalError(ReadableInterface|string $source, int $offset, \Throwable $e): self
33+
public static function fromInternalError(string $source, int $offset, \Throwable $e): self
4134
{
4235
return new static(
4336
source: $source,
@@ -51,7 +44,7 @@ public static function fromInternalError(ReadableInterface|string $source, int $
5144
/**
5245
* @param int<0, max> $offset
5346
*/
54-
public function withSource(ReadableInterface|string $source, int $offset): self
47+
public function withSource(string $source, int $offset): self
5548
{
5649
return new static(
5750
source: $source,
@@ -62,7 +55,7 @@ public function withSource(ReadableInterface|string $source, int $offset): self
6255
);
6356
}
6457

65-
public function getSource(): ReadableInterface
58+
public function getSource(): string
6659
{
6760
return $this->source;
6861
}

src/Exception/RuntimeExceptionInterface.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace TypeLang\PHPDoc\Exception;
66

7-
use Phplrt\Contracts\Source\ReadableInterface;
8-
97
/**
108
* Error occurring while processing phpdoc content.
119
*/
@@ -16,12 +14,12 @@ interface RuntimeExceptionInterface extends PHPDocExceptionInterface
1614
*
1715
* @param int<0, max> $offset
1816
*/
19-
public function withSource(ReadableInterface|string $source, int $offset): self;
17+
public function withSource(string $source, int $offset): self;
2018

2119
/**
2220
* Returns the full content in which the error occurred.
2321
*/
24-
public function getSource(): ReadableInterface;
22+
public function getSource(): string;
2523

2624
/**
2725
* Returns the byte offset at the location where the error occurs.

src/Parser.php

+2-12
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@
55
namespace TypeLang\PHPDoc;
66

77
use JetBrains\PhpStorm\Language;
8-
use Phplrt\Contracts\Lexer\LexerExceptionInterface;
9-
use Phplrt\Contracts\Lexer\LexerRuntimeExceptionInterface;
10-
use Phplrt\Contracts\Source\SourceExceptionInterface;
118
use TypeLang\PHPDoc\Exception\ParsingException;
129
use TypeLang\PHPDoc\Exception\RuntimeExceptionInterface;
1310
use TypeLang\PHPDoc\Parser\Comment\CommentParserInterface;
14-
use TypeLang\PHPDoc\Parser\Comment\LexerAwareCommentParser;
11+
use TypeLang\PHPDoc\Parser\Comment\RegexCommentParser;
1512
use TypeLang\PHPDoc\Parser\Comment\Segment;
1613
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1714
use TypeLang\PHPDoc\Parser\Description\SprintfDescriptionReader;
@@ -25,7 +22,7 @@
2522
class Parser implements ParserInterface
2623
{
2724
public function __construct(
28-
private readonly CommentParserInterface $comments = new LexerAwareCommentParser(),
25+
private readonly CommentParserInterface $comments = new RegexCommentParser(),
2926
private readonly DescriptionParserInterface $descriptions = new SprintfDescriptionReader(),
3027
private readonly TagParserInterface $tags = new TagParser(),
3128
) {}
@@ -64,10 +61,7 @@ public function parse(#[Language('PHP')] string $docblock): DocBlock
6461
/**
6562
* @return \Generator<array-key, Segment, void, DocBlock>
6663
*
67-
* @throws LexerExceptionInterface
68-
* @throws LexerRuntimeExceptionInterface
6964
* @throws RuntimeExceptionInterface
70-
* @throws SourceExceptionInterface
7165
*/
7266
private function analyze(string $docblock): \Generator
7367
{
@@ -106,10 +100,6 @@ private function analyze(string $docblock): \Generator
106100

107101
/**
108102
* @return \Generator<array-key, Segment, void, non-empty-list<string>>
109-
*
110-
* @throws LexerExceptionInterface
111-
* @throws LexerRuntimeExceptionInterface
112-
* @throws SourceExceptionInterface
113103
*/
114104
private function groupByCommentSections(string $docblock): \Generator
115105
{

src/Parser/Comment/LexerAwareCommentParser.php

-128
This file was deleted.

0 commit comments

Comments
 (0)