Changeset 11876
- Timestamp:
- 03.07.2009 17:44:06 (5 months ago)
- Files:
-
- 1 modified
-
trunk/Syntax/ToXml.hs (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Syntax/ToXml.hs
r11874 r11876 78 78 toXml (Lib_defn n il rg an) = 79 79 mkEl "Lib" ["name", toStr n] 80 $ printAnnotations rg an [] :map (toXml . item) il80 $ maybeToList (printAnnotations rg an []) ++ map (toXml . item) il 81 81 82 82 instance XmlPrintable LIB_ITEM where … … 170 170 instance XmlListPrintable GENERICITY where 171 171 toLst (Genericity (Params pl) (Imported il) _) 172 = map (mkPEl "Param" . (: []) . toXml) pl ++173 map (mkPEl "Given" . (: []) . toXml)il172 = let f n l = map (mkPEl n . (: []) . toXml) l 173 in f "Param" pl ++ f "Given" il 174 174 175 175 instance XmlListPrintable RESTRICTION where … … 178 178 179 179 instance XmlListPrintable G_symb_items_list where 180 toLst _ = []180 toLst (G_symb_items_list lid l) = map toText l 181 181 182 182 instance XmlListPrintable G_symb_map_items_list where 183 toLst _ = []183 toLst (G_symb_map_items_list lid l) = map toText l 184 184 185 185 instance XmlAttrList [String] where … … 193 193 instance XmlAttrList Logic_code where 194 194 mkAtts (Logic_code enc src trg _) 195 = mkAtts $ catMaybes [liftM ((,) "encoding" . toStr) enc,196 liftM ((,) "source" . toStr) src,197 liftM ((,) "target" . toStr)trg]195 = let f n o = liftM ((,) n . toStr) o 196 in mkAtts $ catMaybes 197 [f "encoding" enc, f "source" src, f "target" trg] 198 198 199 199 printBasicSpecItem :: Annoted String -> Content … … 203 203 204 204 205 printAnnotated :: Annoted a -> Content205 printAnnotated :: Annoted a -> Maybe Content 206 206 printAnnotated (Annoted _ rg la ra) = printAnnotations rg la ra 207 207 208 printAnnotations :: Range -> [Annotation] -> [Annotation] -> Content 209 printAnnotations rg lan ran = 210 withRg rg $ mkPEl "Annotations" 211 [printPXmlList "Left" lan, printPXmlList "Right" ran] 212 213 208 printAnnotations :: Range -> [Annotation] -> [Annotation] -> Maybe Content 209 printAnnotations rg [] [] = Nothing 210 printAnnotations rg lan ran 211 = Just $ withRg rg $ mkPEl "Annotations" 212 $ let f n l = (case lan of [] -> [] 213 _ -> [printPXmlList n l]) 214 in f "Left" lan ++ f "Right" ran 215 216 -- check if one can remove this by generalizing mkEl such as for attribs 214 217 printXmlList :: XmlPrintable a => String -> [String] -> [a] -> Content 215 218 printXmlList n attrs l = mkEl n attrs $ toLst l … … 220 223 221 224 withAnno :: Annoted a -> Content -> Content 222 withAnno a (Elem e) = Elem $ e { elContent = printAnnotated a : elContent e } 225 withAnno a c@(Elem e) = case printAnnotated a of 226 Just ac -> Elem $ e { elContent = ac : elContent e } 227 _ -> c 228 223 229 withAnno a _ = error "withAnno only applies to elements" 224 230 225 231 withRg :: Range -> Content -> Content 226 withRg rg (Elem e) = Elem $ add_attr (Attr (unqual "range") $ toString rg) e 232 withRg rg c@(Elem e) = case toString rg of [] -> c 233 str -> Elem $ add_attr 234 (Attr (unqual "range") $ str) e 227 235 withRg rg _ = error "withRg only applies to elements" 228 236