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