Parse_AS_Library.hs revision 1cbee24256e1c03a06103283c9dd8dcd97a10f70
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiuModule : $Header$
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiuDescription : parser for CASL specification librariess
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiuCopyright : (c) Maciek Makowski, Uni Bremen 2002-2006
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiuLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiuMaintainer : Christian.Maeder@dfki.de
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiuStability : provisional
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiuPortability : non-portable(Grothendieck)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiuParser for CASL specification librariess
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu Follows Sect. II:3.1.5 of the CASL Reference Manual.
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiumodule Syntax.Parse_AS_Library (library) where
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiuimport Logic.Grothendieck (LogicGraph(currentLogic))
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiuimport Logic.Logic (AnyLogic(..), language_name)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (logicName, groupSpec, aSpec, parseMapping)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiuimport Data.List(intersperse)
a604cbad8e2202147b5c6bb9f2e06ae61162d654Felix Gabriel Manceimport Data.Maybe(maybeToList)
be2439588008221e691321fdf4f75432cfb72878Felix Gabriel Mance-- * Parsing functions
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu-- | Parse a library of specifications
b84c87f199dc287d235d7dad6ea344f6912ef531Christian Maederlibrary :: AnyLogic -> LogicGraph -> AParser st LIB_DEFN
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiulibrary (Logic lid) lG = do
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (ps, ln) <- option
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (nullRange, Lib_id $ Indirect_link libraryS nullRange "" noTime) $ do
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu s1 <- asKey libraryS
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return (tokPos s1, n)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu ls <- libItems lG { currentLogic = language_name lid }
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return (Lib_defn ln ls ps an)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu-- | Parse library name
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiulibName :: AParser st LIB_NAME
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu v <- option Nothing (fmap Just version)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return $ case v of
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu Nothing -> Lib_id libid
b84c87f199dc287d235d7dad6ea344f6912ef531Christian Maeder Just v1 -> Lib_version libid v1
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu-- | Parse the library version
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiuversion :: AParser st VERSION_NUMBER
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu s <- asKey versionS
b84c87f199dc287d235d7dad6ea344f6912ef531Christian Maeder n <- many1 digit `sepBy1` (string ".")
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return (Version_number n (tokPos s `appRange` Range [pos]))
be00381168b3f10192afabbba136fb06d3a9f358Christian Maeder-- | Parse library ID
be00381168b3f10192afabbba136fb06d3a9f358Christian MaederlibId :: AParser st LIB_ID
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu path <- scanAnyWords `sepBy1` (string "/")
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return $ Indirect_link (concat (intersperse "/" path)) (Range [pos])
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu -- ??? URL need to be added
d0f58d27c2536eba454d8f77de8617bc6a2c99cdFelix Gabriel Mance-- | Parse the library elements
d0f58d27c2536eba454d8f77de8617bc6a2c99cdFelix Gabriel MancelibItems :: LogicGraph -> AParser st [Annoted LIB_ITEM]
d0f58d27c2536eba454d8f77de8617bc6a2c99cdFelix Gabriel Mance (eof >> return [])
60f30f0eeeacdfc1e0dfe39664373ddf5a0675adFelix Gabriel Mance la <- lineAnnos
60f30f0eeeacdfc1e0dfe39664373ddf5a0675adFelix Gabriel Mance is <- libItems $ case r of
60f30f0eeeacdfc1e0dfe39664373ddf5a0675adFelix Gabriel Mance Logic_decl (Logic_name logN _) _ ->
0dd6e7830de0887c9a12356447975a826b3b3db2Christian Maeder l { currentLogic = tokStr logN }
60f30f0eeeacdfc1e0dfe39664373ddf5a0675adFelix Gabriel Mance [] -> return [Annoted r nullRange [] $ la ++ an]
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu Annoted i p nl ra : rs ->
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return $ Annoted r nullRange [] la : Annoted i p (an ++ nl) ra : rs
60f30f0eeeacdfc1e0dfe39664373ddf5a0675adFelix Gabriel Mance-- | Parse an element of the library
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiulibItem :: LogicGraph -> AParser st LIB_ITEM
9475501a6acf48434052d9e6f4a05ed6681eaaabFrancisc Nicolae Bungiu do s <- asKey specS
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu g <- generics l
0dd6e7830de0887c9a12356447975a826b3b3db2Christian Maeder (catPos ([s, e] ++ maybeToList q)))
60f30f0eeeacdfc1e0dfe39664373ddf5a0675adFelix Gabriel Mance <|> -- view defn
0dd6e7830de0887c9a12356447975a826b3b3db2Christian Maeder do s1 <- asKey viewS
0dd6e7830de0887c9a12356447975a826b3b3db2Christian Maeder vn <- simpleId
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu g <- generics l
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu s2 <- asKey ":"
d0f58d27c2536eba454d8f77de8617bc6a2c99cdFelix Gabriel Mance vt <- viewType l
60f30f0eeeacdfc1e0dfe39664373ddf5a0675adFelix Gabriel Mance (symbMap,ps) <- option ([],[])
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (do s <- equalT
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (m, _) <- parseMapping l
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return (m,[s]))
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return (Syntax.AS_Library.View_defn vn g vt symbMap
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (catPos ([s1, s2] ++ ps ++ maybeToList q)))
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu <|> -- unit spec
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu do kUnit <- asKey unitS
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu kSpec <- asKey specS
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu name <- simpleId
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu usp <- unitSpec l
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return (Syntax.AS_Library.Unit_spec_defn name usp
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (catPos ([kUnit, kSpec, kEqu] ++ maybeToList kEnd)))
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu <|> -- ref spec
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu do kRef <- asKey refinementS
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu name <- simpleId
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu rsp <- refSpec l
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return (Syntax.AS_Library.Ref_spec_defn name rsp
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (catPos ([kRef, kEqu] ++ maybeToList kEnd)))
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu <|> -- arch spec
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu do kArch <- asKey archS
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu kSpec <- asKey specS
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu name <- simpleId
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu asp <- annotedArchSpec l
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return (Syntax.AS_Library.Arch_spec_defn name asp
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (catPos ([kArch, kSpec, kEqu] ++ maybeToList kEnd)))
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu <|> -- download
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu do s1 <- asKey fromS
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu s2 <- asKey getS
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (il,ps) <- itemNameOrMap `separatedBy` anComma
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return (Download_items iln il
0dd6e7830de0887c9a12356447975a826b3b3db2Christian Maeder (catPos ([s1, s2] ++ ps ++ maybeToList q)))
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu do s1 <- asKey logicS
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu logN@(Logic_name t _) <- logicName
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return (Logic_decl logN (catPos [s1, t]))
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu <|> -- just a spec (turned into "spec spec = sp")
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu do a <- aSpec l
06acd8a23b2f06e7b2373d53f738cf56c7f03223Francisc Nicolae Bungiu return (Syntax.AS_Library.Spec_defn (mkSimpleId specS)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (Genericity (Params []) (Imported []) nullRange) a nullRange)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu-- | Parse view type
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiuviewType :: LogicGraph -> AParser st VIEW_TYPE
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu sp1 <- annoParser (groupSpec l)
be00381168b3f10192afabbba136fb06d3a9f358Christian Maeder sp2 <- annoParser (groupSpec l)
0dd6e7830de0887c9a12356447975a826b3b3db2Christian Maeder return (View_type sp1 sp2 $ tokPos s)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu-- | Parse item name or name map
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiuitemNameOrMap :: AParser st ITEM_NAME_OR_MAP
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiuitemNameOrMap = do
b84c87f199dc287d235d7dad6ea344f6912ef531Christian Maeder i1 <- simpleId
b84c87f199dc287d235d7dad6ea344f6912ef531Christian Maeder i' <- option Nothing $ do
b84c87f199dc287d235d7dad6ea344f6912ef531Christian Maeder s <- asKey "|->"
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return $ Just (i,s)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return $ case i' of
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu Nothing -> Item_name i1
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu Just (i2, s) -> Item_name_map i1 i2 $ tokPos s
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae BungiuoptEnd :: AParser st (Maybe Token)
624f8c31bd8d6746b93f4b5966aa6fc7680fefc5Felix Gabriel Mance (addAnnos >> option Nothing (fmap Just $ pToken $ keyWord $ string endS))
624f8c31bd8d6746b93f4b5966aa6fc7680fefc5Felix Gabriel Mance << addLineAnnos
624f8c31bd8d6746b93f4b5966aa6fc7680fefc5Felix Gabriel Mancegenerics :: LogicGraph -> AParser st GENERICITY
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (pa, ps1) <- params l
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (imp, ps2) <- option ([], nullRange) (imports l)
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return $ Genericity (Params pa) (Imported imp) $ appRange ps1 ps2
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiuparams :: LogicGraph -> AParser st ([Annoted SPEC],Range)
b84c87f199dc287d235d7dad6ea344f6912ef531Christian Maeder pas <- many (param l)
624f8c31bd8d6746b93f4b5966aa6fc7680fefc5Felix Gabriel Mance let (pas1, ps) = unzip pas
be00381168b3f10192afabbba136fb06d3a9f358Christian Maeder return (pas1, concatMapRange id ps)
624f8c31bd8d6746b93f4b5966aa6fc7680fefc5Felix Gabriel Manceparam :: LogicGraph -> AParser st (Annoted SPEC,Range)
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance c <- cBracketT
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu return (pa, toPos b [] c)
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Manceimports :: LogicGraph -> AParser st ([Annoted SPEC], Range)
86f318f607745d1f40cbf87048a13ac1c65100e6Felix Gabriel Mance s <- asKey givenS
ee93ea764a2b8189253e912c8447f9419033f6d4Francisc Nicolae Bungiu (sps, ps) <- annoParser (groupSpec l) `separatedBy` anComma
d0f58d27c2536eba454d8f77de8617bc6a2c99cdFelix Gabriel Mance return (sps, catPos (s:ps))