FromXml.hs revision 22b30604969a8d786c8f1b9fe19220159cfe7b7f
8e117661fd51fd19d6430fca8d7ae87c67d6de20stoddardModule : $Header$
8e117661fd51fd19d6430fca8d7ae87c67d6de20stoddardDescription : xml update input for Hets development graphs
8e117661fd51fd19d6430fca8d7ae87c67d6de20stoddardCopyright : (c) Christian Maeder, DFKI GmbH 2010
8e117661fd51fd19d6430fca8d7ae87c67d6de20stoddardLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
14d27a22a8fdb25e6e82d8af853a63bd4c6bd894wroweMaintainer : Christian.Maeder@dfki.de
8e117661fd51fd19d6430fca8d7ae87c67d6de20stoddardStability : provisional
8e117661fd51fd19d6430fca8d7ae87c67d6de20stoddardPortability : non-portable(Grothendieck)
8e117661fd51fd19d6430fca8d7ae87c67d6de20stoddardadjust development graph according to xupdate information
b6546cf6d01472a9bf658fa50b096c76314cbbf7stoddardimport qualified Common.OrderedMap as OMap
d9d416febbde142f8afd14d5472e5ab3253c640cwroweimport qualified Data.Map as Map
d9d416febbde142f8afd14d5472e5ab3253c640cwroweimport qualified Data.Set as Set
d9d416febbde142f8afd14d5472e5ab3253c640cwroweanaUpdates :: LibEnv -> DGraph -> String -> Result [AddChangeDG]
d9d416febbde142f8afd14d5472e5ab3253c640cwroweanaUpdates _lenv _dg input = do
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe cs <- anaXUpdates input
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe acs <- mapM changeDG cs
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe return $ concat acs
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe-- | target data type of elements that may be added (via AddElem)
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowedata AddChangeDG =
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe SpecEntryDG
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe { name :: SIMPLE_ID
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe , formalParams :: Maybe NodeName
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe | ViewEntryDG
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe { name :: SIMPLE_ID
521adbcace47547bdd9b8a8409da1199a39123c4wrowe , formalParams :: Maybe NodeName
521adbcace47547bdd9b8a8409da1199a39123c4wrowe , source :: NodeName
521adbcace47547bdd9b8a8409da1199a39123c4wrowe , target :: NodeName
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe , gmorphism :: String
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe | NodeDG -- no reference nodes yet
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe { nName :: NodeName -- including xpath
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe , refName :: Maybe SIMPLE_ID
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe , consStatus :: String
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe , declsOrSign :: DeclsOrSign
b23117c3c7034b6e61dac1b0ffebd256950abb56wrowe { linkId :: EdgeId
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe , source :: NodeName
483ed5892604266e702d65db4d0b2b621c488a09wrowe , target :: NodeName
483ed5892604266e702d65db4d0b2b621c488a09wrowe , linkType :: String
483ed5892604266e702d65db4d0b2b621c488a09wrowe , gmorphism :: String
483ed5892604266e702d65db4d0b2b621c488a09wrowe | GMorphismDG
483ed5892604266e702d65db4d0b2b621c488a09wrowe { gmorphism :: String }
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe { symbol :: String }
fd615438163a63ea43ce5f87bdb76dfba9b8a827wrowe { affected :: String }
2b58afd3d784930cd4e8748fd069577d3192dd0dmturk deriving Show
d9d416febbde142f8afd14d5472e5ab3253c640cwrowedata DeclsOrSign =
d9d416febbde142f8afd14d5472e5ab3253c640cwrowe { symbols :: [String] }
8e117661fd51fd19d6430fca8d7ae87c67d6de20stoddard { sign :: String }
8e117661fd51fd19d6430fca8d7ae87c67d6de20stoddard deriving Show
14d27a22a8fdb25e6e82d8af853a63bd4c6bd894wroweeName :: Element -> String
4d1b0ff0bb6735f8a7ec1936acc4bf587ef4db0dwroweeName = qName . elName
29fc13ae8c586a980b0d4e8cba4546b370a951e6wrowefindChildrenByLocalName :: String -> Element -> [Element]
29fc13ae8c586a980b0d4e8cba4546b370a951e6wrowefindChildrenByLocalName str = filterChildrenName ((== str) . qName)
cfab5b5b6dc82c578597b582f76491c96b86eeb7wrowegetElementTexts :: String -> Element -> [String]
cfab5b5b6dc82c578597b582f76491c96b86eeb7wrowegetElementTexts str = map strContent . findChildrenByLocalName str
6cfdc62fc0d30985d5d6e9bf646c6139748d91c1wrowe-- | convert (parts of) an xupdate change (list) to more abstract change(s)
b3ffcf1e862b6636310daf1dc4d97182d5882a54wroweaddChangeDG :: Monad m => AddChange -> m AddChangeDG
b3ffcf1e862b6636310daf1dc4d97182d5882a54wroweaddChangeDG ac = case ac of
6cfdc62fc0d30985d5d6e9bf646c6139748d91c1wrowe AddElem e -> do
b3ffcf1e862b6636310daf1dc4d97182d5882a54wrowe n <- getNameAttr e
b3ffcf1e862b6636310daf1dc4d97182d5882a54wrowe case eName e of
ec520097ee84be47111fe6b5e543a3080fa9c3dcwrowe "SPEC_DEFN" ->
ec520097ee84be47111fe6b5e543a3080fa9c3dcwrowe return SpecEntryDG
ec520097ee84be47111fe6b5e543a3080fa9c3dcwrowe { name = mkSimpleId n
1e83c8de3aa48b316b28057d53995272baf1260cwrowe , formalParams = fmap parseNodeName $ getAttrVal "formal-param" e
1e83c8de3aa48b316b28057d53995272baf1260cwrowe "DGNode" -> do
1e83c8de3aa48b316b28057d53995272baf1260cwrowe dOrS <- getDeclsOrSign e
1e83c8de3aa48b316b28057d53995272baf1260cwrowe return NodeDG
1e83c8de3aa48b316b28057d53995272baf1260cwrowe { nName = parseNodeName n -- getAttrVal "relxpath" e
fea5a668be80100d79e731b0e255db84cbd309dcgsmith , refName = fmap mkSimpleId $ getAttrVal "refname" e
fea5a668be80100d79e731b0e255db84cbd309dcgsmith , consStatus = concat $ getElementTexts "ConsStatus" e
fea5a668be80100d79e731b0e255db84cbd309dcgsmith , declsOrSign = dOrS
0c01ceec64ab3a97b86baaecf0e77506e7098132gsmith "DGLink" -> do
0c01ceec64ab3a97b86baaecf0e77506e7098132gsmith lnkId <- getAttrVal "linkid" e
1e83c8de3aa48b316b28057d53995272baf1260cwrowe edgeId <- maybe (fail "Static.FromXML.addChangeDG.DGLink.edgeId")
1e83c8de3aa48b316b28057d53995272baf1260cwrowe return $ readMaybe lnkId
1e83c8de3aa48b316b28057d53995272baf1260cwrowe src <- getAttrVal "source" e
e41fbd2619b62a029b4f32e67fd1a1a64b391875wrowe tar <- getAttrVal "target" e
e41fbd2619b62a029b4f32e67fd1a1a64b391875wrowe gmor <- getGMorphism e
e41fbd2619b62a029b4f32e67fd1a1a64b391875wrowe return LinkDG
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe { linkId = EdgeId edgeId
4d1b0ff0bb6735f8a7ec1936acc4bf587ef4db0dwrowe , source = parseNodeName src
4d1b0ff0bb6735f8a7ec1936acc4bf587ef4db0dwrowe , target = parseNodeName tar
483ed5892604266e702d65db4d0b2b621c488a09wrowe , linkType = concat $ getElementTexts "Type" e
483ed5892604266e702d65db4d0b2b621c488a09wrowe , gmorphism = gmor
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe "GMorphism" -> return GMorphismDG
4d1b0ff0bb6735f8a7ec1936acc4bf587ef4db0dwrowe { gmorphism = strContent e }
4d1b0ff0bb6735f8a7ec1936acc4bf587ef4db0dwrowe "Symbol" -> return SymbolDG
ec520097ee84be47111fe6b5e543a3080fa9c3dcwrowe { symbol = strContent e }
34e753c9dba1e821f54f0d4179f8774f854123eecolm en -> fail $ "Static.FromXML.addChangeDG: unexpected element: " ++ en
34e753c9dba1e821f54f0d4179f8774f854123eecolm AddAttr a -> return Affected
ec520097ee84be47111fe6b5e543a3080fa9c3dcwrowe { affected = qName $ attrKey a }
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe _ -> fail "Static.FromXML.addChangeDG: unexpected added change"
ec520097ee84be47111fe6b5e543a3080fa9c3dcwrowegetGMorphism :: Monad m => Element -> m String
bc21ce13cec2409c8fdb7122154636b2df97715ajerenkrantzgetGMorphism e = case getElementTexts "GMorphism" e of
bc21ce13cec2409c8fdb7122154636b2df97715ajerenkrantz [ s ] -> return s
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowegetDeclsOrSign :: Monad m => Element -> m DeclsOrSign
a985f6595e5da3e4b35bd91eab0a6eac3cbc8ae4fuankggetDeclsOrSign e = case findChildrenByLocalName "Declarations" e of
a985f6595e5da3e4b35bd91eab0a6eac3cbc8ae4fuankg [ d ] -> return DeclsDG { symbols = getElementTexts "Symbol" d }
a985f6595e5da3e4b35bd91eab0a6eac3cbc8ae4fuankg _ -> case getElementTexts "Signature" e of
06abbe9e2ee34c04b732fd000be5e31eb321eefegsmith [ str@(_ : _) ] -> return SignDG { sign = str }
6a5b8f7bd9abe819babda806a7245a31cd0dd2fbwrowechangeDG :: Monad m => Change -> m [AddChangeDG]
6a5b8f7bd9abe819babda806a7245a31cd0dd2fbwrowechangeDG (Change sel _) = case sel of
6a5b8f7bd9abe819babda806a7245a31cd0dd2fbwrowe Add _ cs -> mapM addChangeDG cs
ec520097ee84be47111fe6b5e543a3080fa9c3dcwrowe _ -> fail "Static.FromXML.addChangeDG: unexpected change"