factor/extra/irc/messages/parser/parser.factor

30 lines
959 B
Factor
Raw Normal View History

2009-03-05 20:11:46 -05:00
! Copyright (C) 2009 Bruno Deferrari
! See http://factorcode.org/license.txt for BSD license.
USING: kernel fry splitting ascii accessors combinators
2009-03-05 20:11:46 -05:00
arrays classes.tuple math.order words assocs
irc.messages.base sequences ;
IN: irc.messages.parser
<PRIVATE
: split-at-first ( seq separators -- before after )
dupd '[ _ member? ] find [ cut rest ] [ swap ] if ;
2009-03-05 20:11:46 -05:00
2016-05-09 14:49:19 -04:00
! ":ircuser!n=user@isp.net JOIN :#factortest"
2009-03-05 20:11:46 -05:00
: split-message ( string -- prefix command parameters trailing )
2016-05-09 14:49:19 -04:00
":" ?head [ " " split1 ] [ f swap ] if
":" split1
[ " " split harvest unclip swap ] dip ;
2009-03-05 20:11:46 -05:00
: sender ( irc-message -- sender )
2016-05-09 14:49:19 -04:00
prefix>> [ ":" ?head drop "!" split-at-first drop ] [ f ] if* ;
2009-03-05 20:11:46 -05:00
PRIVATE>
: string>irc-message ( string -- irc-message )
dup split-message
[ [ irc>type new ] [ >>command ] bi ]
[ >>parameters ]
[ >>trailing ]
tri*
[ prefix<< ] [ fill-irc-message-slots ] [ swap >>line ] tri
dup sender >>sender ;