Twelf2GR.hs revision 98890889ffb2e8f6f722b00e265a211f13b5a861
d49d75f5073294d798aa500728116309398bb535Andreas GustafssonModule : $Header$
800f99741c01cfb1b9a0294688349398bc8a0271Automatic UpdaterDescription : Conversion of Twelf files to LF signatures and morphisms
dafcb997e390efa4423883dafd100c975c4095d6Mark AndrewsCopyright : (c) Kristina Sojakova, DFKI Bremen 2010
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David LawrenceLicense : GPLv2 or higher, see LICENSE.txt
d49d75f5073294d798aa500728116309398bb535Andreas GustafssonMaintainer : k.sojakova@jacobs-university.de
d49d75f5073294d798aa500728116309398bb535Andreas GustafssonStability : experimental
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David LawrencePortability : portable
d49d75f5073294d798aa500728116309398bb535Andreas Gustafssonimport System.IO (hGetContents)
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas Gustafssonimport qualified Data.Map as Map
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas Gustafssonimport qualified Data.Set as Set
683e751c957d8b209cc393ff603bea937f5565b0Mark Andrewstype NODE = (BASE,MODULE)
683e751c957d8b209cc393ff603bea937f5565b0Mark Andrewstype LINK = (BASE,MODULE,NAME)
683e751c957d8b209cc393ff603bea937f5565b0Mark Andrewstype SIGS = Map.Map MODULE Sign
d49d75f5073294d798aa500728116309398bb535Andreas Gustafssontype MORPHS = Map.Map ((MODULE,NAME),NODE,NODE) Morphism
a60f32928e486c147fa66d74ba02eda74a5d1d42Mark Andrewstype GRAPH = (SIGS,MORPHS)
a60f32928e486c147fa66d74ba02eda74a5d1d42Mark Andrewstype LIBS = Map.Map BASE GRAPH
38bcbbf947f0611bcae2e127d004dab761770c64Mark Andrewstype LIBS_EXT = ((LIBS,[BASE]),(BASE,GRAPH))
a60f32928e486c147fa66d74ba02eda74a5d1d42Mark AndrewsemptyGraph :: GRAPH
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsomdocNS :: Maybe String
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsopenMathNS :: Maybe String
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsopenMathNS = Just "http://www.openmath.org/OpenMath"
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewslfBase :: String
a60f32928e486c147fa66d74ba02eda74a5d1d42Mark AndrewslfBase = "http://cds.omdoc.org/foundations/lf/lf.omdoc"
a60f32928e486c147fa66d74ba02eda74a5d1d42Mark AndrewsmmtBase :: String
a60f32928e486c147fa66d74ba02eda74a5d1d42Mark AndrewsmmtBase = "http://cds.omdoc.org/omdoc/mmt.omdoc"
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewslfMod :: String
d49d75f5073294d798aa500728116309398bb535Andreas GustafssonmmtMod :: String
d49d75f5073294d798aa500728116309398bb535Andreas GustafssonomdocQN :: QName
d49d75f5073294d798aa500728116309398bb535Andreas GustafssonomdocQN = QName "omdoc" omdocNS Nothing
d49d75f5073294d798aa500728116309398bb535Andreas GustafssontheoryQN :: QName
d49d75f5073294d798aa500728116309398bb535Andreas GustafssontheoryQN = QName "theory" omdocNS Nothing
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsviewQN :: QName
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsviewQN = QName "view" omdocNS Nothing
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsincludeQN :: QName
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsincludeQN = QName "include" omdocNS Nothing
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsstructureQN :: QName
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsstructureQN = QName "structure" omdocNS Nothing
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsconstantQN :: QName
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsconstantQN = QName "constant" omdocNS Nothing
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsaliasQN :: QName
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsaliasQN = QName "alias" omdocNS Nothing
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsnotationQN :: QName
d49d75f5073294d798aa500728116309398bb535Andreas GustafssonnotationQN = QName "notation" omdocNS Nothing
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewstypeQN :: QName
d49d75f5073294d798aa500728116309398bb535Andreas GustafssontypeQN = QName "type" omdocNS Nothing
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas GustafssondefinitionQN :: QName
8f9755413f8814bbabbad40c850a81be52e05623Mark AndrewsdefinitionQN = QName "definition" omdocNS Nothing
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas GustafssonomobjQN :: QName
a60f32928e486c147fa66d74ba02eda74a5d1d42Mark AndrewsomobjQN = QName "OMOBJ" openMathNS Nothing
7964553eb43ab5146475841540c1c0d977e08b30Mark AndrewsomsQN :: QName
a26e1cacef2047b1048febd5e8d756060b4bddb1Evan HuntomsQN = QName "OMS" openMathNS Nothing
7964553eb43ab5146475841540c1c0d977e08b30Mark AndrewsomaQN :: QName
7964553eb43ab5146475841540c1c0d977e08b30Mark AndrewsomaQN = QName "OMA" openMathNS Nothing
7964553eb43ab5146475841540c1c0d977e08b30Mark AndrewsombindQN :: QName
7964553eb43ab5146475841540c1c0d977e08b30Mark AndrewsombindQN = QName "OMBIND" openMathNS Nothing
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas GustafssonombvarQN :: QName
b043b56271060295bd32f61e7b7221dd40fb60dcMark AndrewsombvarQN = QName "OMBVAR" openMathNS Nothing
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas GustafssonomattrQN :: QName
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas GustafssonomattrQN = QName "OMATTR" openMathNS Nothing
d49d75f5073294d798aa500728116309398bb535Andreas GustafssonomatpQN :: QName
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsomatpQN = QName "OMATP" openMathNS Nothing
d49d75f5073294d798aa500728116309398bb535Andreas GustafssonomvQN = QName "OMV" openMathNS Nothing
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsommorQN :: QName
a26e1cacef2047b1048febd5e8d756060b4bddb1Evan HuntommorQN = QName "OMMOR" omdocNS Nothing
d49d75f5073294d798aa500728116309398bb535Andreas GustafssonconassQN :: QName
38bcbbf947f0611bcae2e127d004dab761770c64Mark AndrewsconassQN = QName "conass" omdocNS Nothing
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas GustafssonstrassQN :: QName
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas GustafssonstrassQN = QName "strass" omdocNS Nothing
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas GustafssontypeOMS :: Element
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas Gustafsson Element omsQN [Attr baseQN lfBase,
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas Gustafsson Attr moduleQN lfMod,
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas Gustafsson Attr nameQN "type"] [] Nothing
c4213ed935163b25bde9273a7c1a79a6296a0662Andreas GustafssonarrowOMS :: Element
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson Element omsQN [Attr baseQN lfBase,
6e8a02d5d3a845ca1768e92c88bdc0a4da47f95bAndreas Gustafsson Attr moduleQN lfMod,
6e8a02d5d3a845ca1768e92c88bdc0a4da47f95bAndreas Gustafsson Attr nameQN "arrow"] [] Nothing
6e8a02d5d3a845ca1768e92c88bdc0a4da47f95bAndreas GustafssonlambdaOMS :: Element
6e8a02d5d3a845ca1768e92c88bdc0a4da47f95bAndreas Gustafsson Element omsQN [Attr baseQN lfBase,
52f16aeb304bc13f6957e3ecf24c8c5b69991558Andreas Gustafsson Attr moduleQN lfMod,
7d97663b2ca5b7b057276fc9d239025da80e4756Mark Andrews Attr nameQN "lambda"] [] Nothing
6e8a02d5d3a845ca1768e92c88bdc0a4da47f95bAndreas GustafssonpiOMS :: Element
52f16aeb304bc13f6957e3ecf24c8c5b69991558Andreas Gustafsson Element omsQN [Attr baseQN lfBase,
8a86c12ec245eb3838f48ffbc5a01fb9b7666a60Evan Hunt Attr moduleQN lfMod,
7c87a8bf7bc525f9b3ce80e7c12928a226e37d2bMark Andrews Attr nameQN "Pi"] [] Nothing
a26e1cacef2047b1048febd5e8d756060b4bddb1Evan HuntimpLambdaOMS :: Element
a26e1cacef2047b1048febd5e8d756060b4bddb1Evan HuntimpLambdaOMS =
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson Element omsQN [Attr baseQN lfBase,
2e286ac71f3621c11a3409f35a859488026b5fb5Mark Andrews Attr moduleQN lfMod,
61d7ab455fe6c2c1be112e7f48a768b9db1f65bbMark Andrews Attr nameQN "implicit_lambda"] [] Nothing
61d7ab455fe6c2c1be112e7f48a768b9db1f65bbMark AndrewsimpPiOMS :: Element
61d7ab455fe6c2c1be112e7f48a768b9db1f65bbMark Andrews Element omsQN [Attr baseQN lfBase,
61d7ab455fe6c2c1be112e7f48a768b9db1f65bbMark Andrews Attr moduleQN lfMod,
2e286ac71f3621c11a3409f35a859488026b5fb5Mark Andrews Attr nameQN "implicit_Pi"] [] Nothing
c85ffa76df4b94e0c44b2924f7a7f2e875a1ea86Mark AndrewsoftypeOMS :: Element
c85ffa76df4b94e0c44b2924f7a7f2e875a1ea86Mark Andrews Element omsQN [Attr baseQN lfBase,
c85ffa76df4b94e0c44b2924f7a7f2e875a1ea86Mark Andrews Attr moduleQN lfMod,
c85ffa76df4b94e0c44b2924f7a7f2e875a1ea86Mark Andrews Attr nameQN "oftype"] [] Nothing
c85ffa76df4b94e0c44b2924f7a7f2e875a1ea86Mark AndrewscompOMS :: Element
c85ffa76df4b94e0c44b2924f7a7f2e875a1ea86Mark Andrews Element omsQN [Attr baseQN mmtBase,
4347f7ac1286aaa114935823c3cd59151de0166bMark Andrews Attr moduleQN mmtMod,
4347f7ac1286aaa114935823c3cd59151de0166bMark Andrews Attr nameQN "composition"] [] Nothing
3d2ce18535b3d2d828bd40aec7f4686519f305feMark AndrewsnameQN :: QName
3d2ce18535b3d2d828bd40aec7f4686519f305feMark AndrewsnameQN = (QName "name" Nothing Nothing)
3d2ce18535b3d2d828bd40aec7f4686519f305feMark AndrewsmoduleQN :: QName
3d2ce18535b3d2d828bd40aec7f4686519f305feMark AndrewsmoduleQN = (QName "module" Nothing Nothing)
3d2ce18535b3d2d828bd40aec7f4686519f305feMark AndrewsbaseQN :: QName
3d2ce18535b3d2d828bd40aec7f4686519f305feMark AndrewsbaseQN = (QName "base" Nothing Nothing)
4347f7ac1286aaa114935823c3cd59151de0166bMark AndrewsfromQN :: QName
4347f7ac1286aaa114935823c3cd59151de0166bMark AndrewsfromQN = (QName "from" Nothing Nothing)
4347f7ac1286aaa114935823c3cd59151de0166bMark AndrewstoQN :: QName
4347f7ac1286aaa114935823c3cd59151de0166bMark AndrewstoQN = (QName "to" Nothing Nothing)
4347f7ac1286aaa114935823c3cd59151de0166bMark AndrewsomdocE :: String
4347f7ac1286aaa114935823c3cd59151de0166bMark AndrewsomdocE = "omdoc"
4347f7ac1286aaa114935823c3cd59151de0166bMark AndrewstwelfE :: String
4347f7ac1286aaa114935823c3cd59151de0166bMark AndrewstwelfE = "elf"
4347f7ac1286aaa114935823c3cd59151de0166bMark Andrews-- path to the Twelf folder must be set in the environment variable TWELF_LIB
4347f7ac1286aaa114935823c3cd59151de0166bMark Andrewstwelf :: String
4347f7ac1286aaa114935823c3cd59151de0166bMark Andrewstwelf = "check-some"
4347f7ac1286aaa114935823c3cd59151de0166bMark Andrewsoptions :: [String]
4347f7ac1286aaa114935823c3cd59151de0166bMark Andrewsoptions = ["-omdoc"]
4347f7ac1286aaa114935823c3cd59151de0166bMark Andrews------------------------------------------------------------------------------
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson------------------------------------------------------------------------------
d49d75f5073294d798aa500728116309398bb535Andreas Gustafsson-- HELPER FUNCTIONS
1090574e9153ad41c403f812d9b6cef0334e828eMark AndrewsgetFromAttr :: Element -> String
d49d75f5073294d798aa500728116309398bb535Andreas GustafssongetFromAttr e =
{- returns the referenced base and module resolved w.r.t.
if (file == b || Map.member file 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