{- |
Module      :  ./CSMOF/ParseXmiAsLibDefn.hs
Description :  CSMOF XMI parser
Copyright   :  (c) Daniel Calegari Universidad de la Republica, Uruguay 2013
License     :  GPLv2 or higher, see LICENSE.txt
Maintainer  :  dcalegar@fing.edu.uy
Stability   :  provisional
Portability :  portable
-}

module CSMOF.ParseXmiAsLibDefn where

import CSMOF.As
import CSMOF.Parser
import CSMOF.Logic_CSMOF

import Logic.Grothendieck

import Syntax.AS_Library
import Syntax.AS_Structured
import Common.AS_Annotation
import Common.IRI
import Common.Id
import Common.LibName

import Text.XML.Light


parseXmi :: FilePath -> String -> LIB_DEFN
parseXmi :: FilePath -> FilePath -> LIB_DEFN
parseXmi fp :: FilePath
fp contents :: FilePath
contents =
  case FilePath -> Maybe Element
forall s. XmlSource s => s -> Maybe Element
parseXMLDoc FilePath
contents of
    Nothing -> LibName -> [Annoted LIB_ITEM] -> Range -> [Annotation] -> LIB_DEFN
Lib_defn (FilePath -> LibName
emptyLibName (FilePath -> FilePath
convertFileToLibStr FilePath
fp)) [] Range
nullRange []
    Just el :: Element
el -> FilePath -> Element -> LIB_DEFN
parseCSMOFXmi FilePath
fp Element
el


parseCSMOFXmi :: FilePath -> Element -> LIB_DEFN
parseCSMOFXmi :: FilePath -> Element -> LIB_DEFN
parseCSMOFXmi filename :: FilePath
filename contentOfFile :: Element
contentOfFile = FilePath -> Metamodel -> LIB_DEFN
convertToLibDefN FilePath
filename (Element -> Metamodel
parseCSMOF Element
contentOfFile)


convertToLibDefN :: FilePath -> Metamodel -> LIB_DEFN
convertToLibDefN :: FilePath -> Metamodel -> LIB_DEFN
convertToLibDefN filename :: FilePath
filename el :: Metamodel
el = LibName -> [Annoted LIB_ITEM] -> Range -> [Annotation] -> LIB_DEFN
Lib_defn
                               (FilePath -> LibName
emptyLibName (FilePath -> LibName) -> FilePath -> LibName
forall a b. (a -> b) -> a -> b
$ FilePath -> FilePath
convertFileToLibStr FilePath
filename)
                               (CSMOF -> Annoted LIB_ITEM
forall lid. Language lid => lid -> Annoted LIB_ITEM
makeLogicItem CSMOF
CSMOF Annoted LIB_ITEM -> [Annoted LIB_ITEM] -> [Annoted LIB_ITEM]
forall a. a -> [a] -> [a]
: [Metamodel -> Annoted LIB_ITEM
convertoItem Metamodel
el])
                               Range
nullRange []


convertoItem :: Metamodel -> Annoted LIB_ITEM
convertoItem :: Metamodel -> Annoted LIB_ITEM
convertoItem el :: Metamodel
el = SPEC_NAME -> Annoted SPEC -> Annoted LIB_ITEM
makeSpecItem (SIMPLE_ID -> SPEC_NAME
simpleIdToIRI (SIMPLE_ID -> SPEC_NAME) -> SIMPLE_ID -> SPEC_NAME
forall a b. (a -> b) -> a -> b
$ FilePath -> SIMPLE_ID
mkSimpleId (FilePath -> SIMPLE_ID) -> FilePath -> SIMPLE_ID
forall a b. (a -> b) -> a -> b
$ Metamodel -> FilePath
metamodelName Metamodel
el) (Annoted SPEC -> Annoted LIB_ITEM)
-> Annoted SPEC -> Annoted LIB_ITEM
forall a b. (a -> b) -> a -> b
$ Metamodel -> Annoted SPEC
createSpec Metamodel
el


createSpec :: Metamodel -> Annoted SPEC
createSpec :: Metamodel -> Annoted SPEC
createSpec el :: Metamodel
el = G_basic_spec -> Annoted SPEC
makeSpec (G_basic_spec -> Annoted SPEC) -> G_basic_spec -> Annoted SPEC
forall a b. (a -> b) -> a -> b
$ CSMOF -> Metamodel -> G_basic_spec
forall lid sublogics basic_spec sentence symb_items symb_map_items
       sign morphism symbol raw_symbol proof_tree.
Logic
  lid
  sublogics
  basic_spec
  sentence
  symb_items
  symb_map_items
  sign
  morphism
  symbol
  raw_symbol
  proof_tree =>
lid -> basic_spec -> G_basic_spec
G_basic_spec CSMOF
CSMOF Metamodel
el