Twelf2GR.hs revision e5b2824478ab2ec33bdcfe42a99eacf21b0edfd0
e1e8390280254f7f0580d701e583f670643d4f3fnilgunModule : $Header$
e1e8390280254f7f0580d701e583f670643d4f3fnilgunDescription : Conversion of Twelf files to LF signatures and morphisms
e1e8390280254f7f0580d701e583f670643d4f3fnilgunCopyright : (c) Kristina Sojakova, DFKI Bremen 2010
e1e8390280254f7f0580d701e583f670643d4f3fnilgunLicense : GPLv2 or higher, see LICENSE.txt
e1e8390280254f7f0580d701e583f670643d4f3fnilgunMaintainer : k.sojakova@jacobs-university.de
e1e8390280254f7f0580d701e583f670643d4f3fnilgunStability : experimental
e1e8390280254f7f0580d701e583f670643d4f3fnilgunPortability : portable
e1e8390280254f7f0580d701e583f670643d4f3fnilgunimport System.IO (hGetContents)
e1e8390280254f7f0580d701e583f670643d4f3fnilgunimport qualified Data.Map as Map
e1e8390280254f7f0580d701e583f670643d4f3fnilgunimport qualified Data.Set as Set
e1e8390280254f7f0580d701e583f670643d4f3fnilguntype NODE = (BASE,MODULE)
e1e8390280254f7f0580d701e583f670643d4f3fnilguntype LINK = (BASE,MODULE,NAME)
e1e8390280254f7f0580d701e583f670643d4f3fnilguntype SIGS = Map.Map MODULE Sign
e1e8390280254f7f0580d701e583f670643d4f3fnilguntype MORPHS = Map.Map ((MODULE,NAME),NODE,NODE) Morphism
e1e8390280254f7f0580d701e583f670643d4f3fnilguntype GRAPH = (SIGS,MORPHS)
e1e8390280254f7f0580d701e583f670643d4f3fnilguntype LIBS = Map.Map BASE GRAPH
e1e8390280254f7f0580d701e583f670643d4f3fnilguntype LIBS_EXT = ((LIBS,[BASE]),(BASE,GRAPH))
e1e8390280254f7f0580d701e583f670643d4f3fnilgunemptyGraph :: GRAPH
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomdocNS :: Maybe String
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomdocNS = Just "http://omdoc.org/ns"
e1e8390280254f7f0580d701e583f670643d4f3fnilgunopenMathNS :: Maybe String
e1e8390280254f7f0580d701e583f670643d4f3fnilgunopenMathNS = Just "http://www.openmath.org/OpenMath"
e1e8390280254f7f0580d701e583f670643d4f3fnilgunlfBase :: String
e1e8390280254f7f0580d701e583f670643d4f3fnilgunlfBase = "http://cds.omdoc.org/foundations/lf/lf.omdoc"
e1e8390280254f7f0580d701e583f670643d4f3fnilgunmmtBase :: String
e1e8390280254f7f0580d701e583f670643d4f3fnilgunlfMod :: String
e1e8390280254f7f0580d701e583f670643d4f3fnilgunlfMod = "lf"
e1e8390280254f7f0580d701e583f670643d4f3fnilgunmmtMod :: String
e1e8390280254f7f0580d701e583f670643d4f3fnilgunmmtMod = "mmt"
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomdocQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomdocQN = QName "omdoc" omdocNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilguntheoryQN :: QName
2704de98885368683621b01c8f8f4e4b01557611takashitheoryQN = QName "theory" omdocNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunviewQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunviewQN = QName "view" omdocNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunincludeQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunincludeQN = QName "include" omdocNS Nothing
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgunstructureQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunstructureQN = QName "structure" omdocNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunconstantQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunconstantQN = QName "constant" omdocNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunaliasQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunaliasQN = QName "alias" omdocNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunnotationQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunnotationQN = QName "notation" omdocNS Nothing
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilguntypeQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilguntypeQN = QName "type" omdocNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgundefinitionQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgundefinitionQN = QName "definition" omdocNS Nothing
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgunomobjQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomobjQN = QName "OMOBJ" openMathNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomsQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomsQN = QName "OMS" openMathNS Nothing
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgunomaQN :: QName
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgunomaQN = QName "OMA" openMathNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunombindQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunombindQN = QName "OMBIND" openMathNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunombvarQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunombvarQN = QName "OMBVAR" openMathNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomattrQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomattrQN = QName "OMATTR" openMathNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomatpQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomatpQN = QName "OMATP" openMathNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomvQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunomvQN = QName "OMV" openMathNS Nothing
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgunommorQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunommorQN = QName "OMMOR" omdocNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunconassQN :: QName
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgunconassQN = QName "conass" omdocNS Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunstrassQN :: QName
e1e8390280254f7f0580d701e583f670643d4f3fnilgunstrassQN = QName "strass" omdocNS Nothing
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilguntypeOMS :: Element
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Element omsQN [Attr baseQN lfBase,
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Attr moduleQN lfMod,
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Attr nameQN "type"] [] Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunarrowOMS :: Element
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Element omsQN [Attr baseQN lfBase,
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgun Attr moduleQN lfMod,
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Attr nameQN "arrow"] [] Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilgunlambdaOMS :: Element
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Element omsQN [Attr baseQN lfBase,
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Attr moduleQN lfMod,
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Attr nameQN "lambda"] [] Nothing
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgunpiOMS :: Element
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgun Element omsQN [Attr baseQN lfBase,
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgun Attr moduleQN lfMod,
2704de98885368683621b01c8f8f4e4b01557611takashi Attr nameQN "Pi"] [] Nothing
2704de98885368683621b01c8f8f4e4b01557611takashiimpLambdaOMS :: Element
2704de98885368683621b01c8f8f4e4b01557611takashiimpLambdaOMS =
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Element omsQN [Attr baseQN lfBase,
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgun Attr moduleQN lfMod,
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Attr nameQN "implicit_lambda"] [] Nothing
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgunimpPiOMS :: Element
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgun Element omsQN [Attr baseQN lfBase,
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgun Attr moduleQN lfMod,
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgun Attr nameQN "implicit_Pi"] [] Nothing
e0cfea1f5d38eeaa8fdf7c197c3c1eb31148e191nilgunoftypeOMS :: Element
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Element omsQN [Attr baseQN lfBase,
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Attr moduleQN lfMod,
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Attr nameQN "oftype"] [] Nothing
e1e8390280254f7f0580d701e583f670643d4f3fnilguncompOMS :: Element
e1e8390280254f7f0580d701e583f670643d4f3fnilgun Element omsQN [Attr baseQN mmtBase,
5effc8b39fae5cd169d17f342bfc265705840014rbowen Attr moduleQN mmtMod,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen Attr nameQN "composition"] [] Nothing
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowennameQN :: QName
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowennameQN = (QName "name" Nothing Nothing)
e1e8390280254f7f0580d701e583f670643d4f3fnilgunmoduleQN :: QName
{- returns the referenced base and module resolved w.r.t.
if (fp == b || Map.member fp l)
fst $ Map.findWithDefault er b libs
in Map.findWithDefault er m sigs1
snd $ Map.findWithDefault er b libs
morphs2 = Map.filterWithKey (\ (l,_,_) _ -> l == (m,n)) morphs1
in case Map.toList morphs2 of
let sigs1 = Map.insert (sigModule sig) sig sigs
morphs1 = Map.insert (l,s,t) m morphs
let morphs2 = Map.foldWithKey
in Map.insert k morph1 morphs1
) Map.empty morphs
(libs,_) <- twelf2GR fp (Map.empty,[])
let libs' = Map.insert b gr' libs
if (Set.member (getSym d) syms)
Morphism (sigBase sig2) (sigModule sig2) "" sig1 sig2 Definitional Map.empty
Morphism b2 m2 name (Sign b1 m1 []) tarSig Definitional Map.empty
Nothing -> Map.lookup s symmap
else Map.findWithDefault (Const s)
else Map.insert s e $ symMap morph
IO (Map.Map Symbol EXP, LIBS_EXT)
) (Map.empty,libs) els
conass2map :: Element -> (Map.Map Symbol EXP, LIBS_EXT) -> NODE -> NODE ->
IO (Map.Map Symbol EXP, LIBS_EXT)
let map1 = Map.insert (Symbol b m n) expr mapp
incl2map :: Element -> (Map.Map Symbol EXP, LIBS_EXT) -> NODE -> NODE ->
IO (Map.Map Symbol EXP, LIBS_EXT)
let map1 = Map.union mapp $ symMap mor
strass2map :: Element -> (Map.Map Symbol EXP, LIBS_EXT) -> NODE -> NODE ->
IO (Map.Map Symbol EXP, LIBS_EXT)
let map1 = Map.union mapp $ combineMorphs mor1 mor2
combineMorphs :: Morphism -> Morphism -> Map.Map Symbol EXP
in Set.fold ( \ s ->
in Map.insert s1 e1