OMDocOutput.hs revision b87efd3db0d2dc41615ea28669faf80fc1b48d56
module OMDoc.OMDocOutput
import qualified OMDoc.HetsDefs as Hets
import OMDoc.CASLOutput
import CASL.Sign
import CASL.AS_Basic_CASL as ABC
import Common.Consistency as Cons
import qualified Common.Id as Id
import qualified Common.LibName as ASL
import Common.Utils (splitOn, number)
import Driver.Options
import Static.DevGraph
import qualified Data.Graph.Inductive.Graph as Graph
import Text.XML.HXT.Parser
import qualified Text.XML.HXT.Parser as HXT hiding (run, trace, when)
import qualified Text.XML.HXT.DOM.XmlTreeTypes as HXTT hiding (when)
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Common.Lib.Rel as Rel
import qualified Common.AS_Annotation as Ann
import Data.List (find, intercalate)
import Debug.Trace (trace)
import System.Directory
import OMDoc.Util
import OMDoc.XmlHandling
import OMDoc.OMDocDefs
import qualified OMDoc.OMDocInterface as OMDoc
import qualified OMDoc.OMDocXml as OMDocXML
import qualified Network.URI as URI
import OMDoc.Sentences
caslImportURI::URI.URI
->HXTT.XNode -- ^ DOCTYPE-Element
www.mathweb.org does not provide the dtd anymore (or it is hidden..)
defaultDTDURI = <http://www.mathweb.org/src/mathweb/omdoc/dtd/omdoc.dtd>
defaultDTDURI = <https://svn.mathweb.org/repos/mathweb.org/trunk/omdoc/dtd/omdoc.dtd>
defaultDTDURI = "http://www.informatik.uni-bremen.de/~hiben/omdoc/dtd/omdoc.dtd"
((\(HXT.NTree a _) -> a) emptyRoot)
((HXT.NTree (mkOMDocTypeElem dtd' ) [])
((\(HXT.NTree a _) -> a) emptyRoot)
showOMDoc t = HXT.run' $
showOMDocDTD dtd' t = HXT.run' $
HXT.XmlTrees -- ^ tree to write
->IO HXT.XmlTrees -- ^ errors are wrapped inside 'XmlTrees'
writeOMDoc t f = HXT.run' $
writeOMDocDTD dtd' t f = HXT.run' $
->(ASL.LibName, LibEnv) -- ^ Name of the loaded library and the environment
flatNames = Hets.getFlatNames lenv
multiOrigins = Hets.getMultiOrigins lenv
if Set.size keepSets > 0
Map.insert mln keepSets i
(Hets.woOrigin i)
(Hets.woItem i)
Map.insert mln remapped tR
trying = Hets.findMultiOriginUnifications lenv interesting
identMap = Hets.identifyFlatNames lenv flatNames
remMap = Hets.removeReferencedIdentifiers flatNames identMap
useMap = Hets.getIdUseNumber remMap
unnMap = Hets.makeUniqueNames useMap
uniqueNames = Hets.makeUniqueIdNameMapping lenv unnMap
-- (_, collectionMap) = Hets.makeFullNames lenv unnMap identMap
collectionMap = Hets.makeCollectionMap lenv unnMap identMap
doesExists <- System.Directory.doesFileExist outfile
if (modtime /= ASL.noTime) && doesExists
System.Directory.createDirectoryIfMissing True (snd $ splitPath outfile)
(Map.keys lenv) -- all libnames
, Set.map (\(id', uN) -> (id', adjustStringForXmlName uN)) idNameSortSet
, Set.map (\(a, uN) -> (a, adjustStringForXmlName uN)) idNamePredSet
, Set.map (\(a, uN) -> (a, adjustStringForXmlName uN)) idNameOpSet
, Set.map (\(a, uN) -> (a, adjustStringForXmlName uN)) idNameSensSet
-- , Set.map (\(a, uN) -> (a, adjustStringForXmlName uN)) idNameConsSet
, Set.map (\(a, uN) -> (a, adjustStringForXmlName uN)) idNameGaPredSet
caslLogicImports::OMDoc.Imports
Static.DevGraph.LibEnv -- ^ library environment
->ASL.LibName -- ^ library (where link occures)
->[Hets.IdNameMapping] -- ^ mapping of unique names (Hets\<->OMDoc)
-- ->[Hets.IdNameMapping] -- ^ mapping of names (Hets\<->OMDoc)
e_fname = "OMDoc.OMDocOutput.createOMDefLink: "
(Just inm) -> Hets.inmGetNodeId inm
then OMDoc.ITLocal
else OMDoc.ITGlobal
fromuri = case URI.parseURIReference (liburl ++ "#" ++ fromname) of
->Static.DevGraph.LibEnv -- ^ library environment
->ASL.LibName -- ^ library (where link occures)
->[Hets.IdNameMapping] -- ^ mapping of unique names (Hets\<->OMDoc)
-- ->[Hets.IdNameMapping] -- ^ mapping of names (Hets\<->OMDoc)
e_fname = "OMDoc.OMDocOutput.createXmlThmLinkOM: "
(Just inm) -> Hets.inmGetNodeId inm
(Just inm) -> Hets.inmGetNodeId inm
touri = case URI.parseURIReference (toliburl ++ "#" ++ toname) of
fromuri = case URI.parseURIReference (liburl ++ "#" ++ fromname) of
OMDoc.morphismId = Nothing
, OMDoc.morphismHiding = []
, OMDoc.morphismBase = [iid ++ "-base"]
, OMDoc.morphismRequations = []
OMDoc.CNone -> Nothing
(OMDoc.AxiomInclusion fromuri touri mommorph (Just iid) cons, helpimports)
(OMDoc.TheoryInclusion fromuri touri mommorph (Just iid) cons, helpimports)
consConv _ = OMDoc.CNone
Static.DevGraph.LibEnv -- ^ library environment
->ASL.LibName -- ^ library (of morphism)
->[Hets.IdNameMapping] -- ^ mapping of unique names (Hets\<->OMDoc)
-- ->[Hets.IdNameMapping] -- ^ mapping of names (Hets\<->OMDoc)
->Maybe OMDoc.Morphism
e_fname = "OMDoc.OMDocOutput.createOMMorphism: "
caslmorph = Hets.getCASLMorphLL ll
fromIds = Hets.getIdentifierAt collectionMap (ln, from)
toIds = Hets.getIdentifierAt collectionMap (ln, to)
fromSortIds = Hets.getSortsAt collectionMap (ln, from)
fromPredIds = Hets.getPredsAt collectionMap (ln, from)
fromOpIds = Hets.getOpsAt collectionMap (ln, from)
toSortIds = Hets.getSortsAt collectionMap (ln, to)
toPredIds = Hets.getPredsAt collectionMap (ln, to)
toOpIds = Hets.getOpsAt collectionMap (ln, to)
Hets.inmFindLNNN (ln, from) names
Hets.inmFindLNNN (ln, to) names
if Hets.isEmptyMorphism caslmorph && null hidden
Just $ OMDoc.Morphism Nothing hidden [] reqs
idsInFrom = Hets.inmGetIdNameAllSet fromIdNameMapping
idsInTo = Hets.inmGetIdNameAllSet toIdNameMapping
->Set.Set (OpType, String)
emptyRelForSort::Rel.Rel SORT->SORT->Bool
null $ filter (\(s', _) -> s' == s) $ Rel.toList rel
->Rel.Rel SORT
->[OMDoc.Constructor] -- ^ contructors generated via 'createConstructorsOM'
->(OMDoc.ADT, [SORT])
(OMDoc.mkSymbolRef (adjustStringForXmlName sppUname))
--(OMDoc.mkSymbolRef (getSortIdName idNameMapping s''))
->Id.Id -- ^ Symbol to lookup
(Set.toList ss)
Hets.IdNameMapping -- ^ Mapping to use
->Id.Id -- ^ Sort to lookup
(error "OMDoc.OMDocOutput.getSortIdName: Cannot find name!")
lookupIdName (Hets.inmGetIdNameSortSet idNameMapping) sid
->ASL.LibName -- ^ Libary to process
->OMDoc.XmlId -- ^ Name (xml:id) for OMDoc-Document
->[Hets.IdNameMapping] -- ^ Mapping of unique names (Hets\<->XML)
->IO OMDoc.OMDoc
e_fname = "OMDoc.OMDocOutput.libEnvLibNameIdNameMappingToOMDoc: "
(map OMDoc.CIm dummyImports)
OMDoc.OMDoc omdocId initTheories thmLinksToRefsOM
caslsign = (\(Just a) -> a) $ Hets.getCASLSign (dgn_sign node)
(Hets.inmGetLibName inm) == ln
&& (Hets.inmGetNodeName inm) == dgnodename
&& (Hets.inmGetNodeNum inm) == nn
theoryXmlId = (Hets.inmGetNodeId uniqueidnamemapping)
(Hets.inmGetIdNameConstructors uniqueidnamemapping)
if (Set.size sortcons) > 0
case OMDoc.adtId newadt of
Debug.Trace.trace "ADT without ID..."
(Hets.idToString s)
|| ( (Set.size sortcons) > 0 )
-- ...else the ADT would say nothing
(Hets.getDefinedPredsAt collectionMap (ln, nn))
(Hets.getDefinedOpsAt collectionMap (ln, nn))
-- ...for every (tagged) theorem link...
(OMDoc.mkOMDocRef "casl")
, OMDoc.toElement isSym
-- translate formulas (axiom/definition + presentation)
(Hets.getNodeSentences node)
(map OMDoc.mkCIm theoryDummyImports)
(map OMDoc.mkCIm theoryDefLinks)
(map OMDoc.mkCSy theorySorts)
(map OMDoc.mkCSy theoryOps)
(map OMDoc.mkCSy theoryPreds)
(map OMDoc.mkCAd theoryADTs)
(map OMDoc.mkCSy omRecognizers)
(map OMDoc.mkCAx omAxs)
(map OMDoc.mkCDe omDefs)
alias for 'Hets.inmGetNodeId'
getNodeNameForXml::Hets.IdNameMapping->String
getNodeNameForXml = Hets.inmGetNodeId
-- | create an OMDoc-/symbol/ defining a predication.
ASL.LibName -- ^ library name of predication
->Graph.Node -- ^ node of predication
->[Hets.IdNameMapping] -- ^ unique name mapping
->(Id.Id, PredType) -- ^ predication to translate
e_fname = "OMDoc.OMDocOutput.predicationToXmlOM: "
preds = Hets.getPredsAt collectionMap (ln, nn)
(OMDoc.mkOMDocRef "casl")
OMDoc.mkOMSE Nothing "casl" "predication"
OMDoc.mkOMSE ab ao (adjustStringForXmlName an)
-- | create an OMDoc-/symbol/ defining an operator.
ASL.LibName -- ^ library name of operator
->Graph.Node -- ^ node of operator
->[Hets.IdNameMapping] -- ^ unique name mapping
->(Id.Id, OpType) -- ^ operator to translate
e_fname = "OMDoc.OMDocOutput.operatorToXmlOM: "
ops = Hets.getOpsAt collectionMap (ln, nn)
(OMDoc.mkOMDocRef "casl")
OMDoc.mkOMSE ab ao (adjustStringForXmlName an)
sortToXmlOM::XmlNamed SORT->OMDoc.Symbol
createLibName::ASL.LibName->String
-- Takes a list of 'Id.Pos'-file-positions and extracts the
(psm, _) <- foldl (\iomaps pos@(Id.SourcePos name' line _) ->
case Map.lookup name' linemap of
return (Map.insert pos (headorempty (drop (line-1) flines)) strmap,
fe <- System.Directory.doesFileExist name'
return (Map.insert pos (headorempty (drop (line-1) flines)) strmap,
Map.insert name' flines linemap)
ASL.LibName -- ^ library to search in
->[Hets.IdNameMapping] -- ^ unique name mapping
->[Hets.IdNameMapping] -- ^ name mapping
->Maybe (XmlName, Hets.IdNameMapping)
ASL.LibName -- ^ name of library to search in
->[Hets.IdNameMapping] -- ^ unique name mapping
->[Hets.IdNameMapping] -- ^ name mapping
->Rel.Rel SORT -- ^ sort relation for compatibility checks
->Maybe (XmlName, Hets.IdNameMapping)
uid == pr && upt == (Hets.cv_Pred_typeToPredType pt)
ASL.LibName -- ^ name of library to search in
->[Hets.IdNameMapping] -- ^ unique name mapping
->[Hets.IdNameMapping] -- ^ name mapping
->Rel.Rel SORT -- ^ sort relation for compatibility checks
->Maybe (XmlName, Hets.IdNameMapping)
uid == op && uot == (Hets.cv_Op_typeToOpType ot)
->ASL.LibName -- ^ library of formulas
->Graph.Node -- ^ node of formulas
->[Hets.IdNameMapping] -- ^ mapping of unique names
->[(Ann.Named CASLFORMULA)] -- ^ named formulas