Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix index building and add simple key look
  • Loading branch information
stmuk committed Aug 2, 2014
1 parent 9cb4baa commit 4eaa349
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions index.p6
@@ -1,5 +1,6 @@
#!/usr/bin/env perl6
use v6;
use File::Find;

my $index_file = "index.data";
multi sub MAIN() {
Expand All @@ -9,14 +10,21 @@ multi sub MAIN() {

multi sub MAIN('index') {
my %words;
for dir('lib') -> $file {
my $pod = substr($file.Str, 0 , $file.Str.chars -4);

my @files := find(:dir('lib'),:type('file'));

for @files -> $f {
my $file = $f.path;
next if $file !~~ /\.pod$/;
my $pod = substr($file.Str, 0 , $file.Str.chars -4);
$pod.=subst(/lib\//,"");
$pod.=subst(/\//,'::',:g);
my $section = '';
for open('lib/' ~ $file.Str).lines -> $row {
for open( $file.Str).lines -> $row {
#if $row ~~ /^\=(item|head\d) \s+ X\<(.*)\> \s*$/ {
if $row ~~ /^\=(item|head\d) \s+ (.*?) \s*$/ {
$section = $1.Str;
$section.=subst(/\|/,"",:g);
%words{$section}.push([$pod, $section]);
}
if $row ~~ /X\<(.*?)\>/ and $section {
Expand All @@ -43,3 +51,14 @@ multi sub MAIN('list') {
}
}

multi sub MAIN('lookup', $key) {
if $index_file.IO ~~ :e {
my %data = EVAL slurp $index_file;
die "not found" unless %data{$key};
say %data{$key}.split(" ").[0];
} else {
say "First run $*PROGRAM_NAME index to create the index";
exit;
}
}

0 comments on commit 4eaa349

Please sign in to comment.