ParseItem.hs revision a21be3ba0cb875d618b2b227f7c23e2ccc0bcb3b
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuModule : $Header$
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuDescription : parser for HasCASL basic Items
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuCopyright : (c) Christian Maeder and Uni Bremen 2002-2005
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuLicense : similar to LGPL, see HetCATS/LICENSE.txt or LIZENZ.txt
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuMaintainer : Christian.Maeder@dfki.de
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuStability : provisional
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuPortability : portable
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savuparser for HasCASL basic Items
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savumodule HasCASL.ParseItem (basicItems, basicSpec) where
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu-- * adapted item list parser (using 'itemAux')
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst SchulzhasCaslItemList :: String -> AParser st b
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu -> ([Annoted b] -> Range -> a) -> AParser st a
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavuhasCaslItemList kw ip constr = do
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu p <- pluralKeyword kw
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz auxItemList hasCaslStartKeywords [p] ip constr
ad2e68e571352b6759441733df697e075ceed341Robert SavuhasCaslItemAux :: [Token] -> AParser st b -> ([Annoted b] -> Range -> a)
ad2e68e571352b6759441733df697e075ceed341Robert Savu -> AParser st a
ad2e68e571352b6759441733df697e075ceed341Robert SavuhasCaslItemAux ps = auxItemList hasCaslStartKeywords ps
ad2e68e571352b6759441733df697e075ceed341Robert Savu-- * parsing type items
ad2e68e571352b6759441733df697e075ceed341Robert SavucommaTypeDecl :: TypePattern -> AParser st TypeItem
ad2e68e571352b6759441733df697e075ceed341Robert SavucommaTypeDecl s = do
ad2e68e571352b6759441733df697e075ceed341Robert Savu c <- anComma
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu (is, cs) <- typePattern `separatedBy` anComma
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu let l = s : is
ad2e68e571352b6759441733df697e075ceed341Robert Savu subTypeDecl (l, p) <|> kindedTypeDecl (l, p)
ad2e68e571352b6759441733df697e075ceed341Robert Savu <|> return (TypeDecl l universe $ catPos p)
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavukindedTypeDecl :: ([TypePattern], [Token]) -> AParser st TypeItem
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavukindedTypeDecl (l, p) = do
ad2e68e571352b6759441733df697e075ceed341Robert Savu let d = TypeDecl l s $ catPos $ p ++ [t]
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz [hd] -> pseudoTypeDef hd (Just s) [t] <|> dataDef hd s [t] <|> return d
ad2e68e571352b6759441733df697e075ceed341Robert Savu _ -> return d
ad2e68e571352b6759441733df697e075ceed341Robert SavuisoDecl :: TypePattern -> AParser st TypeItem
ad2e68e571352b6759441733df697e075ceed341Robert SavuisoDecl s = do
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu subTypeDefn (s, e) <|> do
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu (l, p) <- typePattern `separatedBy` equalT
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savu return $ IsoDecl (s : l) $ catPos $ e : p
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuvars :: AParser st Vars
ad306df140215d8fb88d14bbb7d685011e0f770bRobert Savuvars = fmap Var var <|> do
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu o <- oParenT
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu (vs, ps) <- vars `separatedBy` anComma
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu c <- cParenT
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu return $ VarTuple vs $ toPos o ps c
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavusubTypeDefn :: (TypePattern, Token) -> AParser st TypeItem
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst SchulzsubTypeDefn (s, e) = do
ad2e68e571352b6759441733df697e075ceed341Robert Savu o <- oBraceT
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz t <- parseType
ad2e68e571352b6759441733df697e075ceed341Robert Savu d <- dotT -- or bar
e09066e7b76cea97557974b825bb057455b24ab0Robert Savu p <- cBraceT
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert Savu let qs = toPos e [o,c,d] p
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz return $ SubtypeDefn s v t (Annoted f qs a []) qs
b3df7e69d4d6066fdfae0a8a2f3b4a161eaaf540Robert SavusubTypeDecl :: ([TypePattern], [Token]) -> AParser st TypeItem
ad306df140215d8fb88d14bbb7d685011e0f770bRobert SavusubTypeDecl (l, p) = do
ad2e68e571352b6759441733df697e075ceed341Robert Savu s <- parseType
ad2e68e571352b6759441733df697e075ceed341Robert Savu return $ SubtypeDecl l s $ catPos $ p ++ [t]
ad2e68e571352b6759441733df697e075ceed341Robert SavusortItem :: AParser st TypeItem
ad2e68e571352b6759441733df697e075ceed341Robert SavusortItem = do
a9c461443a740732a62d58c1c465b88cba3c606bRobert Savu s <- typePattern
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz subTypeDecl ([s],[])
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz <|> kindedTypeDecl ([s],[])
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz <|> commaTypeDecl s
0a03acf9fa28e6ff00f4d7c9c6acbae64cf09c56Ewaryst Schulz <|> isoDecl s
do s <- try (addAnnos >> Common.Lexer.semiT << addLineAnnos)