-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathparse-spells.pl
48 lines (41 loc) · 1.09 KB
/
parse-spells.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
use v6;
use JSON::Tiny;
my @list = 'spelllist.txt'.IO.lines;
my @buf;
my %spells;
my @descs = 'spelldescs.txt'.IO.lines;
sub parse-type($line) {
my @words = $line.words;
if @words[0] ~~ /^(\d)/ {
return [+~$0, @words[1].tc]
} else {
return [0, @words[0].tc]
}
}
sub parse(@buf) {
my %props;
my $type = parse-type(@buf.shift);
%props<level> = $type[0];
%props<school> = $type[1];
%props<casting_time> = @buf.shift.subst(/^'Casting Time: '/, '');
%props<range> = @buf.shift.subst(/^'Range: '/, '');
%props<components> = @buf.shift.subst(/^'Components: '/, '');
%props<duration> = @buf.shift.subst(/^'Duration: '/, '');
%props<description> = @buf.join(" ");
return %props;
}
my $current = @list.shift;
for @descs -> $descline {
if $descline eq (@list[0] // '') {
if not %spells {
@buf.shift; # fix for Acid Splash
}
%spells{$current} = parse(@buf);
$current = @list.shift;
@buf = ();
} else {
@buf.push: $descline
}
}
%spells{$current} = parse(@buf);
say to-json(%spells);