Skip to content

Commit 5d6fbec

Browse files
committed
Improve &find-definitions documentation a bit
1 parent 0edfb1a commit 5d6fbec

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

htmlify.p6

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,17 +304,19 @@ multi write-type-source($doc) {
304304
spurt "html/$what/$podname.html", p2h($pod, $what);
305305
}
306306

307+
#| A one-pass-parser for pod headers that define something documentable.
307308
sub find-definitions (:$pod, :$origin, :$min-level = -1) {
308-
# Run through the pod content, and look for headings.
309-
# If a heading is a definition, like "class FooBar", process
310-
# the class and give the rest of the pod to find-definitions,
309+
# Runs through the pod content, and looks for headings.
310+
# If a heading is a definition, like "class FooBar", processes
311+
# the class and gives the rest of the pod to find-definitions,
311312
# which will return how far the definition of "class FooBar" extends.
312-
my @all-pod-elements := $pod ~~ Positional ?? @$pod !! $pod.contents;
313+
# We then continue parsing from after that point.
314+
my @pod-section := $pod ~~ Positional ?? @$pod !! $pod.contents;
313315
my int $i = 0;
314-
my int $len = +@all-pod-elements;
316+
my int $len = +@pod-section;
315317
while $i < $len {
316318
NEXT {$i = $i + 1}
317-
my $pod-element := @all-pod-elements[$i];
319+
my $pod-element := @pod-section[$i];
318320
next unless $pod-element ~~ Pod::Heading;
319321
return $i if $pod-element.level <= $min-level;
320322

@@ -368,8 +370,8 @@ sub find-definitions (:$pod, :$origin, :$min-level = -1) {
368370
}
369371
when 'class'|'role'|'enum' {
370372
my $summary = '';
371-
if @all-pod-elements[$i+1] ~~ {$_ ~~ Pod::Block::Named and .name eq "SUBTITLE"} {
372-
$summary = @all-pod-elements[$i+1].contents[0].contents[0];
373+
if @pod-section[$i+1] ~~ {$_ ~~ Pod::Block::Named and .name eq "SUBTITLE"} {
374+
$summary = @pod-section[$i+1].contents[0].contents[0];
373375
} else {
374376
note "$name does not have an =SUBTITLE";
375377
}
@@ -407,18 +409,18 @@ sub find-definitions (:$pod, :$origin, :$min-level = -1) {
407409
# And updating $i to be after the places we've already searched
408410
once {
409411
$new-i = $i + find-definitions
410-
:pod(@all-pod-elements[$i+1..*]),
412+
:pod(@pod-section[$i+1..*]),
411413
:origin($created),
412-
:min-level(@all-pod-elements[$i].level);
414+
:min-level(@pod-section[$i].level);
413415
}
414416

415417
my $new-head = Pod::Heading.new(
416-
:level(@all-pod-elements[$i].level),
418+
:level(@pod-section[$i].level),
417419
:contents[pod-link "$subkinds $name",
418420
$created.url ~ "#$origin.human-kind() $origin.name()".subst(:g, /\s+/, '_')
419421
]
420422
);
421-
my @orig-chunk = $new-head, @all-pod-elements[$i ^.. $new-i];
423+
my @orig-chunk = $new-head, @pod-section[$i ^.. $new-i];
422424
my $chunk = $created.pod.push: pod-lower-headings(@orig-chunk, :to(%attr<kind> eq 'type' ?? 0 !! 2));
423425

424426
if $subkinds eq 'routine' {

0 commit comments

Comments
 (0)