topdecl :: HParser Declaration
topdecl = addRange (
    do
        lexDATA
        st <- simpleType
        lexASG
        cs <- constrs
        ds <- option [] derivings
        return (\r -> Declaration_Data r [] st cs ds)
    <|>
    do
        lexTYPE
        st <- simpleType
        lexASG
        t <- type_
        return $ \r -> Declaration_Type r st t
    <|>
-- Declaration_Class (Range) (ContextItems) (SimpleType) (MaybeDeclarations)
{-
cdecls :: HParser Declarations
cdecls =
    do
     ds <- withLayout cdecl
     return (CollectFunctionBindings.cdecls ds)
-}
    do
        lexCLASS
        ct <- option [] (try $ do {c <- scontext ; lexDARROW ; return c} )
        st <- simpleType
        ds <- option MaybeDeclarations_Nothing 
                     (try $ do lexWHERE
                               d <-  option MaybeDeclarations_Nothing (try $ do  
                                                                               cds <- cdecls 
                                                                               return (MaybeDeclarations_Just cds))                                                     
                               return d)
        return $ \r -> Declaration_Class r ct st ds
    <|>
-- Declaration_Instance (Range) (ContextItems) (Name) (Types) (MaybeDeclarations)
    do
        lexINSTANCE
        ct <- option [] (try $ do {c <- scontext; lexDARROW ; return c} )
        n  <- tycls
        ts <- iType
        ds <- option MaybeDeclarations_Nothing (try $ do lexWHERE
                                                         d <- idecls
                                                         return (MaybeDeclarations_Just d))
        return $ \r -> Declaration_Instance r ct n [ts] ds
    <|>
    infixdecl
    ) 
    <|> addRange (
      do
         lexHOLE
         jb <- optionMaybe normalRhs
         case jb  of
            Just b ->  return $ \r -> Declaration_PatternBinding r (Pattern_Hole r (-1)) b
            Nothing -> return $ \r -> Declaration_Hole r (-1)
      )
    <|>
    decl
    <?> Texts.parserDeclaration
topdecl :: HParser Declaration
topdecl = addRange (
    do
        lexDATA
        st <- simpleType
        lexASG
        cs <- constrs
        ds <- option [] derivings
        return (\r -> Declaration_Data r [] st cs ds)
    <|>
    do
        lexTYPE
        st <- simpleType
        lexASG
        t <- type_
        return $ \r -> Declaration_Type r st t
    <|>
-- Declaration_Class (Range) (ContextItems) (SimpleType) (MaybeDeclarations)
{-
cdecls :: HParser Declarations
cdecls =
    do
     ds <- withLayout cdecl
     return (CollectFunctionBindings.cdecls ds)
-}
    do
        lexCLASS
        ct <- option [] (try $ do {c <- scontext ; lexDARROW ; return c} )
        st <- simpleType
        ds <- option MaybeDeclarations_Nothing 
                     (try $ do lexWHERE
                               d <-  option MaybeDeclarations_Nothing (try $ do  
                                                                               cds <- cdecls 
                                                                               return (MaybeDeclarations_Just cds))                                                     
                               return d)
        return $ \r -> Declaration_Class r ct st ds
    <|>
-- Declaration_Instance (Range) (ContextItems) (Name) (Types) (MaybeDeclarations)
    do
        lexINSTANCE
        ct <- option [] (try $ do {c <- scontext; lexDARROW ; return c} )
        n  <- tycls
        ts <- iType
        ds <- option MaybeDeclarations_Nothing (try $ do lexWHERE
                                                         d <- idecls
                                                         return (MaybeDeclarations_Just d))
        return $ \r -> Declaration_Instance r ct n [ts] ds
    <|>
    infixdecl
    ) 
    <|> addRange (
      do
         lexHOLE
         jb <- optionMaybe normalRhs
         case jb  of
            Just b ->  return $ \r -> Declaration_PatternBinding r (Pattern_Hole r (-1)) b
            Nothing -> return $ \r -> Declaration_Hole r (-1)
      )
    <|>
    decl
    <?> Texts.parserDeclaration
topdecl = addRange (
    do
        lexDATA
        st <- simpleType
        lexASG
        cs <- constrs
        ds <- option [] derivings
        return (\r -> Declaration_Data r [] st cs ds)
    <|>
    do
        lexTYPE
        st <- simpleType
        lexASG
        t <- type_
        return $ \r -> Declaration_Type r st t
    <|>
-- Declaration_Class (Range) (ContextItems) (SimpleType) (MaybeDeclarations)
{-
cdecls :: HParser Declarations
cdecls =
    do
     ds <- withLayout cdecl
     return (CollectFunctionBindings.cdecls ds)
-}
    do
        lexCLASS
        ct <- option [] (try $ do {c <- scontext ; lexDARROW ; return c} )
        st <- simpleType
        ds <- option MaybeDeclarations_Nothing 
                     (try $ do lexWHERE
                               d <-  option MaybeDeclarations_Nothing (try $ do  
                                                                               cds <- cdecls 
                                                                               return (MaybeDeclarations_Just cds))                                                     
                               return d)
        return $ \r -> Declaration_Class r ct st ds
    <|>
-- Declaration_Instance (Range) (ContextItems) (Name) (Types) (MaybeDeclarations)
    do
        lexINSTANCE
        ct <- option [] (try $ do {c <- scontext; lexDARROW ; return c} )
        n  <- tycls
        ts <- iType
        ds <- option MaybeDeclarations_Nothing (try $ do lexWHERE
                                                         d <- idecls
                                                         return (MaybeDeclarations_Just d))
        return $ \r -> Declaration_Instance r ct n [ts] ds
    <|>
    infixdecl
    ) 
    <|> addRange (
      do
         lexHOLE
         jb <- optionMaybe normalRhs
         case jb  of
            Just b ->  return $ \r -> Declaration_PatternBinding r (Pattern_Hole r (-1)) b
            Nothing -> return $ \r -> Declaration_Hole r (-1)
      )
    <|>
    decl
    <?> Texts.parserDeclaration