Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
fix for period inside parens (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjergus authored Oct 25, 2019
1 parent 60ae5a1 commit 16362a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 1 addition & 2 deletions docs/class.Facebook.HHAPIDoc.DocBlock.DocBlock.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
</head>
<body>
<h1>Facebook\HHAPIDoc\DocBlock\DocBlock</h1>
<p>Class to represent and parse a docblock (a</p>
<p>k.a. doc comment).</p>
<p>Class to represent and parse a docblock (a.k.a. doc comment)</p>
<p>These comments always are delimeted by <code>/**</code> and <code>*\/</code>.</p>
<p>DocBlocks are treated as GitHub Flavored Markdown, and standard
JavaDoc style tags are supported, such as <code>@param</code>, <code>@see</code>, and
Expand Down
16 changes: 15 additions & 1 deletion src/DocBlock/DocBlock.hack
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,21 @@ final class DocBlock {

$content = Str\trim_left(Str\join($content_lines, "\n"));

$first_period = Str\search($content, '.');
// Find first period that is not nested e.g. inside a link's URL.
$first_period = null;
$nesting_level = 0;
for ($i = 0; $i < Str\length($content); ++$i) {
if ($content[$i] === '.' && $nesting_level === 0) {
$first_period = $i;
break;
} else if ($content[$i] === '(' || $content[$i] === '[') {
++$nesting_level;
} else if ($content[$i] === ')' || $content[$i] === ']') {
// Trim at 0 in case the docblock is not correctly parenthesized.
$nesting_level = Math\maxva($nesting_level - 1, 0);
}
}

if ($first_period !== null) {
// Handle '...'
$slice = Str\slice($content, $first_period);
Expand Down

0 comments on commit 16362a9

Please sign in to comment.