subTypeDecl (l, p) <|> kindedTypeDecl (l, p)
<|> return (TypeDecl l universe $ catRange p)
kindedTypeDecl :: ([TypePattern], [Token]) -> AParser st TypeItem
kindedTypeDecl (l, p) = do
let d = TypeDecl l s $ catRange $ p ++ [t]
[hd] -> pseudoTypeDef hd (Just s) [t] <|> dataDef hd s [t] <|> return d
isoDecl :: TypePattern -> AParser st TypeItem
subTypeDefn (s, e) <|> do
(l, p) <- typePattern `separatedBy` equalT
return $ IsoDecl (s : l) $ catRange $ e : p
vars = fmap Var var <|> do
(vs, ps) <- vars `separatedBy` anComma
return $ VarTuple vs $ toRange o ps c
subTypeDefn :: (TypePattern, Token) -> AParser st TypeItem
let qs = toRange e [o, c, d] p
return $ SubtypeDefn s v t (Annoted f qs a a2) qs
subTypeDecl :: ([TypePattern], [Token]) -> AParser st TypeItem
return $ SubtypeDecl l s $ catRange $ p ++ [t]
sortItem :: AParser st TypeItem
<|> kindedTypeDecl ([s], [])
<|> return (TypeDecl [s] universe nullRange)
sortItems :: AParser st SigItems
sortItems = hasCaslItemList sortS sortItem (TypeItems Plain)
typeItem :: AParser st TypeItem
<|> dataDef s universe []
<|> pseudoTypeDef s Nothing []
<|> kindedTypeDecl ([s], [])
<|> return (TypeDecl [s] universe nullRange)
typeItemList :: [Token] -> Instance -> AParser st SigItems
typeItemList ps = hasCaslItemAux ps typeItem . TypeItems
typeItems :: AParser st SigItems
do q <- pluralKeyword instanceS
typeItemList [p, q] Instance
<|> typeItemList [p] Plain
pseudoTypeDef :: TypePattern -> Maybe Kind -> [Token] -> AParser st TypeItem
return $ AliasType t k (simpleTypeScheme p) $ catRange $ l ++ [c]
component :: AParser st [Component]
(is, cs) <- opId `separatedBy` anComma
concatFst :: [[a]] -> Range -> ([a], Range)
concatFst as ps = (concat as, ps)
tupleComponent :: AParser st ([Component], Range)
tupleComponent = bracketParser component oParenT cParenT anSemi concatFst
altComponent :: AParser st ([Component], Range)
altComponent = tupleComponent <|> do
Id [tok] [] _ -> TypeToken tok
_ -> error "altComponent"
return ([NoSelector t], nullRange)
compType :: [Id] -> [Token] -> AParser st [Component]
let makeComps l1 l2 = case (l1, l2) of
([a], [b]) -> [Selector a Total t Other $ tokPos b]
(a : r, b : s) -> Selector a Total t Comma (tokPos b) : makeComps r s
_ -> error "makeComps: empty selector list"
return $ makeComps is $ cs ++ [c]
alternative :: AParser st Alternative
s <- pluralKeyword sortS <|> pluralKeyword typeS
(ts, cs) <- parseType `separatedBy` anComma
return $ Subtype ts $ catRange $ s : cs
let ps = concatMapRange snd cps
return $ Constructor i cs Partial $ appRange ps $ tokPos q
<|> return (Constructor i cs Total ps)
dataDef :: TypePattern -> Kind -> [Token] -> AParser st TypeItem
let aAlternative = liftM2 (\ i -> Annoted i nullRange [])
(Annoted v _ _ b : as, ps) <- aAlternative `separatedBy` barT
let aa = Annoted v nullRange a b : as
qs = catRange $ l ++ c : ps
(cs, cps) <- classId `separatedBy` anComma
return $ Datatype $ DatatypeDecl t k aa cs
$ appRange qs $ appRange (tokPos d) $ catRange cps
<|> return (Datatype (DatatypeDecl t k aa [] qs))
dataItem :: AParser st DatatypeDecl
Datatype d <- dataDef t k [c]
Datatype d <- dataDef t universe []
dataItems :: AParser st BasicItem
dataItems = hasCaslItemList typeS dataItem FreeDatatype
classDecl :: AParser st ClassDecl
(is, cs) <- classId `separatedBy` anComma
(ps, k) <- option ([], universe) $ pair (single $ lessT <|> colonT) kind
return $ ClassDecl is k $ catRange $ cs ++ ps
classItem :: AParser st ClassItem
is <- annosParser basicItems
return $ ClassItem c is $ toRange o [] p
<|> return (ClassItem c [] nullRange)
classItemList :: [Token] -> Instance -> AParser st BasicItem
classItemList ps = hasCaslItemAux ps classItem . ClassItems
classItems :: AParser st BasicItem
p <- asKey (classS ++ "es") <|> asKey classS <?> classS
do q <- pluralKeyword instanceS
classItemList [p, q] Instance
<|> classItemList [p] Plain
opAttr :: AParser st OpAttr
opAttr = let l = [Assoc, Comm, Idem] in
return $ BinOpAttr a $ tokPos b) l)
return $ UnitOpAttr t $ tokPos a
multiTypeScheme :: [PolyId] -> AParser st TypeScheme
multiTypeScheme os = case os of
p : r -> if null r || all ( \ (PolyId _ tys _) -> null tys) os
else fail $ "instantiation list in identifier list: "
++ show (map ( \ (PolyId i _ _) -> i) os)
opDecl :: [PolyId] -> [Token] -> AParser st OpItem
opAttrs os ps c t <|> return (OpDecl os t [] $ catRange $ ps ++ [c])
opAttrs :: [PolyId] -> [Token] -> Token -> TypeScheme -> AParser st OpItem
(attrs, cs) <- opAttr `separatedBy` anComma
return $ OpDecl os t attrs $ catRange $ ps ++ [c, d] ++ cs
opArg :: AParser st ([VarDecl], Range)
opArg = bracketParser varDecls oParenT cParenT anSemi concatFst
opArgs :: AParser st ([[VarDecl]], Range)
return (map fst cps, concatMapRange snd cps)
opDeclOrDefn :: PolyId -> AParser st OpItem
opAttrs [o] [] c t <|> opTerm o [] nullRange c t
<|> return (OpDecl [o] t [] $ tokPos c)
t <- fmap simpleTypeScheme parseType
opTerm :: PolyId -> [[VarDecl]] -> Range -> Token -> TypeScheme
return $ OpDefn o as sc f $ appRange ps $ toRange c [] e
opItem :: AParser st OpItem
(os, ps) <- parsePolyId `separatedBy` anComma
opItems :: AParser st SigItems
opItems = hasCaslItemList opS opItem (OpItems Op)
<|> hasCaslItemList functS opItem (OpItems Fun)
-- * parse pred items as op items
predDecl :: [PolyId] -> [Token] -> AParser st OpItem
let p = catRange $ ps ++ [c]
return $ OpDecl os (predTypeScheme p t) [] p
predDefn :: PolyId -> AParser st OpItem
let p = appRange ps $ tokPos e
(simpleTypeScheme $ mkLazyType $ unitTypeWithRange p) f p
predItem :: AParser st OpItem
(os, ps) <- parsePolyId `separatedBy` anComma
[hd] -> d <|> predDefn hd
predItems :: AParser st SigItems
predItems = hasCaslItemList predS predItem (OpItems Pred)
sigItems :: AParser st SigItems
sigItems = sortItems <|> opItems <|> predItems <|> typeItems
generatedItems :: AParser st BasicItem
do FreeDatatype ds ps <- dataItems
return $ GenItems [Annoted (TypeItems Plain (map ( \ d -> Annoted
(Datatype $ item d) nullRange (l_annos d) (r_annos d)) ds) ps)
nullRange [] []] $ tokPos g
is <- annosParser sigItems
return $ GenItems is $ toRange g [o] c
genVarItems :: AParser st ([GenVarDecl], [Token])
do s <- trySemi << addLineAnnos
do tryItemEnd hasCaslStartKeywords
return (vs ++ ws, s : ts)
freeDatatype :: AParser st BasicItem
FreeDatatype ds ps <- dataItems
return $ FreeDatatype ds $ appRange (tokPos f) ps
progItems :: AParser st BasicItem
progItems = hasCaslItemList programS
(patternTermPair [equalS] (WithIn, []) equalS) ProgItems
axiomItems :: AParser st BasicItem
axiomItems = hasCaslItemList axiomS term $ AxiomItems []
forallItem :: AParser st BasicItem
(vs, ps) <- genVarDecls `separatedBy` anSemi
AxiomItems _ (Annoted ft qs as rs : fs) ds <- dotFormulae
let aft = Annoted ft qs (a ++ as) rs
return $ AxiomItems (concat vs) (aft : fs) $ appRange (catRange $ f : ps) ds
genVarItem :: AParser st BasicItem
return $ GenVarItems vs $ catRange $ v : ps
dotFormulae :: AParser st BasicItem
(fs, ds) <- allAnnoParser term `separatedBy` dotT
let ps = catRange $ d : ds
if null $ r_annos lst then do
return $ AxiomItems [] (init fs ++ [appendAnno lst an]) $ appRange ps
else return $ AxiomItems [] fs ps
internalItems :: AParser st BasicItem
is <- annosParser basicItems
return (Internal is $ toRange i [o] p)
basicItems :: AParser st BasicItem
basicItems = fmap SigItems sigItems
basicSpec :: AParser st BasicSpec
basicSpec = fmap BasicSpec (annosParser basicItems)