]> gitweb.factorcode.org Git - factor.git/blob - extra/irc/messages/parser/parser.factor
core: Add words/unwords/unwords-as and use them.
[factor.git] / extra / irc / messages / parser / parser.factor
1 ! Copyright (C) 2009 Bruno Deferrari
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: kernel fry splitting ascii accessors combinators
4        arrays classes.tuple math.order words assocs
5        irc.messages.base sequences ;
6 IN: irc.messages.parser
7
8 <PRIVATE
9 : split-at-first ( seq separators -- before after )
10     dupd '[ _ member? ] find [ cut rest ] [ swap ] if ;
11
12 ! ":ircuser!n=user@isp.net JOIN :#factortest"
13 : split-message ( string -- prefix command parameters trailing )
14     ":" ?head [ " " split1 ] [ f swap ] if
15     ":" split1
16     [ words harvest unclip swap ] dip ;
17
18 : sender ( irc-message -- sender )
19     prefix>> [ ":" ?head drop "!" split-at-first drop ] [ f ] if* ;
20 PRIVATE>
21
22 : string>irc-message ( string -- irc-message )
23     dup split-message
24     [ [ irc>type new ] [ >>command ] bi ]
25     [ >>parameters ]
26     [ >>trailing ]
27     tri*
28     [ prefix<< ] [ fill-irc-message-slots ] [ swap >>line ] tri
29     dup sender >>sender ;