From ccbd5ff10ce1fa1a2025a540635bc1c939484098 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sat, 5 Dec 2015 14:52:45 -0500 Subject: Barely-working grammar --- lib/IRC/Client.pm6 | 24 ++++++++++++------------ lib/IRC/Grammar.pm6 | 39 +++++++++++++++++++++++++++++++++++++++ lib/IRC/Grammar/Actions.pm6 | 6 ++++++ 3 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 lib/IRC/Grammar.pm6 create mode 100644 lib/IRC/Grammar/Actions.pm6 (limited to 'lib/IRC') diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index ae8f245..4635301 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -1,16 +1,16 @@ use v6; role IRC::Client::Plugin { ... } class IRC::Client:ver<1.001001> { - has Bool $.debug = False; - has Str $.host = 'localhost'; - has Int $.port where 0 <= $_ <= 65535 = 6667; - has Str $.nick where 1 <= .chars <= 9 = 'Perl6IRC'; - has Str $.username = 'Perl6IRC'; - has Str $.userhost = 'localhost'; - has Str $.userreal = 'Perl6 IRC Client'; - has Str @.channels = ['#perl6bot']; - has @.plugins = []; - has IO::Socket::Async $.sock; + has Bool:D $.debug = False; + has Str:D $.host = 'localhost'; + has Int:D $.port where 0 <= $_ <= 65535 = 6667; + has Str:D $.nick = 'Perl6IRC'; + has Str:D $.username = 'Perl6IRC'; + has Str:D $.userhost = 'localhost'; + has Str:D $.userreal = 'Perl6 IRC Client'; + has Str:D @.channels = ['#perl6bot']; + has IRC::Client::Plugin @.plugins = []; + has IO::Socket::Async $.sock; method run { await IO::Socket::Async.connect( $!host, $!port ).then({ @@ -23,8 +23,8 @@ class IRC::Client:ver<1.001001> { for @!plugins.grep(*.interval); react { - whenever $!sock.chars-supply -> $str is copy { - $str.say; + whenever $!sock.Supply -> $str is copy { + "[$str]".perl.say; .msg(self, $str) for @!plugins.grep(so *.msg); } } diff --git a/lib/IRC/Grammar.pm6 b/lib/IRC/Grammar.pm6 new file mode 100644 index 0000000..2013b9b --- /dev/null +++ b/lib/IRC/Grammar.pm6 @@ -0,0 +1,39 @@ +# use Grammar::Debugger; +unit grammar IRC::Grammar:ver<1.001001>; +token ws { ' ' } +token TOP { [ \r\n ]* } +token message { [':' ' '+ ]? } +token prefix { [ | ] [ '!' ]? [ '@' ]? } +token command { + | **3 } +token params { ' '+ [ ':' | ]? } +token middle { <-[: \0\r\n]> <-[ \0\r\n]>+ } +token trailing { <-[\0\r\n]>+ } +token target { [ ',' ]? } +token to { | '@' | | } +token channel { ['#' | '&'] } +token servername { \S+ } # see RFC 952 [DNS:4] for details on allowed hostnames +token nick { [ | | ]+ } +token mask { <[#$]> } +token chstring { <-[ \a\0\r\l,]> } +token user { <-[ \0\r\l]>+ } +token letter { <[a..zA..Z]> } +token number { <[0..9]> } +token special { <[-\[\]\\`^{}]> } + +# unit class IRC::Grammar::Actions:ver<1.001001>; +# method TOP ($/) { $/.make: $».made } +# method message ($/) { $/.make: +# prefix => $ .made, +# command => $.made, +# params => $ | ] [ '!' ]? [ '@' ]? } +# method command ($/) { + | **3 } +# method params ($/) { ' '+ [ ':' | ]? } +# method middle ($/) { <-[: \0\r\n]> <-[ \0\r\n]>+ } +# method trailing ($/) { <-[\0\r\n]> } +# +# method class ($/) { $/.make: ~$/ } +# method rules ($/) { $/.make: ~$/ } +# method pair ($/) { $/.make: $.made => $.made } +# method TOP ($/) { $/.make: $».made } diff --git a/lib/IRC/Grammar/Actions.pm6 b/lib/IRC/Grammar/Actions.pm6 new file mode 100644 index 0000000..039f11e --- /dev/null +++ b/lib/IRC/Grammar/Actions.pm6 @@ -0,0 +1,6 @@ +class IRC::Grammar::Actions { + method class ($/) { $/.make: ~$/ } + method rules ($/) { $/.make: ~$/ } + method pair ($/) { $/.make: $.made => $.made } + method TOP ($/) { $/.make: $».made } +} -- cgit v1.1