Skip to content

Commit cb5d7f3

Browse files
committed
Abstract and generalize finding definitions in language docs
1 parent d636000 commit cb5d7f3

File tree

1 file changed

+60
-34
lines changed

1 file changed

+60
-34
lines changed

htmlify.p6

Lines changed: 60 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -184,46 +184,29 @@ sub process-pod-dir($dir, :$dr, :&sorted-by = &[cmp]) {
184184
for @pod-sources.kv -> $num, (:key($podname), :value($file)) {
185185
printf "% 4d/%d: % -40s => %s\n", $num, $total, $file.path, "$what/$podname";
186186
my $pod = EVAL(slurp($file.path) ~ "\n\$=pod")[0];
187-
process-pod-file($what, :$dr, :what($what), :$pod, :$podname);
187+
process-pod-source $what, :$dr, :what($what), :$pod, :$podname;
188188
}
189189
}
190190

191-
multi process-pod-file("language", :$dr, :$what, :$pod, :$podname) {
192-
spurt "html/$what/$podname.html", p2h($pod, $what);
193-
my $name = $pod.content[0].name eq "TITLE"
194-
?? $pod.content[0].content[0].content[0]
195-
!! $podname;
196-
my $d = $dr.add-new(
197-
:kind<language>,
198-
:name($name),
199-
:url("/language/$podname"),
200-
:$pod,
201-
:pod-is-complete,
202-
);
203-
if $podname eq 'operators' {
204-
my @chunks = chunks-grep($pod.content,
205-
:from({ $_ ~~ Pod::Heading and .level == 2}),
206-
:to({ $^b ~~ Pod::Heading and $^b.level <= $^a.level}),
207-
);
208-
for @chunks -> $chunk {
209-
my $heading = $chunk[0].content[0].content[0];
210-
next unless $heading ~~ / ^ [in | pre | post | circum | postcircum ] fix | listop /;
211-
my $what = ~$/;
212-
my $operator = $heading.split(' ', 2)[1];
213-
$dr.add-new(
214-
:kind<routine>,
215-
:subkinds($what),
216-
:categories<operator>,
217-
:name($operator),
218-
:pod($chunk),
219-
:origin($d)
220-
:!pod-is-complete,
221-
);
222-
}
191+
multi process-pod-source("language", :$dr, :$what, :$pod, :$podname) {
192+
my $name = $podname;
193+
if $pod.content[0].name eq "TITLE" {
194+
$name = $pod.content[0].content[0].content[0]
195+
} else {
196+
note "$podname does not have an =TITLE";
223197
}
198+
my $origin = $dr.add-new(
199+
:kind<language>,
200+
:name($name),
201+
:url("/language/$podname"),
202+
:$pod,
203+
:pod-is-complete,
204+
);
205+
find-definitions :$dr, :$pod, :$origin;
206+
spurt "html/$what/$podname.html", p2h($pod, $what);
224207
}
225208

226-
multi process-pod-file("type", :$dr, :$what, :$pod, :$podname) {
209+
multi process-pod-source("type", :$dr, :$what, :$pod, :$podname) {
227210
my @chunks = chunks-grep($pod.content,
228211
:from({ $_ ~~ Pod::Heading and .level == 2}),
229212
:to({ $^b ~~ Pod::Heading and $^b.level <= $^a.level}),
@@ -348,6 +331,49 @@ multi process-pod-file("type", :$dr, :$what, :$pod, :$podname) {
348331
spurt "html/$what/$podname.html", p2h($pod, $what);
349332
}
350333

334+
sub find-definitions (:$pod, :$origin, :$dr) {
335+
my @chunks = chunks-grep($pod.content,
336+
:from({
337+
$_ ~~ Pod::Heading and
338+
.content[0].content[0] ~~ { $_ ~~ Str and .words.elems == 2 }
339+
}),
340+
:to({ $^b ~~ Pod::Heading and $^b.level <= $^a.level}),
341+
);
342+
for @chunks -> $chunk {
343+
my ($what, $name) = $chunk[0].content[0].content[0].words;
344+
my $created;
345+
my &add-new = { $created = $dr.add-new(
346+
:$name,
347+
:subkinds($what),
348+
:pod($chunk),
349+
:$origin,
350+
:!pod-is-complete,
351+
|%_
352+
)}
353+
given $what {
354+
when / ^ [in | pre | post | circum | postcircum ] fix | listop / {
355+
add-new :kind<routine>
356+
:categories<operator>
357+
}
358+
when / sub | method / {
359+
add-new :kind<routine>
360+
}
361+
when / routine / {
362+
add-new :kind<routine>
363+
:subkinds<sub>
364+
}
365+
when / class | role / {
366+
add-new :kind<type>
367+
}
368+
default {
369+
next
370+
}
371+
}
372+
say "Found definition of $what $name in $origin.name()";
373+
$chunk[0].content[0] = pod-link "$what $name", $created.url;
374+
}
375+
}
376+
351377
sub chunks-grep(:$from!, :&to!, *@elems) {
352378
my @current;
353379

0 commit comments

Comments
 (0)