Archived
1
0
Fork 0

Rewrote the whole architecture.

This commit is contained in:
Julien Dessaux 2010-02-04 20:27:22 +01:00
parent d4103e3e18
commit 57f559f3a1
8 changed files with 230 additions and 210 deletions

View file

@ -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")