summaryrefslogtreecommitdiff
path: root/Hsbot/IRCParser.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Hsbot/IRCParser.hs')
-rw-r--r--Hsbot/IRCParser.hs26
1 files changed, 15 insertions, 11 deletions
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")