From 0daa494480f7abe37a6e593c6238811009b7b914 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Fri, 3 Jun 2016 07:01:14 -0400 Subject: Start rewrite --- lib/IRC/Client/Grammar/Actions.pm6 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 lib/IRC/Client/Grammar/Actions.pm6 (limited to 'lib/IRC/Client/Grammar/Actions.pm6') diff --git a/lib/IRC/Client/Grammar/Actions.pm6 b/lib/IRC/Client/Grammar/Actions.pm6 new file mode 100644 index 0000000..74ae4e8 --- /dev/null +++ b/lib/IRC/Client/Grammar/Actions.pm6 @@ -0,0 +1,31 @@ +unit class IRC::Client::Grammar::Actions; + +method TOP ($/) { $/.make: ($».made, $) } +method left-overs ($/) { + $/.made: $/.defined ?? !$/ !! ''; +} + +method message ($/) { + my $pref = $/; + my %args = command => ~$/; + for qw/nick user host/ { + $pref{$_}.defined or next; + %args{$_} = $pref{$_}.Str; + } + %args = ~$pref if $pref.defined; + + my $p = $/; + + for ^100 { # bail out after 100 iterations; we're stuck + if ( $p.defined ) { + %args.append: ~$p; + } + if ( $p.defined ) { + %args.append: ~$p; + last; + } + $p = $p; + } + + $/.make: %args; +} -- cgit v1.1 From cb0a6cace8871d17c9701edc1ccba26d1e6e0bfe Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sat, 4 Jun 2016 10:32:49 -0400 Subject: Wtf --- lib/IRC/Client/Grammar/Actions.pm6 | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'lib/IRC/Client/Grammar/Actions.pm6') diff --git a/lib/IRC/Client/Grammar/Actions.pm6 b/lib/IRC/Client/Grammar/Actions.pm6 index 74ae4e8..3e190cd 100644 --- a/lib/IRC/Client/Grammar/Actions.pm6 +++ b/lib/IRC/Client/Grammar/Actions.pm6 @@ -1,22 +1,28 @@ unit class IRC::Client::Grammar::Actions; +use IRC::Client::Message::Numeric; + +has $.irc; +has $.server; + method TOP ($/) { $/.make: ($».made, $) } + method left-overs ($/) { $/.made: $/.defined ?? !$/ !! ''; } method message ($/) { + my %args; my $pref = $/; - my %args = command => ~$/; for qw/nick user host/ { $pref{$_}.defined or next; - %args{$_} = $pref{$_}.Str; + %args{$_} = ~$pref{$_}; } %args = ~$pref if $pref.defined; - my $p = $/; + my $p = $; - for ^100 { # bail out after 100 iterations; we're stuck + loop { if ( $p.defined ) { %args.append: ~$p; } @@ -27,5 +33,23 @@ method message ($/) { $p = $p; } - $/.make: %args; + my %msg-args = + irc => $!irc, + nick => %args, + username => %args, + host => %args, + usermask => "%args!%args@%args", + server => $!server; + + my $msg; + given ~$ { + when /^ ([0..9]**3) $/ { + $msg = IRC::Client::Message::Numeric.new: + :command( $ ), + :args( %args ), + |%msg-args; + } + } + + $/.make: $msg; } -- cgit v1.1 From 791d7981cff0cd3a85fdd504f410a7c9833272dc Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sat, 4 Jun 2016 15:16:43 -0400 Subject: More stuff --- lib/IRC/Client/Grammar/Actions.pm6 | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'lib/IRC/Client/Grammar/Actions.pm6') diff --git a/lib/IRC/Client/Grammar/Actions.pm6 b/lib/IRC/Client/Grammar/Actions.pm6 index 3e190cd..54943bd 100644 --- a/lib/IRC/Client/Grammar/Actions.pm6 +++ b/lib/IRC/Client/Grammar/Actions.pm6 @@ -5,23 +5,23 @@ use IRC::Client::Message::Numeric; has $.irc; has $.server; -method TOP ($/) { $/.make: ($».made, $) } - -method left-overs ($/) { - $/.made: $/.defined ?? !$/ !! ''; +method TOP ($/) { + $/.make: ( + $».made, + ~( $ // '' ), + ); } -method message ($/) { +method message ($match) { my %args; - my $pref = $/; + my $pref = $match; for qw/nick user host/ { $pref{$_}.defined or next; %args{$_} = ~$pref{$_}; } %args = ~$pref if $pref.defined; - my $p = $; - + my $p = $match; loop { if ( $p.defined ) { %args.append: ~$p; @@ -30,26 +30,27 @@ method message ($/) { %args.append: ~$p; last; } + last unless $p.defined; $p = $p; } my %msg-args = irc => $!irc, - nick => %args, - username => %args, - host => %args, - usermask => "%args!%args@%args", + nick => %args//'', + username => %args//'', + host => %args//'', server => $!server; + . = . ~ '!' ~ . ~ '@' ~ . given %msg-args; my $msg; - given ~$ { - when /^ ([0..9]**3) $/ { + given ~$match { + when /^ $=(<[0..9]>**3) $/ { $msg = IRC::Client::Message::Numeric.new: - :command( $ ), + :command( ~$ ), :args( %args ), |%msg-args; } } - $/.make: $msg; + $match.make: $msg; } -- cgit v1.1 From 5a2196b2c8f2ac2eacb3ddaf40b3e75b9c38bb62 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sat, 4 Jun 2016 19:18:31 -0400 Subject: Stuff --- lib/IRC/Client/Grammar/Actions.pm6 | 74 ++++++++++++++++++++++++++++++++------ 1 file changed, 63 insertions(+), 11 deletions(-) (limited to 'lib/IRC/Client/Grammar/Actions.pm6') diff --git a/lib/IRC/Client/Grammar/Actions.pm6 b/lib/IRC/Client/Grammar/Actions.pm6 index 54943bd..6ebe33d 100644 --- a/lib/IRC/Client/Grammar/Actions.pm6 +++ b/lib/IRC/Client/Grammar/Actions.pm6 @@ -1,6 +1,6 @@ unit class IRC::Client::Grammar::Actions; -use IRC::Client::Message::Numeric; +use IRC::Client::Message; has $.irc; has $.server; @@ -23,9 +23,8 @@ method message ($match) { my $p = $match; loop { - if ( $p.defined ) { - %args.append: ~$p; - } + %args.append: ~$p if $p.defined; + if ( $p.defined ) { %args.append: ~$p; last; @@ -35,22 +34,75 @@ method message ($match) { } my %msg-args = + command => $match.uc, + args => %args, + host => %args//'', irc => $!irc, nick => %args//'', - username => %args//'', - host => %args//'', - server => $!server; + server => $!server, + username => %args//''; . = . ~ '!' ~ . ~ '@' ~ . given %msg-args; my $msg; - given ~$match { + given %msg-args { when /^ $=(<[0..9]>**3) $/ { - $msg = IRC::Client::Message::Numeric.new: - :command( ~$ ), - :args( %args ), + $msg = IRC::Client::Message::Numeric.new: |%msg-args; + } + when 'JOIN' { + $msg = IRC::Client::Message::Join.new: + :channel( %args[0] ), |%msg-args; } + when 'NOTICE' { $msg = msg-notice %args, %msg-args } + when 'MODE' { $msg = msg-mode %args, %msg-args } + when 'PING' { $msg = IRC::Client::Message::Ping.new: |%msg-args; } + when 'PRIVMSG' { $msg = msg-privmsg %args, %msg-args } + default { $msg = IRC::Client::Message::Unknown.new: |%msg-args } } $match.make: $msg; } + +sub msg-privmsg (%args, %msg-args) { + %args[0] ~~ /^<[#&]>/ + and return IRC::Client::Message::Privmsg::Channel.new: + :channel( %args[0] ), + :text( %args[1] ), + |%msg-args; + + return IRC::Client::Message::Privmsg::Me.new: + :text( %args[1] ), + |%msg-args; +} + +sub msg-notice (%args, %msg-args) { + %args[0] ~~ /^<[#&]>/ + and return IRC::Client::Message::Notice::Channel.new: + :channel( %args[0] ), + :text( %args[1] ), + |%msg-args; + + return IRC::Client::Message::Notice::Me.new: + :text( %args[1] ), + |%msg-args; +} + +sub msg-mode (%args, %msg-args) { + if %args[0] ~~ /^<[#&]>/ { + my @modes; + for %args[1..*-1].join.comb: /\S/ { + state $sign; + /<[+-]>/ and $sign = $_ and next; + @modes.push: $sign => $_; + }; + return IRC::Client::Message::Mode::Channel.new: + :channel( %args[0] ), + :modes( @modes ), + |%msg-args; + } + else { + return IRC::Client::Message::Mode::Me.new: + :modes( %args[1..*-1].join.comb: /<[a..zA..Z]>/ ), + |%msg-args; + } +} -- cgit v1.1 From c56f8b4359f2730bb9e8bccd40bf2c9fa840f433 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sat, 4 Jun 2016 23:20:01 -0400 Subject: First working rewrite --- lib/IRC/Client/Grammar/Actions.pm6 | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'lib/IRC/Client/Grammar/Actions.pm6') diff --git a/lib/IRC/Client/Grammar/Actions.pm6 b/lib/IRC/Client/Grammar/Actions.pm6 index 6ebe33d..cf702f8 100644 --- a/lib/IRC/Client/Grammar/Actions.pm6 +++ b/lib/IRC/Client/Grammar/Actions.pm6 @@ -40,8 +40,8 @@ method message ($match) { irc => $!irc, nick => %args//'', server => $!server, + usermask => ~($match//''), username => %args//''; - . = . ~ '!' ~ . ~ '@' ~ . given %msg-args; my $msg; given %msg-args { @@ -53,11 +53,17 @@ method message ($match) { :channel( %args[0] ), |%msg-args; } - when 'NOTICE' { $msg = msg-notice %args, %msg-args } - when 'MODE' { $msg = msg-mode %args, %msg-args } - when 'PING' { $msg = IRC::Client::Message::Ping.new: |%msg-args; } - when 'PRIVMSG' { $msg = msg-privmsg %args, %msg-args } - default { $msg = IRC::Client::Message::Unknown.new: |%msg-args } + when 'PART' { + $msg = IRC::Client::Message::Part.new: + :channel( %args[0] ), + |%msg-args; + } + when 'NOTICE' { $msg = msg-notice %args, %msg-args } + when 'MODE' { $msg = msg-mode %args, %msg-args } + when 'PING' { $msg = IRC::Client::Message::Ping.new: |%msg-args } + when 'PRIVMSG' { $msg = msg-privmsg %args, %msg-args } + when 'QUIT' { $msg = IRC::Client::Message::Quit.new: |%msg-args } + default { $msg = IRC::Client::Message::Unknown.new: |%msg-args } } $match.make: $msg; -- cgit v1.1 From 140959e4f170d732d990e69b9a0ca129b89e3ac4 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sun, 5 Jun 2016 21:39:47 -0400 Subject: First working test --- lib/IRC/Client/Grammar/Actions.pm6 | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/IRC/Client/Grammar/Actions.pm6') diff --git a/lib/IRC/Client/Grammar/Actions.pm6 b/lib/IRC/Client/Grammar/Actions.pm6 index cf702f8..7c16227 100644 --- a/lib/IRC/Client/Grammar/Actions.pm6 +++ b/lib/IRC/Client/Grammar/Actions.pm6 @@ -58,6 +58,11 @@ method message ($match) { :channel( %args[0] ), |%msg-args; } + when 'NICK' { + $msg = IRC::Client::Message::Nick.new: + :new-nick( %args[0] ), + |%msg-args; + } when 'NOTICE' { $msg = msg-notice %args, %msg-args } when 'MODE' { $msg = msg-mode %args, %msg-args } when 'PING' { $msg = IRC::Client::Message::Ping.new: |%msg-args } -- cgit v1.1 From 18615cc9bb33801fbde2716513071e7b32af2ab2 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sun, 24 Jul 2016 16:20:12 -0400 Subject: moar work --- lib/IRC/Client/Grammar/Actions.pm6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/IRC/Client/Grammar/Actions.pm6') diff --git a/lib/IRC/Client/Grammar/Actions.pm6 b/lib/IRC/Client/Grammar/Actions.pm6 index 7c16227..b1fcc53 100644 --- a/lib/IRC/Client/Grammar/Actions.pm6 +++ b/lib/IRC/Client/Grammar/Actions.pm6 @@ -45,7 +45,7 @@ method message ($match) { my $msg; given %msg-args { - when /^ $=(<[0..9]>**3) $/ { + when /^ <[0..9]>**3 $/ { $msg = IRC::Client::Message::Numeric.new: |%msg-args; } when 'JOIN' { -- cgit v1.1