Skip to content

Commit 5aeb785

Browse files
committed
Inline &add-new in &find-definitions
There used to be a reason for it to be a sub; no longer
1 parent 0216cbd commit 5aeb785

File tree

1 file changed

+49
-58
lines changed

1 file changed

+49
-58
lines changed

htmlify.p6

Lines changed: 49 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -270,52 +270,8 @@ sub find-definitions (:$pod, :$origin, :$dr, :$min-level = -1) {
270270
# If a heading is a definition, like "class FooBar", process
271271
# the class and give the rest of the pod to find-definitions,
272272
# which will return how far the definition of "class FooBar" extends.
273-
my @c := $pod ~~ Positional ?? @$pod !! $pod.content;
273+
my @c := $pod ~~ Positional ?? @$pod !! $pod.content;
274274
my int $i = 0;
275-
276-
my sub add-new (:$name, :$subkinds, *%_) {
277-
my $created = $dr.add-new(
278-
:$origin,
279-
:pod[],
280-
:!pod-is-complete,
281-
:$name,
282-
:$subkinds,
283-
|%_
284-
);
285-
286-
# Preform sub-parse, checking for definitions elsewhere in the pod
287-
# And updating $i to be after the places we've already searched
288-
my int $new-i = $i + find-definitions :pod(@c[$i+1..*]), :origin($created), :$dr, :min-level(@c[$i].level);
289-
290-
@c[$i].content[0] = pod-link "$subkinds $name",
291-
$created.url ~ "#$origin.human-kind() $origin.name()".subst(:g, /\s+/, '_');
292-
293-
my $chunk = $created.pod.push: pod-lower-headings(@c[$i..$new-i], :to($created.kind eq 'type' ?? 0 !! 2));
294-
295-
$i = $new-i;
296-
297-
if $subkinds eq 'routine' {
298-
# Determine proper subkinds
299-
my Str @subkinds = first-code-block($chunk)\
300-
.match(:g, /:s ^ 'multi'? (sub|method)»/)\
301-
.>>[0]>>.Str.uniq;
302-
303-
note "The subkinds of routine $created.name() in $origin.name() cannot be determined."
304-
unless @subkinds;
305-
306-
$created.subkinds = @subkinds;
307-
$created.categories = @subkinds;
308-
}
309-
if $subkinds 'method' {
310-
%methods-by-type{$origin.name}.push: $chunk;
311-
write-qualified-method-call(
312-
:$name,
313-
:pod($chunk),
314-
:type($origin.name),
315-
);
316-
}
317-
}
318-
319275
my int $len = +@c;
320276
while $i < $len {
321277
my $c := @c[$i];
@@ -328,30 +284,65 @@ sub find-definitions (:$pod, :$origin, :$dr, :$min-level = -1) {
328284
$i = $i + 1 and next unless $c.content[0].content[0] ~~ Str
329285
and 2 == my @words = $c.content[0].content[0].words;
330286

331-
my ($what, $name) = @words;
332-
given $what {
287+
my ($subkinds, $name) = @words;
288+
my %attr;
289+
given $subkinds {
333290
when / ^ [in | pre | post | circum | postcircum ] fix | listop / {
334-
add-new :kind<routine>
335-
:$name
336-
:subkinds($what)
337-
:categories<operator>
291+
%attr = :kind<routine>,
292+
:categories<operator>,
338293
}
339294
when 'sub'|'method'|'term'|'routine' {
340-
add-new :kind<routine>
341-
:$name
342-
:subkinds($what)
343-
:categories($what)
295+
%attr = :kind<routine>,
296+
:categories($subkinds),
344297
}
345298
when 'class'|'role' {
346-
add-new :kind<type>
347-
:$name
348-
:subkinds($what)
299+
%attr = :kind<type>,
349300
}
350301
default {
351302
$i = $i + 1 and next
352303
}
353304
}
354305
# We made it this far, so it's a valid definition
306+
my $created = $dr.add-new(
307+
:$origin,
308+
:pod[],
309+
:!pod-is-complete,
310+
:$name,
311+
:$subkinds,
312+
|%attr
313+
);
314+
315+
# Preform sub-parse, checking for definitions elsewhere in the pod
316+
# And updating $i to be after the places we've already searched
317+
my int $new-i = $i + find-definitions :pod(@c[$i+1..*]), :origin($created), :$dr, :min-level(@c[$i].level);
318+
319+
@c[$i].content[0] = pod-link "$subkinds $name",
320+
$created.url ~ "#$origin.human-kind() $origin.name()".subst(:g, /\s+/, '_');
321+
322+
my $chunk = $created.pod.push: pod-lower-headings(@c[$i..$new-i], :to(%attr<kind> eq 'type' ?? 0 !! 2));
323+
324+
$i = $new-i;
325+
326+
if $subkinds eq 'routine' {
327+
# Determine proper subkinds
328+
my Str @subkinds = first-code-block($chunk)\
329+
.match(:g, /:s ^ 'multi'? (sub|method)»/)\
330+
.>>[0]>>.Str.uniq;
331+
332+
note "The subkinds of routine $created.name() in $origin.name() cannot be determined."
333+
unless @subkinds;
334+
335+
$created.subkinds = @subkinds;
336+
$created.categories = @subkinds;
337+
}
338+
if $subkinds 'method' {
339+
%methods-by-type{$origin.name}.push: $chunk;
340+
write-qualified-method-call(
341+
:$name,
342+
:pod($chunk),
343+
:type($origin.name),
344+
);
345+
}
355346
}
356347
$i = $i + 1;
357348
}

0 commit comments

Comments
 (0)