@@ -295,42 +295,45 @@ sub find-definitions (:$pod, :$origin, :$dr, :$min-level = -1) {
295
295
my int $ i = 0 ;
296
296
my int $ len = + @ c ;
297
297
while $ i < $ len {
298
+ NEXT {$ i = $ i + 1 }
298
299
my $ c := @ c [$ i ];
299
- if $ c ~~ Pod ::Heading {
300
- return $ i if $ c . level <= $ min-level ;
301
-
302
- # Is this new header a definition?
303
- # If so, begin processing it.
304
- # If not, skip to the next heading.
305
- my @ header := $ c . contents[0 ]. contents;
306
- my @ words ;
307
- given @ header {
308
- when : (" " , Pod ::FormattingCode $ , " " ) {
309
- proceed unless . [1 ]. type eq " X" ;
310
- @ words = . [1 ]. meta[0 ][0 ,1 ]; # XXX Multiple definitions
311
- }
312
- when : (Str $ where /^ The \s \S+ \s \w+ $/ ) {
313
- # The Foo Infix
314
- @ words = . [0 ]. words [2 ,1 ];
315
- }
316
- when : (Str $ where {m/^ (\w+ ) \s (\S+ )$/ }) {
317
- # Infix Foo
318
- @ words = . [0 ]. words [0 ,1 ];
319
- }
320
- when : (" The " , Pod ::FormattingCode $ , Str $ where /^ \s (\w+ )$/ ) {
321
- # The C<Foo> infix
322
- @ words = . [2 ]. words [0 ], . [1 ]. contents[0 ];
323
- }
324
- when : (Str $ where /^ (\w+ ) \s$/ , Pod ::FormattingCode $ , " " ) {
325
- # infix C<Foo>
326
- @ words = . [0 ]. words [0 ], . [1 ]. contents[0 ];
327
- }
328
- default { $ i = $ i + 1 ; next }
300
+ next unless $ c ~~ Pod ::Heading;
301
+ return $ i if $ c . level <= $ min-level ;
302
+
303
+ # Is this new header a definition?
304
+ # If so, begin processing it.
305
+ # If not, skip to the next heading.
306
+ my @ header := $ c . contents[0 ]. contents;
307
+ my @ definitions ; # [subkind, name]
308
+ given @ header {
309
+ when : (" " , Pod ::FormattingCode $ , " " ) {
310
+ proceed unless . [1 ]. type eq " X" ;
311
+ @ definitions = . [1 ]. meta[];
312
+ }
313
+ when : (Str $ where /^ The \s \S+ \s \w+ $/ ) {
314
+ # The Foo Infix
315
+ @ definitions = [. [0 ]. words [2 ,1 ]];
316
+ }
317
+ when : (Str $ where {m/^ (\w+ ) \s (\S+ )$/ }) {
318
+ # Infix Foo
319
+ @ definitions = [. [0 ]. words [0 ,1 ]];
320
+ }
321
+ when : (" The " , Pod ::FormattingCode $ , Str $ where /^ \s (\w+ )$/ ) {
322
+ # The C<Foo> infix
323
+ @ definitions = [. [2 ]. words [0 ], . [1 ]. contents[0 ]];
329
324
}
325
+ when : (Str $ where /^ (\w+ ) \s$/ , Pod ::FormattingCode $ , " " ) {
326
+ # infix C<Foo>
327
+ @ definitions = [. [0 ]. words [0 ], . [1 ]. contents[0 ]];
328
+ }
329
+ default { next }
330
+ }
330
331
331
- my ($ subkinds , $ name ) = @ words ;
332
+ my int $ new-i = $ i ;
333
+ for @ definitions -> [$ sk , $ name ] {
334
+ my $ subkinds = $ sk . lc ;
332
335
my % attr ;
333
- given $ subkinds . lc {
336
+ given $ subkinds {
334
337
when / ^ [in | pre | post | circum | postcircum ] fix | listop / {
335
338
% attr = : kind<routine >,
336
339
: categories<operator >,
@@ -349,9 +352,10 @@ sub find-definitions (:$pod, :$origin, :$dr, :$min-level = -1) {
349
352
: categories($ subkinds ),
350
353
}
351
354
default {
352
- $ i = $ i + 1 and next
355
+ last
353
356
}
354
357
}
358
+
355
359
# We made it this far, so it's a valid definition
356
360
my $ created = $ dr . add-new(
357
361
: $ origin ,
@@ -364,14 +368,19 @@ sub find-definitions (:$pod, :$origin, :$dr, :$min-level = -1) {
364
368
365
369
# Preform sub-parse, checking for definitions elsewhere in the pod
366
370
# And updating $i to be after the places we've already searched
367
- my int $ new-i = $ i + find-definitions : pod(@ c [$ i + 1.. * ]), : origin($ created ), : $ dr , : min-level(@ c [$ i ]. level);
368
-
369
- @ c [$ i ]. contents[0 ] = pod-link " $ subkinds $ name" ,
370
- $ created . url ~ " #$ origin. human-kind () $ origin. name ()" . subst (: g, /\s + /, ' _' );
371
-
372
- my $ chunk = $ created . pod. push : pod-lower-headings(@ c [$ i .. $ new-i ], : to(% attr <kind > eq ' type' ?? 0 !! 2 ));
371
+ once {
372
+ $ new-i = $ i + find-definitions
373
+ : pod(@ c [$ i + 1.. * ]), : origin($ created ), : $ dr , : min-level(@ c [$ i ]. level);
374
+ }
373
375
374
- $ i = $ new-i ;
376
+ my $ new-head = Pod ::Heading. new (
377
+ : level(@ c [$ i ]. level),
378
+ : contents[pod-link " $ subkinds $ name" ,
379
+ $ created . url ~ " #$ origin. human-kind () $ origin. name ()" . subst (: g, /\s + /, ' _' )
380
+ ]
381
+ );
382
+ my @ orig-chunk = $ new-head , @ c [$ i ^.. $ new-i ];
383
+ my $ chunk = $ created . pod. push : pod-lower-headings(@ orig-chunk , : to(% attr <kind > eq ' type' ?? 0 !! 2 ));
375
384
376
385
if $ subkinds eq ' routine' {
377
386
# Determine proper subkinds
@@ -394,7 +403,7 @@ sub find-definitions (:$pod, :$origin, :$dr, :$min-level = -1) {
394
403
);
395
404
}
396
405
}
397
- $ i = $ i + 1 ;
406
+ $ i = $ new- i + 1 ;
398
407
}
399
408
return $ i ;
400
409
}
0 commit comments