Parse_AS_Structured.hs revision 89d5b892ca2fd8eb8f72dba097759a6d54f0a78c
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance Author: Till Mossakowski, Christian Maeder
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu Year: 2002/2003
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu Parsing the Structured part of hetrogenous specifications.
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu http://www.cofi.info/Documents/CASL/Summary/
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu from 25 March 2001
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu C.2.2 Structured Specifications
ed1b8e97e72b2e3e92edaf2eb22a4b5373d705f1Felix Gabriel Mance fixing of details concerning annos
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu logic translations
8dd62da91d8ac7cfa80cfaff34dc87bb4c2c855bFelix Gabriel Mancemodule Parse_AS_Structured where
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Manceimport Grothendieck
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Manceimport Logic_CASL -- we need the default logic
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Manceimport AS_Structured
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Manceimport AS_Library
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Manceimport AS_Annotation
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiuimport Anno_Parser
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Manceimport Id(tokPos)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Manceimport Keywords
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiuimport ParsecChar (digit)
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiuimport Maybe(maybeToList)
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiuimport Print_AS_Structured -- for test purposes
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiuimport Print_HetCASL
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu------------------------------------------------------------------------
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu-- annotation adapter
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu------------------------------------------------------------------------
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiu-- skip to leading annotation and read many
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiuannos :: GenParser Char st [Annotation]
5efb71382fdcce83a76a6d40e5f8def0462bf8a8Francisc Nicolae Bungiuannos = skip >> many (annotationL << skip)
67fc6fe7ffa26acdf15b246a26161a5872aff8bcFelix Gabriel ManceannoParser parser = bind (\x y -> Annoted y [] x []) annos parser
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceannoParser2 parser = bind (\x (Annoted y pos l r) -> Annoted y pos (x++l) r) annos parser
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceemptyAnno :: a -> Annoted a
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceemptyAnno x = Annoted x [] [] []
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance------------------------------------------------------------------------
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- simpleIds for spec- and view-name
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance------------------------------------------------------------------------
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel MancelogicS = "logic" -- new keyword
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel MancesimpleId = pToken (reserved (logicS:casl_reserved_words) scanAnyWords)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance------------------------------------------------------------------------
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- logic and encoding names
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance------------------------------------------------------------------------
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- exclude colon (because encoding must be recognized)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- ecclude dot to recognize optional sublogic name
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceotherChars = "_`"
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- better list what is allowed rather than exclude what is forbidden
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- white spaces und non-printables should be not allowed!
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceencodingName = pToken(reserved (funS:casl_reserved_words) (many1
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance (oneOf (otherChars ++ (signChars \\ ":."))
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> scanLPD)))
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- keep these identical in order to
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- decide after seeing ".", ":" or "->" what was meant
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel MancelogicName = do e <- encodingName
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance do string dotS
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance s <- encodingName
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance return (Logic_name e (Just s))
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> return (Logic_name e Nothing)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance------------------------------------------------------------------------
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- parse Logic_code
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance------------------------------------------------------------------------
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceparseLogic :: GenParser Char AnyLogic Logic_code
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance do l <- asKey logicS
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance do e <- logicName -- try to parse encoding or logic source after "logic"
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance Logic_name _ (Just _) -> parseOptLogTarget Nothing (Just e) [l]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance Logic_name f Nothing ->
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance do c <- asKey colonS
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance parseLogAfterColon (Just f) [l,c]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> parseOptLogTarget Nothing (Just e) [l]
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> do f <- asKey funS -- parse at least a logic target after "logic"
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance t <- logicName
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance return (Logic_code Nothing Nothing (Just t) (map tokPos [l,f]))
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- parse optional logic source and target after a colon (given an encoding e)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceparseLogAfterColon e l =
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance do s <- logicName
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance parseOptLogTarget e (Just s) l
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> return (Logic_code e (Just s) Nothing (map tokPos l))
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> parseOptLogTarget e Nothing l
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> return (Logic_code e Nothing Nothing (map tokPos l))
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- parse an optional logic target (given encoding e or source s)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceparseOptLogTarget e s l =
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance do f <- asKey funS
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance do t <- logicName
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance return (Logic_code e s (Just t) (map tokPos (l++[f])))
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> return (Logic_code e s Nothing (map tokPos (l++[f])))
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance------------------------------------------------------------------------
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- for parsing "," not followed by "logic" within G_mapping
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance------------------------------------------------------------------------
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- ParsecCombinator.notFollowedBy only allows to check for a single "tok"
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- thus a single Char.
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel MancenotFollowedWith :: GenParser tok st a -> GenParser tok st b
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance -> GenParser tok st a
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mancep1 `notFollowedWith` p2 = try ((p1 >> p2 >> pzero) <|> p1)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceplainComma = commaT `notFollowedWith` asKey logicS
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- rearrange list to keep current logic as first element
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- does not consume anything! (may only fail)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance{-switchLogic :: Logic_code -> LogicGraph -> GenParser Char st LogicGraph
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceswitchLogic n l@(Logic i : _) =
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance let s = case n of
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance Logic_code _ _ (Just (Logic_name t _)) _ -> tokStr t
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance _ -> language_name i
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance (f, r) = partition (\ (Logic x) -> language_name x == s) l
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance in if null f then fail ("unknown language " ++ s)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance else return (f++r)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance------------------------------------------------------------------------
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- parse G_mapping (if you modify this, do so for G_hiding, too!)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance------------------------------------------------------------------------
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceparseItemsMap :: GenParser Char AnyLogic (G_symb_map_items_list, [Token])
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceparseItemsMap =
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance do Logic id <- getState
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance (cs, ps) <- callParser (parse_symb_map_items id) (language_name id) "symbol maps"
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance `separatedBy` commaT
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance -- ??? should be plainComma, but does not work for reveal s,t!
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance return (G_symb_map_items_list id cs, ps)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceparseMapping :: LogicGraph -> GenParser Char AnyLogic ([G_mapping], [Token])
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceparseMapping l =
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance do n <- parseLogic
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance do c <- commaT
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance (gs, ps) <- parseMapping l
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance return (G_logic_translation n : gs, c:ps)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> return ([G_logic_translation n], [])
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> do (m, ps) <- parseItemsMap
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance do c <- commaT
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance (gs, qs) <- parseMapping l
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance return (G_symb_map m : gs, ps ++ c : qs)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance <|> return ([G_symb_map m], ps)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance------------------------------------------------------------------------
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance-- parse G_hiding (copied from above, but code sharing would be better!)
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance------------------------------------------------------------------------
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceparseItemsList :: LogicGraph -> GenParser Char AnyLogic (G_symb_items_list, [Token])
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel ManceparseItemsList l =
e5ea4eeaeefd3521ae3475719e18c96cf91637d5Felix Gabriel Mance do Logic id <- getState
67fc6fe7ffa26acdf15b246a26161a5872aff8bcFelix Gabriel Mance (cs, ps) <- callParser (parse_symb_items id) (language_name id) "symbols"
return (AS_Library.View_defn vn g vt symbMap
(map tokPos ([s1,s2] ++ ps ++ Maybe.maybeToList q)))
(map tokPos ([s1,s2]++ps++ Maybe.maybeToList q)))