@@ -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
@@ -125,18 +120,16 @@ parseElement c = handleNamespaces c $ do
125120 , Xsd.elementOccurs = (minOccurs, maxOccurs)
126121 , Xsd.elementNillable = nillable
127122 }
128− where
129− anyType = Xsd.QName (Just (Xsd.Namespace Xsd.schemaNamespace)) "anyType"
130123
131124-- | Parse inline type, simple or complex
132−parseType :: Cursor -> P (Maybe Xsd.Type)
125+parseType :: Cursor -> P Xsd.Type
133126parseType c = do
134127 simpleTypeAxis <- makeElemAxis "simpleType"
135128 complexTypeAxis <- makeElemAxis "complexType"
136129 case (c $/ simpleTypeAxis, c $/ complexTypeAxis) of
137− ([], []) -> return Nothing
138− ([t], []) -> Just . Xsd.TypeSimple <$> parseSimpleType t
139− ([], [t]) -> Just . Xsd.TypeComplex <$> parseComplexType t
130+ ([], []) -> parseError c "No type"
131+ ([t], []) -> Xsd.TypeSimple <$> parseSimpleType t
132+ ([], [t]) -> Xsd.TypeComplex <$> parseComplexType t
140133 _ -> parseError c "Multiple types"
141134
142135-- | Top level simple type
@@ -160,19 +153,18 @@ parseSimpleType c = do
160153 unionAxis <- makeElemAxis "union"
161154 case (c $/ restrictionAxis, c $/ listAxis, c $/ unionAxis) of
162155 ([e], [], []) -> Xsd.AtomicType
163− <$> parseSimpleRestriction e
156+ <$> parseRestriction e
164157 <*> parseAnnotations c
165158 ([], [l], []) -> Xsd.ListType
166159 <$> parseList l
167160 <*> parseAnnotations c
168− ([], [], [u]) -> Xsd.UnionType
169− <$> parseUnion u
170− <*> parseAnnotations c
161+ -- TODO implement me
162+ ([], [], [_]) -> parseError c "Not implemented: union"
171163 _ -> parseError c "Expected exactly of of restriction, list or union"
172164
173165-- | Restriction for simple type
174−parseSimpleRestriction :: Cursor -> P Xsd.SimpleRestriction
175−parseSimpleRestriction c = do
166+parseRestriction :: Cursor -> P Xsd.Restriction
167+parseRestriction c = do
176168 -- XXX: generalaze RefOr parsing
177169 tp <- case anAttribute "base" c of
178170 Nothing -> do
@@ -185,9 +177,9 @@ parseSimpleRestriction c = do
185177
186178 constraints <- parseConstrains c
187179
188− return Xsd.SimpleRestriction
189− { Xsd.simpleRestrictionBase = tp
190− , Xsd.simpleRestrictionConstraints = constraints
180+ return Xsd.Restriction
181+ { Xsd.restrictionBase = tp
182+ , Xsd.restrictionConstraints = constraints
191183 }
192184
193185parseConstrains :: Cursor -> P [Xsd.Constraint]
@@ -208,15 +200,6 @@ parseList c =
208200 _ -> parseError c "Multiple types"
209201 Just t -> Xsd.Ref <$> makeQName c t
210202
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−
220203parseComplexType :: Cursor -> P Xsd.ComplexType
221204parseComplexType c = do
222205 annotations <- parseAnnotations c
@@ -247,29 +230,14 @@ parsePlainContent c = do
247230 }
248231
249232parseSimpleContent :: 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− }
233+parseSimpleContent c = parseError c "not implemented"
266234
267235parseComplexContent :: Cursor -> P Xsd.ComplexContent
268236parseComplexContent c = do
269237 restrictionAxis <- makeElemAxis "restriction"
270238 extenstionAxis <- makeElemAxis "extension"
271239 case (c $/ restrictionAxis, c $/ extenstionAxis) of
272− ([r], []) -> Xsd.ComplexContentRestriction <$> parseComplexRestriction r
240+ ([r], []) -> parseError r "not implemented"
273241 ([], [e]) -> Xsd.ComplexContentExtension <$> parseComplexExtension e
274242 _ -> parseError c "Expected one of restriction or extension"
275243
@@ -284,17 +252,6 @@ parseComplexExtension c = handleNamespaces c $ do
284252 , Xsd.complexExtensionAttributes = attributes
285253 }
286254
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−
298255parseModelGroup :: Cursor -> P (Maybe Xsd.ModelGroup)
299256parseModelGroup c = do
300257 sequenceAxis <- makeElemAxis "sequence"
@@ -317,10 +274,10 @@ parseAll :: Cursor -> P Xsd.ModelGroup
317274parseAll c = Xsd.All <$> parseElements c
318275
319276-- | Get all child elements
320−parseElements :: Cursor -> P [Xsd.RefOr Xsd.Element]
277+parseElements :: Cursor -> P [Xsd.Element]
321278parseElements c = do
322279 elementAxis <- makeElemAxis "element"
323− mapM parseElementOrRef (c $/ elementAxis)
280+ mapM parseElement (c $/ elementAxis)
324281
325282parseAttributes :: Cursor -> P [Xsd.Attribute]
326283parseAttributes c = do
@@ -329,33 +286,24 @@ parseAttributes c = do
329286
330287parseAttribute :: Cursor -> P Xsd.Attribute
331288parseAttribute c = do
289+ name <- theAttribute "name" c >>= makeTargetQName
332290 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"
291+
292+ -- XXX: generalaze RefOr parsing
293+ tp <- case anAttribute "type" c of
294+ Nothing -> do
295+ simpleTypeAxis <- makeElemAxis "simpleType"
296+ case c $/ simpleTypeAxis of
297+ [s] -> Xsd.Inline <$> parseSimpleType s
298+ [] -> parseError c "Attribute should have type"
299+ _ -> parseError c "Multiple simple types"
300+ Just t -> Xsd.Ref <$> makeQName c t
301+
302+ return Xsd.Attribute
303+ { Xsd.attrName = name
304+ , Xsd.attrUse = use
305+ , Xsd.attrType = tp
306+ }
359307
360308parseUseAttribute :: Cursor -> P Xsd.Use
361309parseUseAttribute c = case anAttribute "use" c of