Skip to content

Commit d69d8db

Browse files
ntrelthewilsonator
authored andcommitted
[ddoc_preprocessor] Skip GRAMMAR sections with suffix
Follow up to #3860.
1 parent f4c45f9 commit d69d8db

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

ddoc/source/preprocessor.d

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,15 +291,31 @@ auto genGrammar(string fileText)
291291
continue;
292292

293293
enum grammarKey = "$(GRAMMAR";
294-
auto text = entry.fileName.readText.find(grammarKey);
295-
if (text.length)
296-
newContent ~= "$(H2 $(LNAME2 %s, %s))\n".format(entry.title.toLower, entry.title);
297-
for (; text.length; text = text[ grammarKey.length .. $].find(grammarKey))
294+
295+
static string findKey(string s)
296+
{
297+
s = s.find(grammarKey);
298+
// retry if no space after
299+
if (s.length > grammarKey.length && !s[grammarKey.length].isWhite)
300+
{
301+
return findKey(s[grammarKey.length .. $]);
302+
}
303+
return s;
304+
}
305+
auto text = findKey(entry.fileName.readText);
306+
if (!text.length)
307+
continue;
308+
309+
newContent ~= "$(H2 $(LNAME2 %s, %s))\n".format(entry.title.toLower, entry.title);
310+
do
298311
{
299312
newContent ~= grammarKey;
300-
newContent ~= text.drop(grammarKey.length).untilClosingParentheses.to!string;
313+
text.popFrontN(grammarKey.length);
314+
newContent ~= text.untilClosingParentheses.to!string;
301315
newContent ~= ")\n";
316+
text = findKey(text);
302317
}
318+
while (text.length);
303319
}
304320
return updateDdocTag(fileText, ddocKey, newContent);
305321
}

0 commit comments

Comments
 (0)