aboutsummaryrefslogtreecommitdiff
path: root/lib/IRC/Grammar/Actions.pm6
blob: 74a8f11c865b57eef400137abf18086f105c3f83 (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
unit class IRC::Grammar::Actions:ver<1.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>;
    loop {
        if ( $p<middle>.defined ) {
            %args<params>.append: ~$p<middle>;
        }
        if ( $p<trailing>.defined ) {
            %args<params>.append: ~$p<trailing>;
            last;
        }
        $p = $p<params>;
    }

    $/.make: %args;
}