ParseItem.hs revision 9e0472be46104307b974fe5079bf5cc9e94a1a96
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens ElknerModule : $Header$
0992b212df8eec8af18e1c208da54897021964c4Christian MaederDescription : parser for HasCASL basic Items
0992b212df8eec8af18e1c208da54897021964c4Christian MaederCopyright : (c) Christian Maeder and Uni Bremen 2002-2005
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu ProdescuLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
0992b212df8eec8af18e1c208da54897021964c4Christian MaederMaintainer : Christian.Maeder@dfki.de
0992b212df8eec8af18e1c208da54897021964c4Christian MaederStability : provisional
0992b212df8eec8af18e1c208da54897021964c4Christian MaederPortability : portable
0992b212df8eec8af18e1c208da54897021964c4Christian Maederparser for HasCASL basic Items
0d3b1901921690f9ac499d03b08f63b44182481cChristian Maedermodule HasCASL.ParseItem (basicItems, basicSpec) where
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder-- * adapted item list parser (using 'itemAux')
d058429727dd696a0327cdc28cadd268c34c36baChristian MaederhasCaslItemList :: String -> AParser st b
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder -> ([Annoted b] -> Range -> a) -> AParser st a
d058429727dd696a0327cdc28cadd268c34c36baChristian MaederhasCaslItemList kw ip constr = do
0992b212df8eec8af18e1c208da54897021964c4Christian Maeder p <- pluralKeyword kw
720eeee7c9d8442093c8d05bed743193eee906e0Christian Maeder auxItemList hasCaslStartKeywords [p] ip constr
0a73a105711f90b75f4785fbe2bbdf16071b98a9Christian MaederhasCaslItemAux :: [Token] -> AParser st b -> ([Annoted b] -> Range -> a)
0a73a105711f90b75f4785fbe2bbdf16071b98a9Christian Maeder -> AParser st a
0a73a105711f90b75f4785fbe2bbdf16071b98a9Christian MaederhasCaslItemAux ps = auxItemList hasCaslStartKeywords ps
720eeee7c9d8442093c8d05bed743193eee906e0Christian Maeder-- * parsing type items
0d3b1901921690f9ac499d03b08f63b44182481cChristian MaedercommaTypeDecl :: TypePattern -> AParser st TypeItem
0d3b1901921690f9ac499d03b08f63b44182481cChristian MaedercommaTypeDecl s = do
0d3b1901921690f9ac499d03b08f63b44182481cChristian Maeder (is, cs) <- typePattern `separatedBy` anComma
0d3b1901921690f9ac499d03b08f63b44182481cChristian Maeder let l = s : is
0a73a105711f90b75f4785fbe2bbdf16071b98a9Christian Maeder subTypeDecl (l, p) <|> kindedTypeDecl (l, p)
0a73a105711f90b75f4785fbe2bbdf16071b98a9Christian Maeder <|> return (TypeDecl l universe $ catPos p)
0a73a105711f90b75f4785fbe2bbdf16071b98a9Christian MaederkindedTypeDecl :: ([TypePattern], [Token]) -> AParser st TypeItem
0a73a105711f90b75f4785fbe2bbdf16071b98a9Christian MaederkindedTypeDecl (l, p) = do
8cffae2c30c242f56abac2052d0b5691dc6e1784Christian Maeder let d = TypeDecl l s $ catPos $ p ++ [t]
a74f814d3b445eadad6f68737a98a7a303698affChristian Maeder [hd] -> pseudoTypeDef hd (Just s) [t] <|> dataDef hd s [t] <|> return d
2a5b885d9350ec6dd8bc4992ee91d2f68aa592f4Christian Maeder _ -> return d
8cffae2c30c242f56abac2052d0b5691dc6e1784Christian MaederisoDecl :: TypePattern -> AParser st TypeItem
0d3b1901921690f9ac499d03b08f63b44182481cChristian MaederisoDecl s = do
9ecf13b5fd914bc7272f1fc17348d7f4a8c77061Christian Maeder subTypeDefn (s, e) <|> do
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder (l, p) <- typePattern `separatedBy` equalT
0992b212df8eec8af18e1c208da54897021964c4Christian Maeder return $ IsoDecl (s : l) $ catPos $ e : p
720eeee7c9d8442093c8d05bed743193eee906e0Christian Maedervars :: AParser st Vars
8dfaa1b79cf2f92e897a034408954b4715f602b4Christian Maedervars = fmap Var var <|> do
d5833d2ee7bafcbf2fdd2bdfd9a728c769b100c7Christian Maeder (vs, ps) <- vars `separatedBy` anComma
d009a47a0497fe50dd3c11d3bb3ad639be3f947dChristian Maeder return $ VarTuple vs $ toPos o ps c
d009a47a0497fe50dd3c11d3bb3ad639be3f947dChristian MaedersubTypeDefn :: (TypePattern, Token) -> AParser st TypeItem
8cffae2c30c242f56abac2052d0b5691dc6e1784Christian MaedersubTypeDefn (s, e) = do
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder t <- parseType
d5833d2ee7bafcbf2fdd2bdfd9a728c769b100c7Christian Maeder d <- dotT -- or bar
ad5f48cb4f7d459e2c0fa67ea108243dcc399de2Christian Maeder let qs = toPos e [o,c,d] p
ad5f48cb4f7d459e2c0fa67ea108243dcc399de2Christian Maeder return $ SubtypeDefn s v t (Annoted f qs a []) qs
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian MaedersubTypeDecl :: ([TypePattern], [Token]) -> AParser st TypeItem
ad5f48cb4f7d459e2c0fa67ea108243dcc399de2Christian MaedersubTypeDecl (l, p) = do
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder s <- parseType
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder return $ SubtypeDecl l s $ catPos $ p ++ [t]
ad5f48cb4f7d459e2c0fa67ea108243dcc399de2Christian MaedersortItem :: AParser st TypeItem
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder s <- typePattern
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder subTypeDecl ([s],[])
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder <|> kindedTypeDecl ([s],[])
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder <|> commaTypeDecl s
d058429727dd696a0327cdc28cadd268c34c36baChristian Maeder <|> isoDecl s
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian Maeder <|> return (TypeDecl [s] universe nullRange)
22eea35d0effc6582b2951a28b5240fa7a82f3dfChristian MaedersortItems :: AParser st SigItems
d0c66a832d7b556e20ea4af4852cdc27a5463d51Christian MaedersortItems = hasCaslItemList sortS sortItem (TypeItems Plain)
do s <- try (addAnnos >> Common.Lexer.semiT << addLineAnnos)