damnpacket-0.3.1: Parsing dAmn packets

Safe HaskellNone




Provides convenience functions for manipulating dAmn packets.


The Packet datatype

data Packet Source

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
by=name of setter

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"

type Arguments = Map Text TextSource

A type synonym--because pressing spacebar is pretty irritating.


pktSubpacket :: Packet -> Result 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.

pktArgsL :: Functor f => (Arguments -> f Arguments) -> Packet -> f PacketSource

A lens on pktArgs.


parse :: ByteString -> Result PacketSource

Parse some text, providing a packet or the reason for parse failure.

parse' :: ByteString -> Maybe PacketSource

Parse some text, discarding any failure message.

Rendering packets

render :: Packet -> ByteStringSource

render converts a packet back into the dAmn text format. This is used by pktSubpacketL to fulfill the lens laws, but you might find it useful if you want to write packets to dAmn.