diff options
author | Julien Dessaux | 2009-08-13 00:07:08 +0200 |
---|---|---|
committer | Julien Dessaux | 2009-08-13 00:07:08 +0200 |
commit | dfd0b3dcd72a8efa84612a4ae925204f3e4526d8 (patch) | |
tree | 574665be7df16d203337ac807eddfd70a3ebcbf0 /Hsbot/IRCParser.hs | |
parent | Added server states, in order to handle rebooting more cleanly (still missing... (diff) | |
download | hsbot-dfd0b3dcd72a8efa84612a4ae925204f3e4526d8.tar.gz hsbot-dfd0b3dcd72a8efa84612a4ae925204f3e4526d8.tar.bz2 hsbot-dfd0b3dcd72a8efa84612a4ae925204f3e4526d8.zip |
Added the IRCParser (thx galdor), and PrivMsg handling (simply repeat)
Diffstat (limited to '')
-rw-r--r-- | Hsbot/IRCParser.hs | 36 |
1 files changed, 36 insertions, 0 deletions
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") + |