| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Data.THGen.XML
Description
Generate XML-isomorphic types from declarative descriptions.
There are two kinds of XML-isomorphic types: enumerations and records.
Enumerations are simple enum-types generated via Data.THGen.Enum
plus a FromContent instance and a ToXML instance which are derived
from Read and Show. Records are a bit more complicated: to define
a record you need to supply its name, a prefix for fields, and a list
of field descriptions. A field description contains the XML tag name
and repetition kind (mandatory, optional, repeated or multiplied).
The repetition kind determines both the parsing strategy and the wrapper around the field type:
afor mandatory fieldsMaybe afor optional fields[a]for repeated fieldsNonEmpty afor multiplied fields
Example 1.
"Color" =:= enum & "R" & "G" & "B"
produces
data XmlColor = XmlColorR | XmlColorG | XmlColorB | UnknownXmlColor String
with a FromContent instance that expects the current element content
to be either R, G or B.
Example 2.
"Message" =:= record ! "author" + "recipient" ? "message" [t|Text|] * "attachement"
produces
data Message = Message
{ _mAuthor :: Author
, _mRecipient :: NonEmpty Recipient
, _mMessage :: Maybe Text
, _mAttachement :: [Attachement]
} deriving (...)with a corresponding FromDom instance. Lenses are generated
automatically as well.
The examples above also demonstrate that to define the declarative descriptions of data types we provide a terse and convenient EDSL.
To define an enumeration, use the enum function followed by the name
of the data type to be generated. You can optionally specify if the
enumeration is exhaustive (contains only the listed constructors) or
non-exhaustive (also contains a constructor for unknown values; this
is the default):
"Enum1" Exhaustive =:= enum ...
"Enum2" NonExhaustive =:= enum ...
To define a record, use the record function followed by the name of
the data type to be generated. The prefix for the record fields is
inferred automatically by taking all of the uppercase letters in the
name. You can override it manually like so:
"Reference" "ref" =:= record ...
To describe a record field you must supply its name as it appears in the XML tag, prefixed by its repetition kind:
!for mandatory fields?for optional fields*for repeated fields+for multiplied fields
The type of the field is inferred automatically from its name, so
if the field is called "author" its type will be Author. You can
override the type by specifying it in quasiquotes like so:
"Message" =:= record ! "author" [t|Person|] ...
Synopsis
- data Exhaustiveness
- data PrefixName = PrefixName String String
- data ExhaustivenessName = ExhaustivenessName String Exhaustiveness
- record :: IsoXmlDescRecord
- enum :: IsoXmlDescEnum
- (!) :: IsoXmlDescRecord -> IsoXmlDescPreField -> IsoXmlDescRecord
- (?) :: IsoXmlDescRecord -> IsoXmlDescPreField -> IsoXmlDescRecord
- (*) :: IsoXmlDescRecord -> IsoXmlDescPreField -> IsoXmlDescRecord
- (+) :: IsoXmlDescRecord -> IsoXmlDescPreField -> IsoXmlDescRecord
- (!%) :: IsoXmlDescRecord -> IsoXmlDescPreAttribute -> IsoXmlDescRecord
- (?%) :: IsoXmlDescRecord -> IsoXmlDescPreAttribute -> IsoXmlDescRecord
- (&) :: IsoXmlDescEnum -> IsoXmlDescEnumCon -> IsoXmlDescEnum
- (=:=) :: Description name desc => name -> desc -> DecsQ
- data Text
- data Int
- data Integer
Documentation
data Exhaustiveness #
Constructors
| Exhaustive | |
| NonExhaustive |
Instances
| Eq Exhaustiveness # | |
Defined in Data.THGen.Enum Methods (==) :: Exhaustiveness -> Exhaustiveness -> Bool # (/=) :: Exhaustiveness -> Exhaustiveness -> Bool # | |
| Ord Exhaustiveness # | |
Defined in Data.THGen.Enum Methods compare :: Exhaustiveness -> Exhaustiveness -> Ordering # (<) :: Exhaustiveness -> Exhaustiveness -> Bool # (<=) :: Exhaustiveness -> Exhaustiveness -> Bool # (>) :: Exhaustiveness -> Exhaustiveness -> Bool # (>=) :: Exhaustiveness -> Exhaustiveness -> Bool # max :: Exhaustiveness -> Exhaustiveness -> Exhaustiveness # min :: Exhaustiveness -> Exhaustiveness -> Exhaustiveness # | |
| Show Exhaustiveness # | |
Defined in Data.THGen.Enum Methods showsPrec :: Int -> Exhaustiveness -> ShowS # show :: Exhaustiveness -> String # showList :: [Exhaustiveness] -> ShowS # | |
data PrefixName #
Constructors
| PrefixName String String |
Instances
| IsString PrefixName # | |
Defined in Data.THGen.XML Methods fromString :: String -> PrefixName # | |
| s ~ String => IsString (s -> PrefixName) # | |
Defined in Data.THGen.XML Methods fromString :: String -> s -> PrefixName # | |
data ExhaustivenessName #
Constructors
| ExhaustivenessName String Exhaustiveness |
Instances
| IsString ExhaustivenessName # | |
Defined in Data.THGen.XML Methods fromString :: String -> ExhaustivenessName # | |
| e ~ Exhaustiveness => IsString (e -> ExhaustivenessName) # | |
Defined in Data.THGen.XML Methods fromString :: String -> e -> ExhaustivenessName # | |
A space efficient, packed, unboxed Unicode text type.
Instances
| FromAttribute Text | |
Defined in Text.XML.DOM.Parser.FromAttribute | |
| FromDom Text | |
Defined in Text.XML.DOM.Parser.FromDom | |
| Ixed Text | |
Defined in Control.Lens.At | |
| AsEmpty Text | |
Defined in Control.Lens.Empty | |
| Reversing Text | |
Defined in Control.Lens.Internal.Iso | |
| ToXML Text | Don't use [Char] please, it will scare OverloadedStrings. |
Defined in Text.XML.Writer | |
| ToXmlAttribute Text # | |
Defined in Text.XML.ParentAttributes Methods toXmlAttribute :: Text -> Text # | |
| Strict Text Text | |
| (a ~ Char, b ~ Char) => Each Text Text a b |
|
| Cons Text Text Char Char | |
| Snoc Text Text Char Char | |
| type Item Text | |
| type Index Text | |
Defined in Control.Lens.At | |
| type IxValue Text | |
Defined in Control.Lens.At | |
A fixed-precision integer type with at least the range [-2^29 .. 2^29-1].
The exact range for a given implementation can be determined by using
minBound and maxBound from the Bounded class.
Instances
Invariant: Jn# and Jp# are used iff value doesn't fit in S#
Useful properties resulting from the invariants:
Instances
| Enum Integer | Since: base-2.1 |
| Eq Integer | |
| Integral Integer | Since: base-2.0.1 |
Defined in GHC.Real | |
| Num Integer | Since: base-2.1 |
| Ord Integer | |
| Read Integer | Since: base-2.1 |
| Real Integer | Since: base-2.0.1 |
Defined in GHC.Real Methods toRational :: Integer -> Rational # | |
| Show Integer | Since: base-2.1 |
| Lift Integer | |
| Arbitrary Integer | |
| CoArbitrary Integer | |
Defined in Test.QuickCheck.Arbitrary Methods coarbitrary :: Integer -> Gen b -> Gen b # | |
| NFData Integer | |
Defined in Control.DeepSeq | |
| FromAttribute Integer | |
Defined in Text.XML.DOM.Parser.FromAttribute | |
| FromDom Integer | |
Defined in Text.XML.DOM.Parser.FromDom | |
| ToXML Integer | |
Defined in Text.XML.Writer | |
| ToXmlAttribute Integer # | |
Defined in Text.XML.ParentAttributes Methods toXmlAttribute :: Integer -> Text # | |
| KnownNat n => Reifies (n :: Nat) Integer | |
Defined in Data.Reflection | |