- command0 :: IRCCommand [String] -> Either Error IRCCommand
- command0 c [] = Right c
- command0 c x = Left $ toString c +++ " doesn't have arguments"
-
- processParse :: [String] -> Either Error IRCCommand
- processParse [] = Left "Empty list of arguments"
- processParse [cmd:args] = case cmd of
- //"ADMIN" = (Maybe String)
- //"AWAY" = String
- //"CONNECT" = String (Maybe (Int, Maybe String))
- "DIE" = command0 DIE args
- //"ERROR" = String
- //"INFO" = (Maybe String)
- //"INVITE" = String String
- //"ISON" = [String]
- //"JOIN" = [(String, Maybe String)]
- //"KICK" = String String (Maybe String)
- //"KILL" = String String
- //"LINKS" = (Maybe (Maybe String, String))
- //"LIST" = (Maybe ([String], Maybe String))
- //"LUSERS" = (Maybe (String, Maybe String))
- //"MODE" = String String (Maybe String) (Maybe String) (Maybe String)
- //"MOTD" = (Maybe String)
- //"NAMES" = [String]
+ p = pSatisfy (const True)
+ lst = fmap $ 'Text'.split ","
+ opt = optional p
+ pInt = toInt <$> p
+
+ nn p f = pToken p >>| f
+
+ cmdParser :: Parser String IRCCommand
+ cmdParser =
+ (nn "ADMIN" $ fmap ADMIN opt)
+ <|> (nn "AWAY" $ fmap AWAY p)
+ <|> (nn "CONNECT" $ liftM2 CONNECT p (optional $ liftM2 tuple pInt opt))
+ <|> (nn "DIE" $ pure DIE)
+ <|> (nn "ERROR" $ fmap ERROR p)
+ <|> (nn "INFO" $ fmap INFO opt)
+ <|> (nn "INVITE" $ liftM2 INVITE p p)
+ <|> (nn "ISON" $ fmap ISON $ pMany p)
+// <|> (nn "JOIN" $ fmap JOIN $ lst p >>= \ch->lst p >>= \ks->pure (zip2 ch (ks ++ repeat Nothing)))
+ <|> (nn "KICK" $ liftM3 KICK p p opt)
+ <|> (nn "KILL" $ liftM2 KILL p p)
+ <|> (nn "LINKS" $ fmap LINKS $ optional $ liftM2 tuple opt p)
+ <|> (nn "LIST" $ fmap LIST $ optional $ liftM2 tuple ('Text'.split "," <$> p) opt)
+ <|> (nn "LUSERS" $ fmap LUSERS $ optional $ liftM2 tuple p opt)
+ <|> (nn "MODE" $ liftM5 MODE p p opt opt opt)
+ <|> (nn "MOTD" $ fmap MOTD $ opt)
+ <|> (nn "NAMES" $ fmap NAMES $ lst p)
+ <|> (nn "NICK" $ fmap NAMES $ lst p)