module Hirc.Parser where import Data.Char import Hirc.Types import Text.Parsec import Text.Parsec.String message :: Parser Message message = Message <$> optionMaybe (char ':' *> prefix) <* spaces1 <*> command <*> params where spaces1 = skipMany1 space prefix = Prefix <$> nick <*> optionMaybe (char '!' *> user) <*> optionMaybe (char '@' *> host) nick = many1 (noneOf " !@") user = many1 (noneOf " !@") host = many1 (noneOf " !@") command = UnknownCommand <$> many1 nonspace params = many1 (spaces1 *> (trailing <|> middle)) trailing = char ':' *> many1 anyChar middle = many1 nonspace nonspace = satisfy (not . isSpace)