summaryrefslogtreecommitdiffstats
path: root/Hirc/Parser.hs
blob: f52564b79bde95823ce71c843b5af1f12001e08f (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 = many1 nonspace
    params = many1 (spaces1 *> (trailing <|> middle))
    trailing = char ':' *> many anyChar
    middle = many1 nonspace
    nonspace = satisfy (not . isSpace)