From dfd0b3dcd72a8efa84612a4ae925204f3e4526d8 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 13 Aug 2009 00:07:08 +0200 Subject: Added the IRCParser (thx galdor), and PrivMsg handling (simply repeat) --- Hsbot/IRCParser.hs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Hsbot/IRCParser.hs (limited to 'Hsbot/IRCParser.hs') diff --git a/Hsbot/IRCParser.hs b/Hsbot/IRCParser.hs new file mode 100644 index 0000000..a76e22a --- /dev/null +++ b/Hsbot/IRCParser.hs @@ -0,0 +1,36 @@ +module Hsbot.IRCParser + ( IrcMsg (..) + , ircParser + ) where + +--import Text.Parsec +import Text.ParserCombinators.Parsec + +-- |An IRC message. +data IrcMsg = IrcMsg (Maybe String) String [String] -- (Maybe first statement) cmd [chan, params/sentence] + deriving (Show) + +--ircParser :: String -> IrcInput +ircParser :: String -> Either ParseError IrcMsg +ircParser str = parse pMsg "" str + +pMsg = do + pfx <- optionMaybe pPrefix + cmd <- pCommand + params <- many (char ' ' >> (pLongParam <|> pShortParam)) + char '\r' + eof + return $ IrcMsg pfx cmd params + +pPrefix = do + char ':' + pfx <- many1 (noneOf " ") + space + return pfx + +pCommand = count 3 digit <|> many1 upper + +pLongParam = char ':' >> (many1 (noneOf "\r")) + +pShortParam = many1 (noneOf " \r") + -- cgit v1.2.3