diff options
Diffstat (limited to 'Hsbot/IRCParser.hs')
-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") + |