From 57f559f3a119b400e4f6288d3b5753185b8f19a7 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 4 Feb 2010 20:27:22 +0100 Subject: Rewrote the whole architecture. --- Hsbot/IRCParser.hs | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'Hsbot/IRCParser.hs') diff --git a/Hsbot/IRCParser.hs b/Hsbot/IRCParser.hs index a76e22a..5c1034e 100644 --- a/Hsbot/IRCParser.hs +++ b/Hsbot/IRCParser.hs @@ -1,36 +1,40 @@ module Hsbot.IRCParser - ( IrcMsg (..) - , ircParser + ( ParseError + , parseIrcMsg ) where ---import Text.Parsec -import Text.ParserCombinators.Parsec +import Control.Monad.Identity +-- import Data.List +import Text.Parsec --- |An IRC message. -data IrcMsg = IrcMsg (Maybe String) String [String] -- (Maybe first statement) cmd [chan, params/sentence] - deriving (Show) +import Hsbot.Core ---ircParser :: String -> IrcInput -ircParser :: String -> Either ParseError IrcMsg -ircParser str = parse pMsg "" str +-- | Parses an IrcInput +parseIrcMsg :: String -> Either ParseError IrcMsg +parseIrcMsg line = parse pMsg "" line +pMsg :: ParsecT String u Identity IrcMsg pMsg = do pfx <- optionMaybe pPrefix cmd <- pCommand params <- many (char ' ' >> (pLongParam <|> pShortParam)) - char '\r' + --char '\r' eof return $ IrcMsg pfx cmd params +pPrefix :: ParsecT String u Identity [Char] pPrefix = do char ':' pfx <- many1 (noneOf " ") space return pfx +pCommand :: ParsecT String u Identity [Char] pCommand = count 3 digit <|> many1 upper +pLongParam :: ParsecT String u Identity [Char] pLongParam = char ':' >> (many1 (noneOf "\r")) +pShortParam :: ParsecT String u Identity [Char] pShortParam = many1 (noneOf " \r") -- cgit v1.2.3