Safe Haskell | None |
---|
Provides convenience functions for manipulating dAmn packets.
- data Packet = Packet {
- pktCommand :: Text
- pktParameter :: Maybe Text
- pktArgs :: Arguments
- pktBody :: Maybe Text
- type Arguments = Map Text Text
- pktSubpacket :: Packet -> Either String Packet
- pktSubpacket' :: Packet -> Maybe Packet
- pktCommandL :: Functor f => (Text -> f Text) -> Packet -> f Packet
- pktParameterL :: Functor f => (Maybe Text -> f (Maybe Text)) -> Packet -> f Packet
- pktArgsL :: Functor f => (Arguments -> f Arguments) -> Packet -> f Packet
- pktBodyL :: Functor f => (Maybe Text -> f (Maybe Text)) -> Packet -> f Packet
- pktSubpacketL :: Functor f => (Maybe Packet -> f (Maybe Packet)) -> Packet -> f Packet
- parse :: Text -> Either String Packet
- parse' :: Text -> Maybe Packet
- render :: Packet -> Text
The Packet datatype
Represents a dAmn packet.
Packets are comprised of a command, which is mandatory, and three other optional elements: a "parameter", an argument list, and a body. Any combination of the latter three (or none of them) is valid, so the parser is fairly lenient.
A packet with all four elements will look something like this:
property chat:SomeChatroom p=propertyName by=name of setter ts=timestamp value of property
Parsing this results in the packet:
Packet
{pktCommand
= "property" ,pktParameter
=Just
"chat:SomeChatroom" ,pktArgs
=fromList
[("p","propertyName"),("by","name of setter"),("ts","timestamp")] ,pktBody
=Just
"value of property" }
Subpackets
pktSubpacket :: Packet -> Either String PacketSource
Due to the way dAmn packets are designed, it's not possible to unambiguously determine whether a packet has a subpacket or just a body. Thus you will need to request a subpacket yourself.
pktSubpacket' :: Packet -> Maybe PacketSource
Use when you don't care about the reason for parse failure.
Packet lenses
pktCommandL :: Functor f => (Text -> f Text) -> Packet -> f PacketSource
A lens on pktCommand
.
pktParameterL :: Functor f => (Maybe Text -> f (Maybe Text)) -> Packet -> f PacketSource
A lens on pktParameter
.
pktBodyL :: Functor f => (Maybe Text -> f (Maybe Text)) -> Packet -> f PacketSource
A lens on pktBody
.
pktSubpacketL :: Functor f => (Maybe Packet -> f (Maybe Packet)) -> Packet -> f PacketSource
A lens on pktSubpacket'
.
Parsing
parse :: Text -> Either String PacketSource
Parse some text, providing a packet or the reason for parse failure.