aboutsummaryrefslogtreecommitdiff
path: root/lib/IRC/Grammar/Actions.pm6
blob: e7f52929cb6860e6ccd8f49beeb93d6ade588caa (plain)
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
unit class IRC::Grammar::Actions:ver<2.001001>;
method TOP ($/) { $/.make: $<message>>>.made }
method message ($/) {
    my $pref = $/<prefix>;
    my %args = command => ~$/<command>;
    for qw/nick user host/ {
        $pref{$_}.defined or next;
        %args<who>{$_} = $pref{$_}.Str;
    }
    %args<who><host> = ~$pref<servername> if $pref<servername>.defined;

    my $p = $/<params>;

    for ^100 { # bail out after 100 iterations; we're stuck
        if ( $p<middle>.defined ) {
            %args<params>.append: ~$p<middle>;
        }
        if ( $p<trailing>.defined ) {
            %args<params>.append: ~$p<trailing>;
            last;
        }
        $p = $p<params>;
    }

    $/.make: %args;
}