Changeset 11876

Show
Ignore:
Timestamp:
03.07.2009 17:44:06 (5 months ago)
Author:
ewaryst
Message:

refinement of xml export, cleaned senseless output

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Syntax/ToXml.hs

    r11874 r11876  
    7878    toXml (Lib_defn n il rg an) = 
    7979        mkEl "Lib" ["name", toStr n] 
    80                  $ printAnnotations rg an [] : map (toXml . item) il 
     80                 $ maybeToList (printAnnotations rg an []) ++ map (toXml . item) il 
    8181 
    8282instance XmlPrintable LIB_ITEM where 
     
    170170instance XmlListPrintable GENERICITY where 
    171171    toLst (Genericity (Params pl) (Imported il) _) 
    172         = map (mkPEl "Param" . (: []) . toXml) pl ++ 
    173           map (mkPEl "Given" . (: []) . toXml) il 
     172        = let f n l = map (mkPEl n . (: []) . toXml) l 
     173          in f "Param" pl ++ f "Given" il 
    174174 
    175175instance XmlListPrintable RESTRICTION where 
     
    178178 
    179179instance XmlListPrintable G_symb_items_list where 
    180     toLst _ = [] 
     180    toLst (G_symb_items_list lid l) = map toText l 
    181181 
    182182instance XmlListPrintable G_symb_map_items_list where 
    183     toLst _ = [] 
     183    toLst (G_symb_map_items_list lid l) = map toText l 
    184184 
    185185instance XmlAttrList [String] where 
     
    193193instance XmlAttrList Logic_code where 
    194194    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] 
    198198 
    199199printBasicSpecItem :: Annoted String -> Content 
     
    203203 
    204204 
    205 printAnnotated :: Annoted a -> Content 
     205printAnnotated :: Annoted a -> Maybe Content 
    206206printAnnotated (Annoted _ rg la ra) = printAnnotations rg la ra 
    207207 
    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  
     208printAnnotations :: Range -> [Annotation] -> [Annotation] -> Maybe Content 
     209printAnnotations rg [] [] = Nothing 
     210printAnnotations 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 
    214217printXmlList :: XmlPrintable a => String -> [String] -> [a] -> Content 
    215218printXmlList n attrs l = mkEl n attrs $ toLst l 
     
    220223 
    221224withAnno :: Annoted a -> Content -> Content 
    222 withAnno a (Elem e) = Elem $ e { elContent = printAnnotated a : elContent e } 
     225withAnno a c@(Elem e) = case printAnnotated a of 
     226                        Just ac -> Elem $ e { elContent = ac : elContent e } 
     227                        _ -> c 
     228 
    223229withAnno a _ = error "withAnno only applies to elements" 
    224230 
    225231withRg :: Range -> Content -> Content 
    226 withRg rg (Elem e) = Elem $ add_attr (Attr (unqual "range") $ toString rg) e 
     232withRg rg c@(Elem e) = case toString rg of [] -> c 
     233                                           str -> Elem $ add_attr 
     234                                                  (Attr (unqual "range") $ str) e 
    227235withRg rg _ = error "withRg only applies to elements" 
    228236