@@ -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,12 +81,6 @@ 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
@@ -160,19 +154,18 @@ parseSimpleType c = do
160154 unionAxis <- makeElemAxis "union"
161155 case (c $/ restrictionAxis, c $/ listAxis, c $/ unionAxis) of
162156 ([e], [], []) -> Xsd.AtomicType
163− <$> parseSimpleRestriction e
157+ <$> parseRestriction e
164158 <*> parseAnnotations c
165159 ([], [l], []) -> Xsd.ListType
166160 <$> parseList l
167161 <*> parseAnnotations c
168− ([], [], [u]) -> Xsd.UnionType
169− <$> parseUnion u
170− <*> parseAnnotations c
162+ -- TODO implement me
163+ ([], [], [_]) -> parseError c "Not implemented: union"
171164 _ -> parseError c "Expected exactly of of restriction, list or union"
172165
173166-- | Restriction for simple type
174−parseSimpleRestriction :: Cursor -> P Xsd.SimpleRestriction
175−parseSimpleRestriction c = do
167+parseRestriction :: Cursor -> P Xsd.Restriction
168+parseRestriction c = do
176169 -- XXX: generalaze RefOr parsing
177170 tp <- case anAttribute "base" c of
178171 Nothing -> do
@@ -185,9 +178,9 @@ parseSimpleRestriction c = do
185178
186179 constraints <- parseConstrains c
187180
188− return Xsd.SimpleRestriction
189− { Xsd.simpleRestrictionBase = tp
190− , Xsd.simpleRestrictionConstraints = constraints
181+ return Xsd.Restriction
182+ { Xsd.restrictionBase = tp
183+ , Xsd.restrictionConstraints = constraints
191184 }
192185
193186parseConstrains :: Cursor -> P [Xsd.Constraint]
@@ -208,15 +201,6 @@ parseList c =
208201 _ -> parseError c "Multiple types"
209202 Just t -> Xsd.Ref <$> makeQName c t
210203
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−
220204parseComplexType :: Cursor -> P Xsd.ComplexType
221205parseComplexType c = do
222206 annotations <- parseAnnotations c
@@ -247,29 +231,14 @@ parsePlainContent c = do
247231 }
248232
249233parseSimpleContent :: 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− }
234+parseSimpleContent c = parseError c "not implemented"
266235
267236parseComplexContent :: Cursor -> P Xsd.ComplexContent
268237parseComplexContent c = do
269238 restrictionAxis <- makeElemAxis "restriction"
270239 extenstionAxis <- makeElemAxis "extension"
271240 case (c $/ restrictionAxis, c $/ extenstionAxis) of
272− ([r], []) -> Xsd.ComplexContentRestriction <$> parseComplexRestriction r
241+ ([r], []) -> parseError r "not implemented"
273242 ([], [e]) -> Xsd.ComplexContentExtension <$> parseComplexExtension e
274243 _ -> parseError c "Expected one of restriction or extension"
275244
@@ -284,17 +253,6 @@ parseComplexExtension c = handleNamespaces c $ do
284253 , Xsd.complexExtensionAttributes = attributes
285254 }
286255
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−
298256parseModelGroup :: Cursor -> P (Maybe Xsd.ModelGroup)
299257parseModelGroup c = do
300258 sequenceAxis <- makeElemAxis "sequence"
@@ -317,10 +275,10 @@ parseAll :: Cursor -> P Xsd.ModelGroup
317275parseAll c = Xsd.All <$> parseElements c
318276
319277-- | Get all child elements
320−parseElements :: Cursor -> P [Xsd.RefOr Xsd.Element]
278+parseElements :: Cursor -> P [Xsd.Element]
321279parseElements c = do
322280 elementAxis <- makeElemAxis "element"
323− mapM parseElementOrRef (c $/ elementAxis)
281+ mapM parseElement (c $/ elementAxis)
324282
325283parseAttributes :: Cursor -> P [Xsd.Attribute]
326284parseAttributes c = do
@@ -329,33 +287,24 @@ parseAttributes c = do
329287
330288parseAttribute :: Cursor -> P Xsd.Attribute
331289parseAttribute c = do
290+ name <- theAttribute "name" c >>= makeTargetQName
332291 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"
292+
293+ -- XXX: generalaze RefOr parsing
294+ tp <- case anAttribute "type" c of
295+ Nothing -> do
296+ simpleTypeAxis <- makeElemAxis "simpleType"
297+ case c $/ simpleTypeAxis of
298+ [s] -> Xsd.Inline <$> parseSimpleType s
299+ [] -> parseError c "Attribute should have type"
300+ _ -> parseError c "Multiple simple types"
301+ Just t -> Xsd.Ref <$> makeQName c t
302+
303+ return Xsd.Attribute
304+ { Xsd.attrName = name
305+ , Xsd.attrUse = use
306+ , Xsd.attrType = tp
307+ }
359308
360309parseUseAttribute :: Cursor -> P Xsd.Use
361310parseUseAttribute c = case anAttribute "use" c of