git.iko.soy/typeable/xsd-isogen
on master help sign in
34 files changed+839−39
since splitsnapshots
unifiedsplit
cabal.project+1−1 golden/README+3 golden/ambig.xsd+20 golden/ambig.xsd.hs+39 golden/ambig1.xsd+16 golden/ambig1.xsd.hs+39 golden/enum.xsd+12 golden/enum.xsd.hs+25 golden/extension.xsd+36 golden/extension.xsd.hs+83 golden/extension_dep.xsd+31 golden/extension_dep.xsd.hs+101 golden/import.xsd+16 golden/import.xsd.hs+33 golden/import_ambig.xsd+26 golden/import_ambig.xsd.hs+50 golden/imported.xsd+9 golden/imported.xsd.hs+27 golden/include.xsd+5 golden/include.xsd.hs+27 golden/included.xsd+6 golden/included.xsd.hs+27 golden/seq.xsd+14 golden/seq.xsd.hs+34 golden/simple.xsd+25 golden/simple.xsd.hs+40 golden/test.sh+5 src/BuiltInTypes.hs+2−2 src/Gen.hs+8−3 src/Main.hs+46−23 src/Options.hs+5−5 src/References.hs+15−4 stack.yaml+12 xsd-isogen.cabal+1−1
cabal.project+1−1
@@ -3,4 +3,4 @@ packages: .
33source-repository-package
44 type: git
55 location: https://github.com/typeable/xsd-parser.git
6− tag: 2ec49b8f0c560fdc411850d71b8724be1526e798
6+ tag: e08a37cf08674a492407b9b7f4a61e8faedb1590
golden/READMEnew file+3
@@ -0,0 +1,3 @@
1+To use the golden tests, cd to this folder and run test.sh. It will run
2+xsd-isogen on each xsd file here. Then use git diff to check the
3+difference.
golden/ambig.xsdnew file+20
@@ -0,0 +1,20 @@
1+<?xml version="1.0"?>
2+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+ <xs:simpleType name="stringtype">
4+ <xs:restriction base="xs:string"/>
5+ </xs:simpleType>
6+ <xs:element name="Aa">
7+ <xs:complexType>
8+ <xs:sequence>
9+ <xs:element name="firstName" type="stringtype"/>
10+ </xs:sequence>
11+ </xs:complexType>
12+ </xs:element>
13+ <xs:element name="Ab">
14+ <xs:complexType>
15+ <xs:sequence>
16+ <xs:element name="firstName" type="stringtype"/>
17+ </xs:sequence>
18+ </xs:complexType>
19+ </xs:element>
20+</xs:schema>
golden/ambig.xsd.hsnew file+39
@@ -0,0 +1,39 @@
1+-- This file was generated by xsd-isogen version 0.1.0.0
2+-- https://github.com/dredozubov/xsd-isogen
3+
4+{-# OPTIONS_GHC -Wno-unused-imports #-}
5+module Dummy where
6+
7+import Control.DeepSeq
8+import Data.Scientific
9+import Data.THGen.XML
10+import Text.XML.DOM.Parser
11+import Text.XML.Writer
12+import Text.XML.ParentAttributes
13+import Prelude hiding ((*), (+))
14+
15+
16+{-|
17+Generated from: stringtype
18+-}
19+newtype XmlStringtype
20+ = XmlStringtype
21+ { unXmlStringtype :: Text
22+ } deriving (Show, Eq, NFData, ToXML)
23+
24+instance FromDom XmlStringtype where
25+ fromDom = XmlStringtype <$> fromDom
26+
27+{-|
28+Generated from: Aa
29+-}
30+"Aa" =:= record ParserAndGenerator
31+ ! "firstName" [t|XmlStringtype|]
32+
33+{-|
34+Generated from: Ab
35+-}
36+"Ab1" =:= record ParserAndGenerator
37+ ! "firstName" [t|XmlStringtype|]
38+
39+
golden/ambig1.xsdnew file+16
@@ -0,0 +1,16 @@
1+<?xml version="1.0"?>
2+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+ <xs:simpleType name="stringtype">
4+ <xs:restriction base="xs:string"/>
5+ </xs:simpleType>
6+ <xs:complexType name="Aa">
7+ <xs:sequence>
8+ <xs:element name="firstName" type="stringtype"/>
9+ </xs:sequence>
10+ </xs:complexType>
11+ <xs:complexType name="Ab">
12+ <xs:sequence>
13+ <xs:element name="firstName" type="stringtype"/>
14+ </xs:sequence>
15+ </xs:complexType>
16+</xs:schema>
golden/ambig1.xsd.hsnew file+39
@@ -0,0 +1,39 @@
1+-- This file was generated by xsd-isogen version 0.1.0.0
2+-- https://github.com/dredozubov/xsd-isogen
3+
4+{-# OPTIONS_GHC -Wno-unused-imports #-}
5+module Dummy where
6+
7+import Control.DeepSeq
8+import Data.Scientific
9+import Data.THGen.XML
10+import Text.XML.DOM.Parser
11+import Text.XML.Writer
12+import Text.XML.ParentAttributes
13+import Prelude hiding ((*), (+))
14+
15+
16+{-|
17+Generated from: stringtype
18+-}
19+newtype XmlStringtype
20+ = XmlStringtype
21+ { unXmlStringtype :: Text
22+ } deriving (Show, Eq, NFData, ToXML)
23+
24+instance FromDom XmlStringtype where
25+ fromDom = XmlStringtype <$> fromDom
26+
27+{-|
28+Generated from: Aa
29+-}
30+"Aa" =:= record ParserAndGenerator
31+ ! "firstName" [t|XmlStringtype|]
32+
33+{-|
34+Generated from: Ab
35+-}
36+"Ab1" =:= record ParserAndGenerator
37+ ! "firstName" [t|XmlStringtype|]
38+
39+
golden/enum.xsdnew file+12
@@ -0,0 +1,12 @@
1+<?xml version="1.0"?>
2+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+ <xs:simpleType name="stringtype">
4+ <xs:annotation>
5+ <xs:documentation>Blah</xs:documentation>
6+ </xs:annotation>
7+ <xs:restriction base="xs:string">
8+ <xs:enumeration value="day"/>
9+ <xs:enumeration value="night"/>
10+ </xs:restriction>
11+ </xs:simpleType>
12+</xs:schema>
golden/enum.xsd.hsnew file+25
@@ -0,0 +1,25 @@
1+-- This file was generated by xsd-isogen version 0.1.0.0
2+-- https://github.com/dredozubov/xsd-isogen
3+
4+{-# OPTIONS_GHC -Wno-unused-imports #-}
5+module Dummy where
6+
7+import Control.DeepSeq
8+import Data.Scientific
9+import Data.THGen.XML
10+import Text.XML.DOM.Parser
11+import Text.XML.Writer
12+import Text.XML.ParentAttributes
13+import Prelude hiding ((*), (+))
14+
15+
16+{-|
17+Generated from: stringtype
18+
19+Blah
20+-}
21+"Stringtype" Exhaustive =:= enum ParserAndGenerator
22+ & "Day"
23+ & "Night"
24+
25+
golden/extension.xsdnew file+36
@@ -0,0 +1,36 @@
1+<?xml version="1.0"?>
2+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+ <xs:complexType name="some">
4+ <xs:sequence>
5+ <xs:element name="a" type="xs:string"/>
6+ </xs:sequence>
7+ </xs:complexType>
8+ <xs:complexType name="basetype">
9+ <xs:sequence>
10+ <xs:element name="a" type="xs:string"/>
11+ </xs:sequence>
12+ </xs:complexType>
13+ <xs:complexType name="ext1">
14+ <xs:complexContent>
15+ <xs:extension base="basetype">
16+ <xs:sequence>
17+ <xs:element name="b" type="xs:int"/>
18+ </xs:sequence>
19+ </xs:extension>
20+ </xs:complexContent>
21+ </xs:complexType>
22+ <xs:complexType name="ext2">
23+ <xs:complexContent>
24+ <xs:extension base="basetype">
25+ <xs:sequence>
26+ <xs:element name="c" type="xs:int"/>
27+ </xs:sequence>
28+ </xs:extension>
29+ </xs:complexContent>
30+ </xs:complexType>
31+ <xs:complexType name="other">
32+ <xs:sequence>
33+ <xs:element name="a" type="basetype"/>
34+ </xs:sequence>
35+ </xs:complexType>
36+</xs:schema>
golden/extension.xsd.hsnew file+83
@@ -0,0 +1,83 @@
1+-- This file was generated by xsd-isogen version 0.1.0.0
2+-- https://github.com/dredozubov/xsd-isogen
3+
4+{-# OPTIONS_GHC -Wno-unused-imports #-}
5+module Dummy where
6+
7+import Control.DeepSeq
8+import Data.Scientific
9+import Data.THGen.XML
10+import Text.XML.DOM.Parser
11+import Text.XML.Writer
12+import Text.XML.ParentAttributes
13+import Prelude hiding ((*), (+))
14+
15+
16+{-|
17+Generated from: basetype
18+-}
19+"Basetype" =:= record ParserAndGenerator
20+ ! "a" [t|Text|]
21+
22+{-|
23+Generated from: ext2
24+-}
25+"Ext2" =:= record ParserAndGenerator
26+ ! "a" [t|Text|]
27+ ! "c" [t|Integer|]
28+
29+{-|
30+Generated from: ext1
31+-}
32+"Ext1" =:= record ParserAndGenerator
33+ ! "a" [t|Text|]
34+ ! "b" [t|Integer|]
35+
36+data AnyXmlBasetype
37+ = TheXmlBasetype !XmlBasetype
38+ | TheXmlExt2 !XmlExt2
39+ | TheXmlExt1 !XmlExt1
40+ deriving (Eq, Show)
41+
42+instance NFData AnyXmlBasetype where
43+ rnf = rwhnf
44+
45+instance FromDom AnyXmlBasetype where
46+ fromDom = do
47+ tp <- parseAttribute
48+ (matchName "{http://www.w3.org/2001/XMLSchema-instance}type")
49+ Right
50+ case tp of
51+ "Basetype" -> TheXmlBasetype <$> fromDom
52+ "Ext2" -> TheXmlExt2 <$> fromDom
53+ "Ext1" -> TheXmlExt1 <$> fromDom
54+ _ -> throwParserError (PEOther "Unexpected type")
55+
56+instance ToXML AnyXmlBasetype where
57+ toXML (TheXmlBasetype a) = toXML a
58+ toXML (TheXmlExt2 a) = toXML a
59+ toXML (TheXmlExt1 a) = toXML a
60+
61+instance ToXmlParentAttributes AnyXmlBasetype where
62+ toXmlParentAttributes (TheXmlBasetype a) =
63+ ("{http://www.w3.org/2001/XMLSchema-instance}type", "Basetype")
64+ : toXmlParentAttributes a
65+ toXmlParentAttributes (TheXmlExt2 a) =
66+ ("{http://www.w3.org/2001/XMLSchema-instance}type", "Ext2")
67+ : toXmlParentAttributes a
68+ toXmlParentAttributes (TheXmlExt1 a) =
69+ ("{http://www.w3.org/2001/XMLSchema-instance}type", "Ext1")
70+ : toXmlParentAttributes a
71+{-|
72+Generated from: other
73+-}
74+"Other" =:= record ParserAndGenerator
75+ ! "a" [t|AnyXmlBasetype|]
76+
77+{-|
78+Generated from: some
79+-}
80+"Some" =:= record ParserAndGenerator
81+ ! "a" [t|Text|]
82+
83+
golden/extension_dep.xsdnew file+31
@@ -0,0 +1,31 @@
1+<?xml version="1.0"?>
2+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+ <xs:complexType name="X">
4+ <xs:sequence>
5+ <xs:element name="s" type="xs:string"/>
6+ </xs:sequence>
7+ </xs:complexType>
8+ <xs:complexType name="B">
9+ <xs:sequence>
10+ <xs:element name="s" type="xs:string"/>
11+ </xs:sequence>
12+ </xs:complexType>
13+ <xs:complexType name="C">
14+ <xs:complexContent>
15+ <xs:extension base="B">
16+ <xs:sequence>
17+ <xs:element name="x" type="X"/>
18+ </xs:sequence>
19+ </xs:extension>
20+ </xs:complexContent>
21+ </xs:complexType>
22+ <xs:complexType name="A">
23+ <xs:complexContent>
24+ <xs:extension base="C">
25+ <xs:sequence>
26+ <xs:element name="i" type="xs:int"/>
27+ </xs:sequence>
28+ </xs:extension>
29+ </xs:complexContent>
30+ </xs:complexType>
31+</xs:schema>
golden/extension_dep.xsd.hsnew file+101
@@ -0,0 +1,101 @@
1+-- This file was generated by xsd-isogen version 0.1.0.0
2+-- https://github.com/dredozubov/xsd-isogen
3+
4+{-# OPTIONS_GHC -Wno-unused-imports #-}
5+module Dummy where
6+
7+import Control.DeepSeq
8+import Data.Scientific
9+import Data.THGen.XML
10+import Text.XML.DOM.Parser
11+import Text.XML.Writer
12+import Text.XML.ParentAttributes
13+import Prelude hiding ((*), (+))
14+
15+
16+{-|
17+Generated from: X
18+-}
19+"X" =:= record ParserAndGenerator
20+ ! "s" [t|Text|]
21+
22+{-|
23+Generated from: A
24+-}
25+"A" =:= record ParserAndGenerator
26+ ! "s" [t|Text|]
27+ ! "x" [t|XmlX|]
28+ ! "i" [t|Integer|]
29+
30+{-|
31+Generated from: B
32+-}
33+"B" =:= record ParserAndGenerator
34+ ! "s" [t|Text|]
35+
36+{-|
37+Generated from: C
38+-}
39+"C" =:= record ParserAndGenerator
40+ ! "s" [t|Text|]
41+ ! "x" [t|XmlX|]
42+
43+data AnyXmlC
44+ = TheXmlC !XmlC
45+ | TheXmlA !XmlA
46+ deriving (Eq, Show)
47+
48+instance NFData AnyXmlC where
49+ rnf = rwhnf
50+
51+instance FromDom AnyXmlC where
52+ fromDom = do
53+ tp <- parseAttribute
54+ (matchName "{http://www.w3.org/2001/XMLSchema-instance}type")
55+ Right
56+ case tp of
57+ "C" -> TheXmlC <$> fromDom
58+ "A" -> TheXmlA <$> fromDom
59+ _ -> throwParserError (PEOther "Unexpected type")
60+
61+instance ToXML AnyXmlC where
62+ toXML (TheXmlC a) = toXML a
63+ toXML (TheXmlA a) = toXML a
64+
65+instance ToXmlParentAttributes AnyXmlC where
66+ toXmlParentAttributes (TheXmlC a) =
67+ ("{http://www.w3.org/2001/XMLSchema-instance}type", "C")
68+ : toXmlParentAttributes a
69+ toXmlParentAttributes (TheXmlA a) =
70+ ("{http://www.w3.org/2001/XMLSchema-instance}type", "A")
71+ : toXmlParentAttributes a
72+data AnyXmlB
73+ = TheXmlB !XmlB
74+ | TheAnyXmlC !AnyXmlC
75+ deriving (Eq, Show)
76+
77+instance NFData AnyXmlB where
78+ rnf = rwhnf
79+
80+instance FromDom AnyXmlB where
81+ fromDom = do
82+ tp <- parseAttribute
83+ (matchName "{http://www.w3.org/2001/XMLSchema-instance}type")
84+ Right
85+ case tp of
86+ "B" -> TheXmlB <$> fromDom
87+ "C" -> TheAnyXmlC <$> fromDom
88+ _ -> throwParserError (PEOther "Unexpected type")
89+
90+instance ToXML AnyXmlB where
91+ toXML (TheXmlB a) = toXML a
92+ toXML (TheAnyXmlC a) = toXML a
93+
94+instance ToXmlParentAttributes AnyXmlB where
95+ toXmlParentAttributes (TheXmlB a) =
96+ ("{http://www.w3.org/2001/XMLSchema-instance}type", "B")
97+ : toXmlParentAttributes a
98+ toXmlParentAttributes (TheAnyXmlC a) =
99+ ("{http://www.w3.org/2001/XMLSchema-instance}type", "C")
100+ : toXmlParentAttributes a
101+
golden/import.xsdnew file+16
@@ -0,0 +1,16 @@
1+<?xml version="1.0"?>
2+<xs:schema
3+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+ xmlns:my="uri:my"
5+ xmlns:my1="uri:my1"
6+ targetNamespace="uri:my1"
7+ >
8+ <xs:import schemaLocation="imported.xsd" namespace="uri:my"/>
9+ <xs:element name="person">
10+ <xs:complexType>
11+ <xs:sequence>
12+ <xs:element name="name" type="my:stringtype"/>
13+ </xs:sequence>
14+ </xs:complexType>
15+ </xs:element>
16+</xs:schema>
golden/import.xsd.hsnew file+33
@@ -0,0 +1,33 @@
1+-- This file was generated by xsd-isogen version 0.1.0.0
2+-- https://github.com/dredozubov/xsd-isogen
3+
4+{-# OPTIONS_GHC -Wno-unused-imports #-}
5+module Dummy where
6+
7+import Control.DeepSeq
8+import Data.Scientific
9+import Data.THGen.XML
10+import Text.XML.DOM.Parser
11+import Text.XML.Writer
12+import Text.XML.ParentAttributes
13+import Prelude hiding ((*), (+))
14+
15+
16+{-|
17+Generated from: uri:my:stringtype
18+-}
19+newtype XmlStringtype
20+ = XmlStringtype
21+ { unXmlStringtype :: Text
22+ } deriving (Show, Eq, NFData, ToXML)
23+
24+instance FromDom XmlStringtype where
25+ fromDom = XmlStringtype <$> fromDom
26+
27+{-|
28+Generated from: uri:my1:person
29+-}
30+"Person" =:= record ParserAndGenerator
31+ ! "{uri:my1}name" [t|XmlStringtype|]
32+
33+
golden/import_ambig.xsdnew file+26
@@ -0,0 +1,26 @@
1+<?xml version="1.0"?>
2+<xs:schema
3+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+ xmlns:my="uri:my"
5+ xmlns:my1="uri:my1"
6+ targetNamespace="uri:my1"
7+ >
8+ <xs:import schemaLocation="imported.xsd" namespace="uri:my"/>
9+ <xs:simpleType name="stringtype">
10+ <xs:restriction base="xs:string"/>
11+ </xs:simpleType>
12+ <xs:element name="AaBb">
13+ <xs:complexType>
14+ <xs:sequence>
15+ <xs:element name="name" type="my:stringtype"/>
16+ </xs:sequence>
17+ </xs:complexType>
18+ </xs:element>
19+ <xs:element name="AaBc">
20+ <xs:complexType>
21+ <xs:sequence>
22+ <xs:element name="name" type="my1:stringtype"/>
23+ </xs:sequence>
24+ </xs:complexType>
25+ </xs:element>
26+</xs:schema>
golden/import_ambig.xsd.hsnew file+50
@@ -0,0 +1,50 @@
1+-- This file was generated by xsd-isogen version 0.1.0.0
2+-- https://github.com/dredozubov/xsd-isogen
3+
4+{-# OPTIONS_GHC -Wno-unused-imports #-}
5+module Dummy where
6+
7+import Control.DeepSeq
8+import Data.Scientific
9+import Data.THGen.XML
10+import Text.XML.DOM.Parser
11+import Text.XML.Writer
12+import Text.XML.ParentAttributes
13+import Prelude hiding ((*), (+))
14+
15+
16+{-|
17+Generated from: uri:my:stringtype
18+-}
19+newtype XmlStringtype
20+ = XmlStringtype
21+ { unXmlStringtype :: Text
22+ } deriving (Show, Eq, NFData, ToXML)
23+
24+instance FromDom XmlStringtype where
25+ fromDom = XmlStringtype <$> fromDom
26+
27+{-|
28+Generated from: uri:my1:AaBb
29+-}
30+"AaBb" =:= record ParserAndGenerator
31+ ! "{uri:my1}name" [t|XmlStringtype|]
32+
33+{-|
34+Generated from: uri:my1:stringtype
35+-}
36+newtype XmlStringtype1
37+ = XmlStringtype1
38+ { unXmlStringtype1 :: Text
39+ } deriving (Show, Eq, NFData, ToXML)
40+
41+instance FromDom XmlStringtype1 where
42+ fromDom = XmlStringtype1 <$> fromDom
43+
44+{-|
45+Generated from: uri:my1:AaBc
46+-}
47+"AaBc1" =:= record ParserAndGenerator
48+ ! "{uri:my1}name" [t|XmlStringtype1|]
49+
50+
golden/imported.xsdnew file+9
@@ -0,0 +1,9 @@
1+<?xml version="1.0"?>
2+<xs:schema
3+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+ targetNamespace="uri:my"
5+ >
6+ <xs:simpleType name="stringtype">
7+ <xs:restriction base="xs:string"/>
8+ </xs:simpleType>
9+</xs:schema>
golden/imported.xsd.hsnew file+27
@@ -0,0 +1,27 @@
1+-- This file was generated by xsd-isogen version 0.1.0.0
2+-- https://github.com/dredozubov/xsd-isogen
3+
4+{-# OPTIONS_GHC -Wno-unused-imports #-}
5+module Dummy where
6+
7+import Control.DeepSeq
8+import Data.Scientific
9+import Data.THGen.XML
10+import Text.XML.DOM.Parser
11+import Text.XML.Writer
12+import Text.XML.ParentAttributes
13+import Prelude hiding ((*), (+))
14+
15+
16+{-|
17+Generated from: uri:my:stringtype
18+-}
19+newtype XmlStringtype
20+ = XmlStringtype
21+ { unXmlStringtype :: Text
22+ } deriving (Show, Eq, NFData, ToXML)
23+
24+instance FromDom XmlStringtype where
25+ fromDom = XmlStringtype <$> fromDom
26+
27+
golden/include.xsdnew file+5
@@ -0,0 +1,5 @@
1+<?xml version="1.0"?>
2+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+ <xs:include schemaLocation="included.xsd"/>
4+ <xs:element name="name" type="stringtype"/>
5+</xs:schema>
golden/include.xsd.hsnew file+27
@@ -0,0 +1,27 @@
1+-- This file was generated by xsd-isogen version 0.1.0.0
2+-- https://github.com/dredozubov/xsd-isogen
3+
4+{-# OPTIONS_GHC -Wno-unused-imports #-}
5+module Dummy where
6+
7+import Control.DeepSeq
8+import Data.Scientific
9+import Data.THGen.XML
10+import Text.XML.DOM.Parser
11+import Text.XML.Writer
12+import Text.XML.ParentAttributes
13+import Prelude hiding ((*), (+))
14+
15+
16+{-|
17+Generated from: stringtype
18+-}
19+newtype XmlStringtype
20+ = XmlStringtype
21+ { unXmlStringtype :: Text
22+ } deriving (Show, Eq, NFData, ToXML)
23+
24+instance FromDom XmlStringtype where
25+ fromDom = XmlStringtype <$> fromDom
26+
27+
golden/included.xsdnew file+6
@@ -0,0 +1,6 @@
1+<?xml version="1.0"?>
2+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+ <xs:simpleType name="stringtype">
4+ <xs:restriction base="xs:string"/>
5+ </xs:simpleType>
6+</xs:schema>
golden/included.xsd.hsnew file+27
@@ -0,0 +1,27 @@
1+-- This file was generated by xsd-isogen version 0.1.0.0
2+-- https://github.com/dredozubov/xsd-isogen
3+
4+{-# OPTIONS_GHC -Wno-unused-imports #-}
5+module Dummy where
6+
7+import Control.DeepSeq
8+import Data.Scientific
9+import Data.THGen.XML
10+import Text.XML.DOM.Parser
11+import Text.XML.Writer
12+import Text.XML.ParentAttributes
13+import Prelude hiding ((*), (+))
14+
15+
16+{-|
17+Generated from: stringtype
18+-}
19+newtype XmlStringtype
20+ = XmlStringtype
21+ { unXmlStringtype :: Text
22+ } deriving (Show, Eq, NFData, ToXML)
23+
24+instance FromDom XmlStringtype where
25+ fromDom = XmlStringtype <$> fromDom
26+
27+
golden/seq.xsdnew file+14
@@ -0,0 +1,14 @@
1+<?xml version="1.0"?>
2+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+ <xs:simpleType name="str">
4+ <xs:restriction base="xs:string"/>
5+ </xs:simpleType>
6+ <xs:element name="customer">
7+ <xs:complexType>
8+ <xs:sequence>
9+ <xs:element name="firstName" type="str"/>
10+ <xs:element name="lastName" type="str"/>
11+ </xs:sequence>
12+ </xs:complexType>
13+ </xs:element>
14+</xs:schema>
golden/seq.xsd.hsnew file+34
@@ -0,0 +1,34 @@
1+-- This file was generated by xsd-isogen version 0.1.0.0
2+-- https://github.com/dredozubov/xsd-isogen
3+
4+{-# OPTIONS_GHC -Wno-unused-imports #-}
5+module Dummy where
6+
7+import Control.DeepSeq
8+import Data.Scientific
9+import Data.THGen.XML
10+import Text.XML.DOM.Parser
11+import Text.XML.Writer
12+import Text.XML.ParentAttributes
13+import Prelude hiding ((*), (+))
14+
15+
16+{-|
17+Generated from: str
18+-}
19+newtype XmlStr
20+ = XmlStr
21+ { unXmlStr :: Text
22+ } deriving (Show, Eq, NFData, ToXML)
23+
24+instance FromDom XmlStr where
25+ fromDom = XmlStr <$> fromDom
26+
27+{-|
28+Generated from: customer
29+-}
30+"Customer" =:= record ParserAndGenerator
31+ ! "firstName" [t|XmlStr|]
32+ ! "lastName" [t|XmlStr|]
33+
34+
golden/simple.xsdnew file+25
@@ -0,0 +1,25 @@
1+<?xml version="1.0"?>
2+<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
3+ <xs:simpleType name="stringtype">
4+ <xs:annotation>
5+ <xs:documentation>Blah</xs:documentation>
6+ </xs:annotation>
7+ <xs:restriction base="xs:string"/>
8+ </xs:simpleType>
9+ <xs:element name="name" type="stringtype"/>
10+ <xs:element name="a">
11+ <xs:annotation>
12+ <xs:documentation>A blah</xs:documentation>
13+ </xs:annotation>
14+ <xs:complexType>
15+ <xs:sequence>
16+ <xs:element name="a" type="stringtype"/>
17+ <xs:element name="b" minOccurs="1" type="stringtype"/>
18+ <xs:element name="c" minOccurs="0" maxOccurs="1" type="stringtype"/>
19+ <xs:element name="d" minOccurs="1" maxOccurs="2" type="stringtype"/>
20+ <xs:element name="e" minOccurs="1" maxOccurs="unbounded" type="stringtype"/>
21+ <xs:element name="f" type="xs:decimal"/>
22+ </xs:sequence>
23+ </xs:complexType>
24+ </xs:element>
25+</xs:schema>
golden/simple.xsd.hsnew file+40
@@ -0,0 +1,40 @@
1+-- This file was generated by xsd-isogen version 0.1.0.0
2+-- https://github.com/dredozubov/xsd-isogen
3+
4+{-# OPTIONS_GHC -Wno-unused-imports #-}
5+module Dummy where
6+
7+import Control.DeepSeq
8+import Data.Scientific
9+import Data.THGen.XML
10+import Text.XML.DOM.Parser
11+import Text.XML.Writer
12+import Text.XML.ParentAttributes
13+import Prelude hiding ((*), (+))
14+
15+
16+{-|
17+Generated from: stringtype
18+
19+Blah
20+-}
21+newtype XmlStringtype
22+ = XmlStringtype
23+ { unXmlStringtype :: Text
24+ } deriving (Show, Eq, NFData, ToXML)
25+
26+instance FromDom XmlStringtype where
27+ fromDom = XmlStringtype <$> fromDom
28+
29+{-|
30+Generated from: a
31+-}
32+"A" =:= record ParserAndGenerator
33+ ! "a" [t|XmlStringtype|]
34+ ! "b" [t|XmlStringtype|]
35+ ? "c" [t|XmlStringtype|]
36+ + "d" [t|XmlStringtype|]
37+ + "e" [t|XmlStringtype|]
38+ ! "f" [t|Scientific|]
39+
40+
golden/test.shnew file+5
@@ -0,0 +1,5 @@
1+#!/bin/bash
2+
3+for file in *.xsd; do
4+ cabal run -v0 xsd-isogen -- -i $file > $file.hs
5+done
src/BuiltInTypes.hs+2−2
@@ -20,7 +20,7 @@ builtInTypes = Map.fromList . map qualify $
2020 , ("date", "Date")
2121 , ("dateTime", "Text")
2222 , ("dateTimeStamp", "Text")
23− , ("decimal", "Double")
23+ , ("decimal", "Scientific")
2424 , ("integer", "Integer")
2525 , ("long", "Integer")
2626 , ("int", "Integer")
@@ -34,7 +34,7 @@ builtInTypes = Map.fromList . map qualify $
3434 , ("nonPositiveInteger", "Integer")
3535 , ("negativeInteger", "Integer")
3636 , ("float", "Float")
37− , ("double", "Double")
37+ , ("double", "Scientific")
3838 , ("gDay", "Day")
3939 , ("gMonth", "Text")
4040 , ("gMonthDay", "Text")
src/Gen.hs+8−3
@@ -23,6 +23,7 @@ where
2323import qualified Data.Char as Char
2424import Data.Text (Text)
2525import qualified Data.Text as Text
26+import Data.Maybe
2627import Data.Set (Set)
2728import qualified Data.Set as Set
2829import Data.Map (Map)
@@ -156,14 +157,18 @@ allFields (Xsd.TypeComplex t) =
156157 case Xsd.complexContent t of
157158 Xsd.ContentPlain c ->
158159 case Xsd.plainContentModel c of
159− Just (Xsd.Sequence es) -> map Xsd.elementName es
160+ Just (Xsd.Sequence es) -> mapMaybe elementName es
160161 _ -> []
161162 Xsd.ContentSimple _ -> []
162163 Xsd.ContentComplex (Xsd.ComplexContentExtension e) ->
163164 case Xsd.complexExtensionModel e of
164− Just (Xsd.Sequence es) -> map Xsd.elementName es
165+ Just (Xsd.Sequence es) -> mapMaybe elementName es
165166 _ -> []
166− Xsd.ContentComplex Xsd.ComplexContentRestriction -> []
167+ Xsd.ContentComplex (Xsd.ComplexContentRestriction _) -> []
168+ where
169+ elementName = Xsd.refOr
170+ (const Nothing)
171+ (Just . Xsd.elementName)
167172
168173-- | Prefix field name with based on the type name
169174makePrefixedField :: Text -> Xsd.QName -> Text
src/Main.hs+46−23
@@ -138,7 +138,10 @@ genExtension base = do
138138 ]
139139 clauses <- mapM mkClause (base : map fst types)
140140 writeCode clauses
141− writeCode [""]
141+ writeCode
142+ [ " _ -> throwParserError (PEOther \"Unexpected type\")"
143+ , ""
144+ ]
142145 unless (mode == Parser) $ do
143146 writeCode
144147 [ "instance ToXML Any" <> baseTypeName <> " where"
@@ -188,18 +191,22 @@ genDependencies a = forM_ (references a) $ \name -> do
188191genSimpleType :: TypeName -> Xsd.SimpleType -> [Xsd.Annotation]-> Gen ()
189192genSimpleType tn (Xsd.AtomicType restriction ann) parentAnn = do
190193 let
191− baseName r = case Xsd.restrictionBase r of
194+ baseName r = case Xsd.simpleRestrictionBase r of
192195 Xsd.Ref n -> Just n
193196 Xsd.Inline (Xsd.AtomicType r' _) -> baseName r'
194197 Xsd.Inline (Xsd.ListType _ _) -> Nothing
198+ Xsd.Inline (Xsd.UnionType _ _) -> Nothing
195199 case baseName restriction of
196200 Just _
197201 | isEnum restriction
198− -> genEnum tn (Xsd.restrictionConstraints restriction) (parentAnn <> ann)
202+ -> genEnum tn
203+ (Xsd.simpleRestrictionConstraints restriction)
204+ (parentAnn <> ann)
199205 Just base ->
200206 genNewtype tn base (parentAnn <> ann)
201207 _ -> genUnsupported tn
202208genSimpleType typeName (Xsd.ListType _ _) _ = genUnsupported typeName
209+genSimpleType typeName (Xsd.UnionType _ _) _ = genUnsupported typeName
203210
204211genNewtype :: TypeName -> Xsd.QName -> [Xsd.Annotation] -> Gen ()
205212genNewtype tn base annots = do
@@ -227,6 +234,7 @@ genNewtype tn base annots = do
227234
228235genEnum :: TypeName -> [Xsd.Constraint] -> [Xsd.Annotation] -> Gen ()
229236genEnum tn constraints annots = do
237+ mode <- getMode
230238 let
231239 values = map toValue constraints
232240 toValue (Xsd.Enumeration v) = v
@@ -234,12 +242,12 @@ genEnum tn constraints annots = do
234242 enumName <- makeEnumName v
235243 return (" & \"" <> enumName <> "\"")
236244 writeCode $ makeComments tn annots
237− writeCode $ "\"" <> tnName tn <> "\" Exhaustive =:= enum Both"
238− : enumLines
245+ writeCode $ "\"" <> tnName tn <> "\" Exhaustive =:= enum "
246+ <> genTypeToText mode : enumLines
239247 writeCode [""]
240248
241−isEnum :: Xsd.Restriction -> Bool
242−isEnum = any isEnumConstraint . Xsd.restrictionConstraints
249+isEnum :: Xsd.SimpleRestriction -> Bool
250+isEnum = any isEnumConstraint . Xsd.simpleRestrictionConstraints
243251 where
244252 isEnumConstraint (Xsd.Enumeration _) = True
245253
@@ -257,15 +265,21 @@ genComplexType typeName t parentAnn = do
257265 writeCode [""]
258266
259267makeComments :: TypeName -> [Xsd.Annotation] -> [Text]
260−makeComments typeName annotations =
261− [ "{-"
262− , "Generated from: " <> prefix <> name
263− , ""
264− ] <> map makeDoc annotations <>
265− [ "-}"
266− , ""
267− ]
268+makeComments typeName annotations = if null annotations
269+ then
270+ [ "{-|"
271+ , generated
272+ , "-}"
273+ ]
274+ else
275+ [ "{-|"
276+ , generated
277+ , ""
278+ ] <> map makeDoc annotations <>
279+ [ "-}"
280+ ]
268281 where
282+ generated = "Generated from: " <> prefix <> name
269283 qname = tnQName typeName
270284 name = Xsd.qnName qname
271285 prefix = maybe "" ((<> ":") . Xsd.fromNamespace) (Xsd.qnNamespace qname)
@@ -280,13 +294,14 @@ genFields typeName (Xsd.ContentPlain c) =
280294genFields _ (Xsd.ContentSimple _) = return []
281295genFields typeName (Xsd.ContentComplex (Xsd.ComplexContentExtension e)) = do
282296 base <- resolveType (Xsd.complexExtensionBase e)
297+ genDependencies base
283298 baseFields <- case base of
284299 Xsd.TypeComplex t -> genFields typeName (Xsd.complexContent t)
285300 _ -> return []
286301 fields <- maybe (return []) (genFieldsForModel typeName)
287302 (Xsd.complexExtensionModel e)
288303 return (baseFields ++ fields)
289−genFields _ (Xsd.ContentComplex Xsd.ComplexContentRestriction) =
304+genFields _ (Xsd.ContentComplex (Xsd.ComplexContentRestriction _)) =
290305 return []
291306
292307genFieldsForModel :: TypeName -> Xsd.ModelGroup -> Gen [Text]
@@ -299,8 +314,9 @@ genFieldsForModel _ (Xsd.All _) = do
299314 warn "all: not implemented"
300315 return []
301316
302−genField :: TypeName -> Xsd.Element -> Gen (Maybe Text)
303−genField typeName e = do
317+genField :: TypeName -> Xsd.RefOr Xsd.Element -> Gen (Maybe Text)
318+genField _ (Xsd.Ref _) = return Nothing
319+genField typeName (Xsd.Inline e) = do
304320 fieldName <- makeFieldName typeName (Xsd.elementName e)
305321
306322 fieldTypeName <- case Xsd.elementType e of
@@ -316,13 +332,18 @@ genField typeName e = do
316332
317333 qualifier <- makeQualifier (Xsd.elementOccurs e)
318334
335+ let
336+ fieldType = if Xsd.elementNillable e
337+ then "Nillable " <> fieldTypeName
338+ else fieldTypeName
339+
319340 return $ Just $ mconcat
320341 [ " "
321342 , qualifier
322343 , " \""
323344 , fieldName
324345 , "\" [t|"
325− , fieldTypeName
346+ , fieldType
326347 , "|]"
327348 ]
328349
@@ -378,9 +399,11 @@ genHeader opts = do
378399 writeCode [""]
379400
380401 writeCode
381− [ "module " <> oModule opts <> " where"
402+ [ "{-# OPTIONS_GHC -Wno-unused-imports #-}"
403+ , "module " <> oModule opts <> " where"
382404 , ""
383405 , "import Control.DeepSeq"
406+ , "import Data.Scientific"
384407 , "import Data.THGen.XML"
385408 ]
386409 writeCode imports
@@ -391,9 +414,9 @@ genHeader opts = do
391414 ]
392415 where
393416 imports = case oMode opts of
394− Generator -> [ xmlWriter, parentAttr ]
395− Parser -> [ domParser ]
396− Both -> [ domParser, xmlWriter, parentAttr ]
417+ Generator -> [ xmlWriter, parentAttr ]
418+ Parser -> [ domParser ]
419+ ParserAndGenerator -> [ domParser, xmlWriter, parentAttr ]
397420 xmlWriter = "import Text.XML.Writer"
398421 parentAttr = "import Text.XML.ParentAttributes"
399422 domParser = "import Text.XML.DOM.Parser"
src/Options.hs+5−5
@@ -19,13 +19,13 @@ import Paths_xsd_isogen (version)
1919import Data.List
2020
2121
22−data GenType = Parser | Generator | Both
22+data GenType = Parser | Generator | ParserAndGenerator
2323 deriving (Read, Show, Eq, Bounded, Enum)
2424
2525genTypeToText :: GenType -> Text
26−genTypeToText Parser = "Parser"
27−genTypeToText Generator = "Generator"
28−genTypeToText Both = "Both"
26+genTypeToText Parser = "Parser"
27+genTypeToText Generator = "Generator"
28+genTypeToText ParserAndGenerator = "ParserAndGenerator"
2929
3030type ModuleName = Text
3131type Header = Text
@@ -54,7 +54,7 @@ optionsParser = Options
5454 <*> option auto
5555 ( long "mode"
5656 <> short 'm'
57− <> value Both
57+ <> value ParserAndGenerator
5858 <> help ("Whether to generate both parsers and generators. One of: "
5959 <> (mconcat . intersperse ", " . fmap show
6060 $ [minBound @GenType .. maxBound]) <> ".")
src/References.hs+15−4
@@ -22,9 +22,13 @@ instance References Xsd.Type where
2222instance References Xsd.SimpleType where
2323 references (Xsd.AtomicType r _) = references r
2424 references (Xsd.ListType r _) = references r
25+ references (Xsd.UnionType rs _) = referencesList rs
2526
26−instance References Xsd.Restriction where
27− references r = references (Xsd.restrictionBase r)
27+instance References Xsd.SimpleRestriction where
28+ references r = references (Xsd.simpleRestrictionBase r)
29+
30+instance References Xsd.ComplexRestriction where
31+ references r = [Xsd.complexRestrictionBase r]
2832
2933instance References t => References (Xsd.RefOr t) where
3034 references (Xsd.Ref r) = [r]
@@ -47,7 +51,7 @@ instance References Xsd.SimpleContent where
4751
4852instance References Xsd.ComplexContent where
4953 references (Xsd.ComplexContentExtension e) = references e
50− references Xsd.ComplexContentRestriction = []
54+ references (Xsd.ComplexContentRestriction r) = references r
5155
5256instance References Xsd.ComplexExtension where
5357 -- Note that we don't include extension base here
@@ -58,7 +62,14 @@ instance References Xsd.ComplexExtension where
5862 ++ references (Xsd.complexExtensionModel e)
5963
6064instance References Xsd.Attribute where
61− references = references . Xsd.attrType
65+ references (Xsd.RefAttribute a) = references a
66+ references (Xsd.InlineAttribute a) = references a
67+
68+instance References Xsd.AttributeRef where
69+ references a = [Xsd.attributeRefRef a]
70+
71+instance References Xsd.AttributeInline where
72+ references = references . Xsd.attributeInlineType
6273
6374instance References Xsd.ModelGroup where
6475 references (Xsd.Sequence elements) = referencesList elements
stack.yamlnew file+12
@@ -0,0 +1,12 @@
1+#resolver: nightly-2022-01-24
2+resolver: lts-18.23
3+
4+packages:
5+- .
6+
7+extra-deps:
8+- git: https://github.com/typeable/xsd-parser
9+ commit: 648877d94d03a58dc9114f68d4e99c674e353fca
10+
11+nix:
12+ packages: [zlib]
xsd-isogen.cabal+1−1
@@ -25,7 +25,7 @@ executable xsd-isogen
2525 , References
2626 , Paths_xsd_isogen
2727 -- other-extensions:
28− build-depends: base ^>=4.12.0.0
28+ build-depends: base >=4.12 && < 5.0
2929 , bytestring
3030 , containers
3131 , data-default