summaryrefslogtreecommitdiff
path: root/Hsbot/IRCParser.hs
diff options
context:
space:
mode:
authorJulien Dessaux2010-02-04 20:27:22 +0100
committerJulien Dessaux2010-02-04 20:27:22 +0100
commit57f559f3a119b400e4f6288d3b5753185b8f19a7 (patch)
tree76bcd9a7e3980b8a79f64d46e5ae75a362dcd486 /Hsbot/IRCParser.hs
parentRebooting now works great, thanks to the communication channel preservation. (diff)
downloadhsbot-57f559f3a119b400e4f6288d3b5753185b8f19a7.tar.gz
hsbot-57f559f3a119b400e4f6288d3b5753185b8f19a7.tar.bz2
hsbot-57f559f3a119b400e4f6288d3b5753185b8f19a7.zip
Rewrote the whole architecture.
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")