-- Haskel data types for the abstract syntax. -- Generated by the BNF converter. {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# 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, Int, Maybe(..)) import Data.String data Decl = DDef [DefAttr] Def -- ^ Decl ::= DefAttr Def | DImp Import -- ^ Decl ::= Import deriving (C.Eq, C.Ord, C.Show, C.Read) data Def = Axiom AIdent [Typing] Exp -- ^ Def ::= "postulate" AIdent Typing "::" Exp | Binding AIdent Exp -- ^ Def ::= AIdent "=" Exp | Commt Comment -- ^ Def ::= Comment | Data AIdent [Typing] [Constructor] -- ^ Def ::= "data" AIdent Typing "=" Constructor | Mutual [Def] -- ^ Def ::= "mutual" "{" Def "}" | Open Exp [OpenArg] -- ^ Def ::= "open" Exp "use" OpenArg | Package AIdent [Typing] PackageBody -- ^ Def ::= "package" AIdent Typing "where" PackageBody | Type AIdent [Typing] Exp -- ^ Def ::= "type" AIdent Typing "=" Exp | Value AIdent [VarDecl] Exp Exp -- ^ Def ::= AIdent VarDecl "::" Exp "=" Exp deriving (C.Eq, C.Ord, C.Show, C.Read) data Exp = EAbs VarDecl Arrow Exp -- ^ Exp ::= "\\" VarDecl Arrow Exp | EAbsUnt [AIdent] Arrow Exp -- ^ Exp ::= "\\" AIdent Arrow Exp | EApp Exp Exp -- ^ Exp ::= Exp1 Exp2 | ECase Exp [Branch] -- ^ Exp ::= "case" Exp "of" "{" Branch "}" | EChar T.Char -- ^ Exp ::= Char | ECommL Comment Exp -- ^ Exp ::= Comment Exp1 | ECommR Exp Comment -- ^ Exp ::= Exp1 Comment | ECon AIdent -- ^ Exp ::= AIdent "@_" | EConst AIdent -- ^ Exp ::= AIdent | EDouble T.Double -- ^ Exp ::= Double | EFun Exp Arrow Exp -- ^ Exp ::= Exp1 Arrow Exp | EIData [VarDecl] [IndConstructor] -- ^ Exp ::= "idata" VarDecl IndConstructor | EInfix Exp Infix Exp -- ^ Exp ::= Exp1 Infix Exp1 | EInt T.Integer -- ^ Exp ::= Integer | ELet [Decl] Exp -- ^ Exp ::= "let" "{" Decl "}" "in" Exp | EMeta -- ^ Exp ::= "?" | EMetaN T.Integer -- ^ Exp ::= "?" Integer | EMetaU -- ^ Exp ::= "_" | EOpen Exp [OpenArg] Exp -- ^ Exp ::= "open" Exp "use" OpenArg "in" Exp | EPi VarDecl Arrow Exp -- ^ Exp ::= VarDecl Arrow Exp | EProj Exp AIdent -- ^ Exp ::= Exp3 "." AIdent | ESet -- ^ Exp ::= "Set" | ESig [FieldDecl] -- ^ Exp ::= "sig" "{" FieldDecl "}" | EStar T.Integer -- ^ Exp ::= "#" Integer | EStr [Binding] -- ^ Exp ::= "struct" "{" Binding "}" | EString T.String -- ^ Exp ::= String | ESum [Constructor] -- ^ Exp ::= "data" Constructor | EType -- ^ Exp ::= "Type" | EVar AIdent -- ^ Exp ::= AIdent deriving (C.Eq, C.Ord, C.Show, C.Read) data Arrow = AHide -- ^ Arrow ::= "|->" | AShow -- ^ Arrow ::= "->" deriving (C.Eq, C.Ord, C.Show, C.Read) data Typing = TDecl VarDecl -- ^ Typing ::= VarDecl | TExp Exp -- ^ Typing ::= Exp2 deriving (C.Eq, C.Ord, C.Show, C.Read) data VarDecl = VDecl [Bound] Exp -- ^ VarDecl ::= "(" Bound "::" Exp ")" deriving (C.Eq, C.Ord, C.Show, C.Read) data Bound = BHide AIdent -- ^ Bound ::= "|" AIdent | BVar AIdent -- ^ Bound ::= AIdent deriving (C.Eq, C.Ord, C.Show, C.Read) data FieldDecl = FDecl AIdent Exp -- ^ FieldDecl ::= AIdent "::" Exp deriving (C.Eq, C.Ord, C.Show, C.Read) data Branch = BranchCon AIdent [AIdent] Exp -- ^ Branch ::= "(" AIdent AIdent ")" "->" Exp | BranchInf AIdent Infix AIdent Exp -- ^ Branch ::= "(" AIdent Infix AIdent ")" "->" Exp | BranchVar AIdent Exp -- ^ Branch ::= AIdent "->" Exp deriving (C.Eq, C.Ord, C.Show, C.Read) data Constructor = Cnstr AIdent [Typing] -- ^ Constructor ::= AIdent Typing deriving (C.Eq, C.Ord, C.Show, C.Read) data IndConstructor = ICnstr AIdent [Typing] [Exp] -- ^ IndConstructor ::= AIdent Typing "::" "_" Exp2 deriving (C.Eq, C.Ord, C.Show, C.Read) data Binding = Bind AIdent Exp -- ^ Binding ::= AIdent "=" Exp deriving (C.Eq, C.Ord, C.Show, C.Read) data PackageBody = PackageDef [Decl] -- ^ PackageBody ::= "{" Decl "}" | PackageInst Exp -- ^ PackageBody ::= Exp deriving (C.Eq, C.Ord, C.Show, C.Read) data OpenArg = OArg [DefAttr] AIdent -- ^ OpenArg ::= DefAttr AIdent | OArgD [DefAttr] AIdent Exp -- ^ OpenArg ::= DefAttr AIdent "=" Exp | OArgT [DefAttr] AIdent Exp -- ^ OpenArg ::= DefAttr AIdent "::" Exp | OArgTD [DefAttr] AIdent Exp Exp -- ^ OpenArg ::= DefAttr AIdent "::" Exp "=" Exp deriving (C.Eq, C.Ord, C.Show, C.Read) data DefAttr = Abstract -- ^ DefAttr ::= "abstract" | Concrete -- ^ DefAttr ::= "concrete" | Private -- ^ DefAttr ::= "private" | Public -- ^ DefAttr ::= "public" deriving (C.Eq, C.Ord, C.Show, C.Read) data Import = Import T.String -- ^ Import ::= "import" String ";" deriving (C.Eq, C.Ord, C.Show, C.Read) data AIdent = F PIdent -- ^ AIdent ::= PIdent | I Infix -- ^ AIdent ::= "(" Infix ")" deriving (C.Eq, C.Ord, C.Show, C.Read) 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 PIdent where hasPosition (PIdent (p, _)) = C.Just p