|
5 | 5 | namespace TypeLang\PHPDoc\Parser\Tag; |
6 | 6 |
|
7 | 7 | use TypeLang\PHPDoc\Exception\InvalidTagNameException; |
| 8 | +use TypeLang\PHPDoc\Exception\RuntimeExceptionInterface; |
8 | 9 | use TypeLang\PHPDoc\FactoryInterface; |
9 | 10 | use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface; |
10 | 11 | use TypeLang\PHPDoc\Tag\Tag; |
@@ -59,17 +60,25 @@ private function getTagName(string $content): string |
59 | 60 | } |
60 | 61 |
|
61 | 62 | /** |
62 | | - * @throws InvalidTagNameException |
| 63 | + * @throws \Throwable |
| 64 | + * @throws RuntimeExceptionInterface |
63 | 65 | */ |
64 | 66 | public function parse(string $tag, DescriptionParserInterface $parser): Tag |
65 | 67 | { |
66 | 68 | $name = $this->getTagName($tag); |
67 | 69 | /** @var non-empty-string $name */ |
68 | 70 | $name = \substr($name, 1); |
69 | 71 |
|
70 | | - $content = \substr($tag, \strlen($name) + 1); |
71 | | - $content = \ltrim($content); |
| 72 | + $content = \substr($tag, $offset = \strlen($name) + 1); |
| 73 | + $trimmed = \ltrim($content); |
| 74 | + |
| 75 | + try { |
| 76 | + return $this->tags->create($name, $trimmed, $parser); |
| 77 | + } catch (RuntimeExceptionInterface $e) { |
| 78 | + /** @var int<0, max> */ |
| 79 | + $offset += \strlen($content) - \strlen($trimmed); |
72 | 80 |
|
73 | | - return $this->tags->create($name, $content, $parser); |
| 81 | + throw $e->withSource($tag, $offset); |
| 82 | + } |
74 | 83 | } |
75 | 84 | } |
0 commit comments