Archived
1
0
Fork 0

Reorganized code and types, changed slightly the architecture.

This commit is contained in:
Julien Dessaux 2010-02-04 20:36:58 +01:00
parent 57f559f3a1
commit 884c6c9f2e
10 changed files with 272 additions and 164 deletions

View file

@ -1,13 +1,13 @@
module Hsbot.IRCParser
( ParseError
, parseIrcMsg
, serializeIrcMsg
) where
import Control.Monad.Identity
-- import Data.List
import Text.Parsec
import Hsbot.Core
import Hsbot.Types
-- | Parses an IrcInput
parseIrcMsg :: String -> Either ParseError IrcMsg
@ -38,3 +38,14 @@ pLongParam = char ':' >> (many1 (noneOf "\r"))
pShortParam :: ParsecT String u Identity [Char]
pShortParam = many1 (noneOf " \r")
-- |Serialize an IRC message to a string.
serializeIrcMsg :: IrcMsg -> String
serializeIrcMsg (IrcMsg pfx cmd params) = pfxStr ++ cmd ++ paramStr
where pfxStr = case pfx of
Nothing -> ""
Just pfx' -> ":" ++ pfx' ++ " "
paramStr = concat (map paramToStr (init params)
++ [lastParamToStr (last params)])
paramToStr p = " " ++ p
lastParamToStr p = " :" ++ p