-- 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 Core. module AbsCore 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 Module = Module' BNFC'Position data Module' a = Module a Ident [Tdef' a] [Vdefg' a] -- ^ Module ::= "%module" Ident Tdef Vdefg deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Tdef = Tdef' BNFC'Position data Tdef' a = Data a (QualIdent' a) [Tbind' a] [Cdef' a] -- ^ Tdef ::= "%data" QualIdent Tbind "=" "{" Cdef "}" | Newtype a (QualIdent' a) [Tbind' a] (MaybeTy' a) -- ^ Tdef ::= "%newtype" QualIdent Tbind MaybeTy deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type MaybeTy = MaybeTy' BNFC'Position data MaybeTy' a = JustTy a (Ty' a) -- ^ MaybeTy ::= "=" Ty | NoTy a -- ^ MaybeTy ::= deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Cdef = Cdef' BNFC'Position data Cdef' a = Constr a (QualIdent' a) [ATbind' a] [Tyt' a] -- ^ Cdef ::= QualIdent ATbind Tyt deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Tyt = Tyt' BNFC'Position data Tyt' a = TT a (Ty' a) -- ^ Tyt ::= Ty2 deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Vdefg = Vdefg' BNFC'Position data Vdefg' a = Nonrec a (Vdef' a) -- ^ Vdefg ::= Vdef | Rec a [Vdef' a] -- ^ Vdefg ::= "%rec" "{" Vdef "}" deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Vdef = Vdef' BNFC'Position data Vdef' a = VdefQ a (QualIdent' a) (Ty' a) (Exp' a) -- ^ Vdef ::= QualIdent "::" Ty "=" Exp | VdefU a Ident (Ty' a) (Exp' a) -- ^ Vdef ::= Ident "::" Ty "=" Exp deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Exp = Exp' BNFC'Position data Exp' a = App a (Exp' a) (Exp' a) -- ^ Exp ::= Exp1 Exp2 | Appt a (Exp' a) (Ty' a) -- ^ Exp ::= Exp1 "@" Ty2 | Case a (Exp' a) (Vbind' a) [Alt' a] -- ^ Exp ::= "%case" Exp2 "%of" Vbind "{" Alt "}" | Coerce a (Ty' a) (Exp' a) -- ^ Exp ::= "%coerce" Ty2 Exp | Dcon a (QualIdent' a) -- ^ Exp ::= QualIdent | External a T.String (Ty' a) -- ^ Exp ::= "%external" String Ty | Lams a [Bind' a] (Exp' a) -- ^ Exp ::= "\\" Bind "->" Exp | Let a (Vdefg' a) (Exp' a) -- ^ Exp ::= "%let" Vdefg "%in" Exp | Litc a (Lit' a) -- ^ Exp ::= Lit | Note a T.String (Exp' a) -- ^ Exp ::= "%note" String Exp | Var a Ident -- ^ Exp ::= Ident deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Bind = Bind' BNFC'Position data Bind' a = Tb a (Tbind' a) -- ^ Bind ::= "@" Tbind | Vb a (Vbind' a) -- ^ Bind ::= Vbind deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Alt = Alt' BNFC'Position data Alt' a = Acon a (QualIdent' a) [ATbind' a] [Vbind' a] (Exp' a) -- ^ Alt ::= QualIdent ATbind Vbind "->" Exp | Adefault a (Exp' a) -- ^ Alt ::= "%_" "->" Exp | Alit a (Lit' a) (Exp' a) -- ^ Alt ::= Lit "->" Exp deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Vbind = Vbind' BNFC'Position data Vbind' a = Vbind a Ident (Ty' a) -- ^ Vbind ::= "(" Ident "::" Ty ")" deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Tbind = Tbind' BNFC'Position data Tbind' a = TbindLift a Ident -- ^ Tbind ::= Ident | TbindPair a Ident (Kind' a) -- ^ Tbind ::= "(" Ident "::" Kind1 ")" deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type ATbind = ATbind' BNFC'Position data ATbind' a = ATbind a (Tbind' a) -- ^ ATbind ::= "@" Tbind deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Ty = Ty' BNFC'Position data Ty' a = TArrow a (Ty' a) (Ty' a) -- ^ Ty ::= Ty1 "->" Ty | Tapp a (Ty' a) (Ty' a) -- ^ Ty ::= Ty1 Ty2 | Tcon a (QualIdent' a) -- ^ Ty ::= QualIdent | Tforalls a [Tbind' a] (Ty' a) -- ^ Ty ::= "%forall" Tbind "." Ty | Tvar a Ident -- ^ Ty ::= Ident deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Kind = Kind' BNFC'Position data Kind' a = Karrow a (Kind' a) (Kind' a) -- ^ Kind ::= Kind1 "->" Kind | Klifted a -- ^ Kind ::= "*" | Kopen a -- ^ Kind ::= "?" | Kunlifted a -- ^ Kind ::= "#" deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type Lit = Lit' BNFC'Position data Lit' a = Lchar a T.Char (Ty' a) -- ^ Lit ::= "(" Char "::" Ty2 ")" | Lint a T.Integer (Ty' a) -- ^ Lit ::= "(" Integer "::" Ty2 ")" | Lrational a T.Double (Ty' a) -- ^ Lit ::= "(" Double "::" Ty2 ")" | Lstring a T.String (Ty' a) -- ^ Lit ::= "(" String "::" Ty2 ")" deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) type QualIdent = QualIdent' BNFC'Position data QualIdent' a = Qual a Ident Ident -- ^ QualIdent ::= Ident "." Ident deriving (C.Eq, C.Ord, C.Show, C.Read, C.Functor, C.Foldable, C.Traversable) newtype Ident = Ident T.String deriving (C.Eq, C.Ord, C.Show, C.Read, Data.String.IsString) -- | 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 Module where hasPosition = \case Module p _ _ _ -> p instance HasPosition Tdef where hasPosition = \case Data p _ _ _ -> p Newtype p _ _ _ -> p instance HasPosition MaybeTy where hasPosition = \case JustTy p _ -> p NoTy p -> p instance HasPosition Cdef where hasPosition = \case Constr p _ _ _ -> p instance HasPosition Tyt where hasPosition = \case TT p _ -> p instance HasPosition Vdefg where hasPosition = \case Nonrec p _ -> p Rec p _ -> p instance HasPosition Vdef where hasPosition = \case VdefQ p _ _ _ -> p VdefU p _ _ _ -> p instance HasPosition Exp where hasPosition = \case App p _ _ -> p Appt p _ _ -> p Case p _ _ _ -> p Coerce p _ _ -> p Dcon p _ -> p External p _ _ -> p Lams p _ _ -> p Let p _ _ -> p Litc p _ -> p Note p _ _ -> p Var p _ -> p instance HasPosition Bind where hasPosition = \case Tb p _ -> p Vb p _ -> p instance HasPosition Alt where hasPosition = \case Acon p _ _ _ _ -> p Adefault p _ -> p Alit p _ _ -> p instance HasPosition Vbind where hasPosition = \case Vbind p _ _ -> p instance HasPosition Tbind where hasPosition = \case TbindLift p _ -> p TbindPair p _ _ -> p instance HasPosition ATbind where hasPosition = \case ATbind p _ -> p instance HasPosition Ty where hasPosition = \case TArrow p _ _ -> p Tapp p _ _ -> p Tcon p _ -> p Tforalls p _ _ -> p Tvar p _ -> p instance HasPosition Kind where hasPosition = \case Karrow p _ _ -> p Klifted p -> p Kopen p -> p Kunlifted p -> p instance HasPosition Lit where hasPosition = \case Lchar p _ _ -> p Lint p _ _ -> p Lrational p _ _ -> p Lstring p _ _ -> p instance HasPosition QualIdent where hasPosition = \case Qual p _ _ -> p