@@ -48,7 +48,7 @@ parseChild :: Cursor -> P (Maybe Xsd.Child)
4848parseChild c = do
4949 name <- getElementName c
5050 case name of
51− "element" -> Just . Xsd.ChildElement <$> parseElementOrRef c
51+ "element" -> Just . Xsd.ChildElement <$> parseElement c
5252 "simpleType" -> Just <$> parseTopSimpleType c
5353 "complexType" -> Just <$> parseTopComplexType c
5454 "include" -> Just . Xsd.ChildInclude <$> parseInclude c
@@ -81,19 +81,14 @@ parseImport c = do
8181 , Xsd.importNamespace = namespace
8282 }
8383
84−parseElementOrRef :: Cursor -> P (Xsd.RefOr Xsd.Element)
85−parseElementOrRef c = do
86− case anAttribute "ref" c of
87− Nothing -> Xsd.Inline <$> parseElement c
88− Just ref -> Xsd.Ref <$> makeQName c ref
89−
9084parseElement :: Cursor -> P Xsd.Element
9185parseElement c = handleNamespaces c $ do
9286 name <- theAttribute "name" c
9387
88+ -- XXX: generalaze RefOr parsing
9489 tp <- case anAttribute "type" c of
9590 Just t -> Xsd.Ref <$> makeQName c t
96− _ -> maybe (Xsd.Ref anyType) Xsd.Inline <$> parseType c
91+ _ -> Xsd.Inline <$> parseType c
9792
9893 minOccurs <- case anAttribute "minOccurs" c of
9994 Nothing -> return 1
@@ -112,31 +107,22 @@ parseElement c = handleNamespaces c $ do
112107
113108 qname <- makeTargetQName name
114109
115− nillable <- case anAttribute "nillable" c of
116− Nothing -> return False
117− Just "true" -> return True
118− Just "false" -> return False
119− _ -> parseError c "Unexpected value of nillable attribute"
120−
121110 return Xsd.Element
122111 { Xsd.elementName = qname
123112 , Xsd.elementType = tp
124113 , Xsd.elementAnnotations = annotations
125114 , Xsd.elementOccurs = (minOccurs, maxOccurs)
126− , Xsd.elementNillable = nillable
127115 }
128− where
129− anyType = Xsd.QName (Just (Xsd.Namespace Xsd.schemaNamespace)) "anyType"
130116
131117-- | Parse inline type, simple or complex
132−parseType :: Cursor -> P (Maybe Xsd.Type)
118+parseType :: Cursor -> P Xsd.Type
133119parseType c = do
134120 simpleTypeAxis <- makeElemAxis "simpleType"
135121 complexTypeAxis <- makeElemAxis "complexType"
136122 case (c $/ simpleTypeAxis, c $/ complexTypeAxis) of
137− ([], []) -> return Nothing
138− ([t], []) -> Just . Xsd.TypeSimple <$> parseSimpleType t
139− ([], [t]) -> Just . Xsd.TypeComplex <$> parseComplexType t
123+ ([], []) -> parseError c "No type"
124+ ([t], []) -> Xsd.TypeSimple <$> parseSimpleType t
125+ ([], [t]) -> Xsd.TypeComplex <$> parseComplexType t
140126 _ -> parseError c "Multiple types"
141127
142128-- | Top level simple type
@@ -160,19 +146,18 @@ parseSimpleType c = do
160146 unionAxis <- makeElemAxis "union"
161147 case (c $/ restrictionAxis, c $/ listAxis, c $/ unionAxis) of
162148 ([e], [], []) -> Xsd.AtomicType
163− <$> parseSimpleRestriction e
149+ <$> parseRestriction e
164150 <*> parseAnnotations c
165151 ([], [l], []) -> Xsd.ListType
166152 <$> parseList l
167153 <*> parseAnnotations c
168− ([], [], [u]) -> Xsd.UnionType
169− <$> parseUnion u
170− <*> parseAnnotations c
154+ -- TODO implement me
155+ ([], [], [_]) -> parseError c "Not implemented: union"
171156 _ -> parseError c "Expected exactly of of restriction, list or union"
172157
173158-- | Restriction for simple type
174−parseSimpleRestriction :: Cursor -> P Xsd.SimpleRestriction
175−parseSimpleRestriction c = do
159+parseRestriction :: Cursor -> P Xsd.Restriction
160+parseRestriction c = do
176161 -- XXX: generalaze RefOr parsing
177162 tp <- case anAttribute "base" c of
178163 Nothing -> do
@@ -185,9 +170,9 @@ parseSimpleRestriction c = do
185170
186171 constraints <- parseConstrains c
187172
188− return Xsd.SimpleRestriction
189− { Xsd.simpleRestrictionBase = tp
190− , Xsd.simpleRestrictionConstraints = constraints
173+ return Xsd.Restriction
174+ { Xsd.restrictionBase = tp
175+ , Xsd.restrictionConstraints = constraints
191176 }
192177
193178parseConstrains :: Cursor -> P [Xsd.Constraint]
@@ -208,15 +193,6 @@ parseList c =
208193 _ -> parseError c "Multiple types"
209194 Just t -> Xsd.Ref <$> makeQName c t
210195
211−parseUnion :: Cursor -> P [Xsd.RefOr Xsd.SimpleType]
212−parseUnion c =
213− case anAttribute "memberTypes" c of
214− Just list ->
215− mapM (fmap Xsd.Ref . makeQName c) (Text.splitOn " " list)
216− Nothing -> do
217− simpleTypeAxis <- makeElemAxis "simpleType"
218− mapM (fmap Xsd.Inline . parseSimpleType) (c $/ simpleTypeAxis)
219−
220196parseComplexType :: Cursor -> P Xsd.ComplexType
221197parseComplexType c = do
222198 annotations <- parseAnnotations c
@@ -247,34 +223,19 @@ parsePlainContent c = do
247223 }
248224
249225parseSimpleContent :: Cursor -> P Xsd.SimpleContent
250−parseSimpleContent c = do
251− restrictionAxis <- makeElemAxis "restriction"
252− extenstionAxis <- makeElemAxis "extension"
253− case (c $/ restrictionAxis, c $/ extenstionAxis) of
254− ([r], []) -> Xsd.SimpleContentRestriction <$> parseSimpleRestriction r
255− ([], [e]) -> Xsd.SimpleContentExtension <$> parseSimpleExtension e
256− _ -> parseError c "Expected one of restriction or extension"
257−
258−parseSimpleExtension :: Cursor -> P Xsd.SimpleExtension
259−parseSimpleExtension c = handleNamespaces c $ do
260− base <- theAttribute "base" c >>= makeQName c
261− attributes <- parseAttributes c
262− return Xsd.SimpleExtension
263− { Xsd.simpleExtensionBase = base
264− , Xsd.simpleExtensionAttributes = attributes
265− }
226+parseSimpleContent c = parseError c "not implemented"
266227
267228parseComplexContent :: Cursor -> P Xsd.ComplexContent
268229parseComplexContent c = do
269230 restrictionAxis <- makeElemAxis "restriction"
270231 extenstionAxis <- makeElemAxis "extension"
271232 case (c $/ restrictionAxis, c $/ extenstionAxis) of
272− ([r], []) -> Xsd.ComplexContentRestriction <$> parseComplexRestriction r
233+ ([r], []) -> parseError r "not implemented"
273234 ([], [e]) -> Xsd.ComplexContentExtension <$> parseComplexExtension e
274235 _ -> parseError c "Expected one of restriction or extension"
275236
276237parseComplexExtension :: Cursor -> P Xsd.ComplexExtension
277−parseComplexExtension c = handleNamespaces c $ do
238+parseComplexExtension c = do
278239 base <- theAttribute "base" c >>= makeQName c
279240 attributes <- parseAttributes c
280241 model <- parseModelGroup c
@@ -284,17 +245,6 @@ parseComplexExtension c = handleNamespaces c $ do
284245 , Xsd.complexExtensionAttributes = attributes
285246 }
286247
287−parseComplexRestriction :: Cursor -> P Xsd.ComplexRestriction
288−parseComplexRestriction c = handleNamespaces c $ do
289− base <- theAttribute "base" c >>= makeQName c
290− attributes <- parseAttributes c
291− model <- parseModelGroup c
292− return Xsd.ComplexRestriction
293− { Xsd.complexRestrictionBase = base
294− , Xsd.complexRestrictionModel = model
295− , Xsd.complexRestrictionAttributes = attributes
296− }
297−
298248parseModelGroup :: Cursor -> P (Maybe Xsd.ModelGroup)
299249parseModelGroup c = do
300250 sequenceAxis <- makeElemAxis "sequence"
@@ -317,10 +267,10 @@ parseAll :: Cursor -> P Xsd.ModelGroup
317267parseAll c = Xsd.All <$> parseElements c
318268
319269-- | Get all child elements
320−parseElements :: Cursor -> P [Xsd.RefOr Xsd.Element]
270+parseElements :: Cursor -> P [Xsd.Element]
321271parseElements c = do
322272 elementAxis <- makeElemAxis "element"
323− mapM parseElementOrRef (c $/ elementAxis)
273+ mapM parseElement (c $/ elementAxis)
324274
325275parseAttributes :: Cursor -> P [Xsd.Attribute]
326276parseAttributes c = do
@@ -329,33 +279,24 @@ parseAttributes c = do
329279
330280parseAttribute :: Cursor -> P Xsd.Attribute
331281parseAttribute c = do
282+ name <- theAttribute "name" c >>= makeTargetQName
332283 use <- parseUseAttribute c
333− case (anAttribute "name" c, anAttribute "ref" c) of
334− (Just n, Nothing) -> do
335− name <- makeTargetQName n
336− tp <- case anAttribute "type" c of
337− Nothing -> do
338− simpleTypeAxis <- makeElemAxis "simpleType"
339− case c $/ simpleTypeAxis of
340− [s] -> Xsd.Inline <$> parseSimpleType s
341− [] -> return (Xsd.Ref anySimpleType)
342− _ -> parseError c "Multiple simple types"
343− Just t -> Xsd.Ref <$> makeQName c t
344− return $ Xsd.InlineAttribute $ Xsd.AttributeInline
345− { Xsd.attributeInlineName = name
346− , Xsd.attributeInlineUse = use
347− , Xsd.attributeInlineType = tp
348− }
349− (Nothing, Just r) -> do
350− ref <- makeQName c r
351− return $ Xsd.RefAttribute $ Xsd.AttributeRef
352− { Xsd.attributeRefRef = ref
353− , Xsd.attributeRefUse = use
354− }
355− _ -> parseError c "Should be either name or ref"
356− where
357− anySimpleType =
358− Xsd.QName (Just (Xsd.Namespace Xsd.schemaNamespace)) "anySimpleType"
284+
285+ -- XXX: generalaze RefOr parsing
286+ tp <- case anAttribute "type" c of
287+ Nothing -> do
288+ simpleTypeAxis <- makeElemAxis "simpleType"
289+ case c $/ simpleTypeAxis of
290+ [s] -> Xsd.Inline <$> parseSimpleType s
291+ [] -> parseError c "Attribute should have type"
292+ _ -> parseError c "Multiple simple types"
293+ Just t -> Xsd.Ref <$> makeQName c t
294+
295+ return Xsd.Attribute
296+ { Xsd.attrName = name
297+ , Xsd.attrUse = use
298+ , Xsd.attrType = tp
299+ }
359300
360301parseUseAttribute :: Cursor -> P Xsd.Use
361302parseUseAttribute c = case anAttribute "use" c of
@@ -511,9 +452,8 @@ makeElemAxis name = do
511452makeQName :: Cursor -> Text -> P Xsd.QName
512453makeQName c t = case Text.splitOn ":" t of
513454 [n] -> do
514− ns <- asks (lookup Nothing . envPrefixes)
515455 return Xsd.QName
516− { Xsd.qnNamespace = ns
456+ { Xsd.qnNamespace = Nothing
517457 , Xsd.qnName = n
518458 }
519459 [p, n] -> do