summaryrefslogtreecommitdiffstats
path: root/Hirc/Parser.hs
blob: 2cb2451836d62e19e7d7532b51eab8e83748603a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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)