-- Haskel data types for the abstract syntax. -- Generated by the BNF converter. {-# LANGUAGE DeriveTraversable #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE PatternSynonyms #-} -- | The abstract syntax of language Alfa. module AbsAlfa where import qualified Prelude as T (Char, Double, Integer, String) import qualified Prelude as C ( Eq , Ord , Show , Read , Functor , Foldable , Traversable , Int, Maybe(..) ) import Data.String type Decl = Decl' BNFC'Position data Decl' a = DDef a [DefAttr' a] (Def' a) -- ^ Decl ::= DefAttr Def | DImp a (Import' a) -- ^ Decl ::= Import deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Def = Def' BNFC'Position data Def' a = Axiom a (AIdent' a) [Typing' a] (Exp' a) -- ^ Def ::= "postulate" AIdent Typing "::" Exp | Binding a (AIdent' a) (Exp' a) -- ^ Def ::= AIdent "=" Exp | Commt a Comment -- ^ Def ::= Comment | Data a (AIdent' a) [Typing' a] [Constructor' a] -- ^ Def ::= "data" AIdent Typing "=" Constructor | Mutual a [Def' a] -- ^ Def ::= "mutual" "{" Def "}" | Open a (Exp' a) [OpenArg' a] -- ^ Def ::= "open" Exp "use" OpenArg | Package a (AIdent' a) [Typing' a] (PackageBody' a) -- ^ Def ::= "package" AIdent Typing "where" PackageBody | Type a (AIdent' a) [Typing' a] (Exp' a) -- ^ Def ::= "type" AIdent Typing "=" Exp | Value a (AIdent' a) [VarDecl' a] (Exp' a) (Exp' a) -- ^ Def ::= AIdent VarDecl "::" Exp "=" Exp deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Exp = Exp' BNFC'Position data Exp' a = EAbs a (VarDecl' a) (Arrow' a) (Exp' a) -- ^ Exp ::= "\\" VarDecl Arrow Exp | EAbsUnt a [AIdent' a] (Arrow' a) (Exp' a) -- ^ Exp ::= "\\" AIdent Arrow Exp | EApp a (Exp' a) (Exp' a) -- ^ Exp ::= Exp1 Exp2 | ECase a (Exp' a) [Branch' a] -- ^ Exp ::= "case" Exp "of" "{" Branch "}" | EChar a T.Char -- ^ Exp ::= Char | ECommL a Comment (Exp' a) -- ^ Exp ::= Comment Exp1 | ECommR a (Exp' a) Comment -- ^ Exp ::= Exp1 Comment | ECon a (AIdent' a) -- ^ Exp ::= AIdent "@_" | EConst a (AIdent' a) -- ^ Exp ::= AIdent | EDouble a T.Double -- ^ Exp ::= Double | EFun a (Exp' a) (Arrow' a) (Exp' a) -- ^ Exp ::= Exp1 Arrow Exp | EIData a [VarDecl' a] [IndConstructor' a] -- ^ Exp ::= "idata" VarDecl IndConstructor | EInfix a (Exp' a) Infix (Exp' a) -- ^ Exp ::= Exp1 Infix Exp1 | EInt a T.Integer -- ^ Exp ::= Integer | ELet a [Decl' a] (Exp' a) -- ^ Exp ::= "let" "{" Decl "}" "in" Exp | EMeta a -- ^ Exp ::= "?" | EMetaN a T.Integer -- ^ Exp ::= "?" Integer | EMetaU a -- ^ Exp ::= "_" | EOpen a (Exp' a) [OpenArg' a] (Exp' a) -- ^ Exp ::= "open" Exp "use" OpenArg "in" Exp | EPi a (VarDecl' a) (Arrow' a) (Exp' a) -- ^ Exp ::= VarDecl Arrow Exp | EProj a (Exp' a) (AIdent' a) -- ^ Exp ::= Exp3 "." AIdent | ESet a -- ^ Exp ::= "Set" | ESig a [FieldDecl' a] -- ^ Exp ::= "sig" "{" FieldDecl "}" | EStar a T.Integer -- ^ Exp ::= "#" Integer | EStr a [Binding' a] -- ^ Exp ::= "struct" "{" Binding "}" | EString a T.String -- ^ Exp ::= String | ESum a [Constructor' a] -- ^ Exp ::= "data" Constructor | EType a -- ^ Exp ::= "Type" | EVar a (AIdent' a) -- ^ Exp ::= AIdent deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Arrow = Arrow' BNFC'Position data Arrow' a = AHide a -- ^ Arrow ::= "|->" | AShow a -- ^ Arrow ::= "->" deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Typing = Typing' BNFC'Position data Typing' a = TDecl a (VarDecl' a) -- ^ Typing ::= VarDecl | TExp a (Exp' a) -- ^ Typing ::= Exp2 deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type VarDecl = VarDecl' BNFC'Position data VarDecl' a = VDecl a [Bound' a] (Exp' a) -- ^ VarDecl ::= "(" Bound "::" Exp ")" deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Bound = Bound' BNFC'Position data Bound' a = BHide a (AIdent' a) -- ^ Bound ::= "|" AIdent | BVar a (AIdent' a) -- ^ Bound ::= AIdent deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type FieldDecl = FieldDecl' BNFC'Position data FieldDecl' a = FDecl a (AIdent' a) (Exp' a) -- ^ FieldDecl ::= AIdent "::" Exp deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Branch = Branch' BNFC'Position data Branch' a = BranchCon a (AIdent' a) [AIdent' a] (Exp' a) -- ^ Branch ::= "(" AIdent AIdent ")" "->" Exp | BranchInf a (AIdent' a) Infix (AIdent' a) (Exp' a) -- ^ Branch ::= "(" AIdent Infix AIdent ")" "->" Exp | BranchVar a (AIdent' a) (Exp' a) -- ^ Branch ::= AIdent "->" Exp deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Constructor = Constructor' BNFC'Position data Constructor' a = Cnstr a (AIdent' a) [Typing' a] -- ^ Constructor ::= AIdent Typing deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type IndConstructor = IndConstructor' BNFC'Position data IndConstructor' a = ICnstr a (AIdent' a) [Typing' a] [Exp' a] -- ^ IndConstructor ::= AIdent Typing "::" "_" Exp2 deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Binding = Binding' BNFC'Position data Binding' a = Bind a (AIdent' a) (Exp' a) -- ^ Binding ::= AIdent "=" Exp deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type PackageBody = PackageBody' BNFC'Position data PackageBody' a = PackageDef a [Decl' a] -- ^ PackageBody ::= "{" Decl "}" | PackageInst a (Exp' a) -- ^ PackageBody ::= Exp deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type OpenArg = OpenArg' BNFC'Position data OpenArg' a = OArg a [DefAttr' a] (AIdent' a) -- ^ OpenArg ::= DefAttr AIdent | OArgD a [DefAttr' a] (AIdent' a) (Exp' a) -- ^ OpenArg ::= DefAttr AIdent "=" Exp | OArgT a [DefAttr' a] (AIdent' a) (Exp' a) -- ^ OpenArg ::= DefAttr AIdent "::" Exp | OArgTD a [DefAttr' a] (AIdent' a) (Exp' a) (Exp' a) -- ^ OpenArg ::= DefAttr AIdent "::" Exp "=" Exp deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type DefAttr = DefAttr' BNFC'Position data DefAttr' a = Abstract a -- ^ DefAttr ::= "abstract" | Concrete a -- ^ DefAttr ::= "concrete" | Private a -- ^ DefAttr ::= "private" | Public a -- ^ DefAttr ::= "public" deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Import = Import' BNFC'Position data Import' a = Import a T.String -- ^ Import ::= "import" String ";" deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type AIdent = AIdent' BNFC'Position data AIdent' a = F a PIdent -- ^ AIdent ::= PIdent | I a Infix -- ^ AIdent ::= "(" Infix ")" deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) newtype Comment = Comment T.String deriving (C.Eq, C.Ord, C.Show, C.Read, Data.String.IsString) newtype Infix = Infix T.String deriving (C.Eq, C.Ord, C.Show, C.Read, Data.String.IsString) newtype PIdent = PIdent ((C.Int, C.Int), T.String) deriving (C.Eq, C.Ord, C.Show, C.Read) -- | Start position (line, column) of something. type BNFC'Position = C.Maybe (C.Int, C.Int) pattern BNFC'NoPosition :: BNFC'Position pattern BNFC'NoPosition = C.Nothing pattern BNFC'Position :: C.Int -> C.Int -> BNFC'Position pattern BNFC'Position line col = C.Just (line, col) -- | Get the start position of something. class HasPosition a where hasPosition :: a -> BNFC'Position instance HasPosition Decl where hasPosition = \case DDef p _ _ -> p DImp p _ -> p instance HasPosition Def where hasPosition = \case Axiom p _ _ _ -> p Binding p _ _ -> p Commt p _ -> p Data p _ _ _ -> p Mutual p _ -> p Open p _ _ -> p Package p _ _ _ -> p Type p _ _ _ -> p Value p _ _ _ _ -> p instance HasPosition Exp where hasPosition = \case EAbs p _ _ _ -> p EAbsUnt p _ _ _ -> p EApp p _ _ -> p ECase p _ _ -> p EChar p _ -> p ECommL p _ _ -> p ECommR p _ _ -> p ECon p _ -> p EConst p _ -> p EDouble p _ -> p EFun p _ _ _ -> p EIData p _ _ -> p EInfix p _ _ _ -> p EInt p _ -> p ELet p _ _ -> p EMeta p -> p EMetaN p _ -> p EMetaU p -> p EOpen p _ _ _ -> p EPi p _ _ _ -> p EProj p _ _ -> p ESet p -> p ESig p _ -> p EStar p _ -> p EStr p _ -> p EString p _ -> p ESum p _ -> p EType p -> p EVar p _ -> p instance HasPosition Arrow where hasPosition = \case AHide p -> p AShow p -> p instance HasPosition Typing where hasPosition = \case TDecl p _ -> p TExp p _ -> p instance HasPosition VarDecl where hasPosition = \case VDecl p _ _ -> p instance HasPosition Bound where hasPosition = \case BHide p _ -> p BVar p _ -> p instance HasPosition FieldDecl where hasPosition = \case FDecl p _ _ -> p instance HasPosition Branch where hasPosition = \case BranchCon p _ _ _ -> p BranchInf p _ _ _ _ -> p BranchVar p _ _ -> p instance HasPosition Constructor where hasPosition = \case Cnstr p _ _ -> p instance HasPosition IndConstructor where hasPosition = \case ICnstr p _ _ _ -> p instance HasPosition Binding where hasPosition = \case Bind p _ _ -> p instance HasPosition PackageBody where hasPosition = \case PackageDef p _ -> p PackageInst p _ -> p instance HasPosition OpenArg where hasPosition = \case OArg p _ _ -> p OArgD p _ _ _ -> p OArgT p _ _ _ -> p OArgTD p _ _ _ _ -> p instance HasPosition DefAttr where hasPosition = \case Abstract p -> p Concrete p -> p Private p -> p Public p -> p instance HasPosition Import where hasPosition = \case Import p _ -> p instance HasPosition AIdent where hasPosition = \case F p _ -> p I p _ -> p instance HasPosition PIdent where hasPosition (PIdent (p, _)) = C.Just p