Skip to content

Commit 17c9b40

Browse files
committed
Calculating the correct position in external tag parser errors
1 parent ca97bbb commit 17c9b40

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Diff for: src/Parser/Tag/TagParser.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace TypeLang\PHPDoc\Parser\Tag;
66

77
use TypeLang\PHPDoc\Exception\InvalidTagNameException;
8+
use TypeLang\PHPDoc\Exception\RuntimeExceptionInterface;
89
use TypeLang\PHPDoc\FactoryInterface;
910
use TypeLang\PHPDoc\Parser\Description\DescriptionParserInterface;
1011
use TypeLang\PHPDoc\Tag\Tag;
@@ -59,17 +60,25 @@ private function getTagName(string $content): string
5960
}
6061

6162
/**
62-
* @throws InvalidTagNameException
63+
* @throws \Throwable
64+
* @throws RuntimeExceptionInterface
6365
*/
6466
public function parse(string $tag, DescriptionParserInterface $parser): Tag
6567
{
6668
$name = $this->getTagName($tag);
6769
/** @var non-empty-string $name */
6870
$name = \substr($name, 1);
6971

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);
7280

73-
return $this->tags->create($name, $content, $parser);
81+
throw $e->withSource($tag, $offset);
82+
}
7483
}
7584
}

0 commit comments

Comments
 (0)