You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

146 lines
3.6 KiB

{-|
Module: Parser.Types
Description: Contains type, class and instance definitions for lexer
Contains type, class and instance definitions for lexer
-}
module Parser.Types where
import Types
-- | Type Signature top level
data TYSG
= TyAll PN [Identifier] TYSG1 -- ^ Forall
| TySG1 TYSG1 -- ^ No forall
deriving Show
instance Positioned TYSG where
pos (TyAll p _ _) = p
pos (TySG1 t) = pos t
-- | Type Signature contents
data TYSG1
= TyVar PN Identifier -- ^ Type variable
| TyImp PN TYSG1 -- ^ Implicit argument
| TyArr PN TYSG1 TYSG1 -- ^ Function arrow
| TyApp PN Identifier [TYSG1] -- ^ Function application in type signature
| TyType PN -- ^ Type type
| TyChar PN -- ^ Char type
| TyString PN -- ^ String type
| TyInt PN -- ^ Int type
| TyNpl PN Int [TYSG1] -- ^ Npl type
deriving Show
instance Positioned TYSG1 where
pos (TyVar p _) = p
pos (TyImp p _) = p
pos (TyArr p _ _) = p
pos (TyApp p _ _) = p
pos (TyType p) = p
pos (TyChar p) = p
pos (TyString p) = p
pos (TyInt p) = p
pos (TyNpl p _ _) = p
-- | Top level parse tree
data TL
= ExDef PN TYSG Identifier [([Pattern], Expr)] -- ^ Definition with args
| DtDef PN Identifier [Identifier] [(TYSG1, Identifier)] -- ^ Data definition
| RcDef PN Identifier [Identifier] [(TYSG1, Identifier)] -- ^ Record definition
deriving Show
instance Positioned TL where
pos (ExDef p _ _ _) = p
pos (DtDef p _ _ _) = p
pos (RcDef p _ _ _) = p
-- | Pattern matching pattern
data Pattern
= PWild PN -- ^ Wild card
| PVar PN Identifier -- ^ Variable (or type constructor of no argument)
| PLit Literal -- ^ Literal
| PApp PN Identifier [Pattern] -- ^ Deconstruction of type constructor
deriving Show
instance Positioned Pattern where
pos (PWild p) = p
pos (PVar p _) = p
pos (PLit l) = pos l
pos (PApp p _ _) = p
-- | A literal value of a builtin type
data Literal
= LInt PN Integer
| LChar PN Char
| LString PN String
deriving Show
instance Positioned Literal where
pos (LInt p _) = p
pos (LChar p _) = p
pos (LString p _) = p
-- | A term, the core / lowest level of value
data Term
= TLit Literal
| TLambda PN [Identifier] Expr
| TLambdaCase PN [(Pattern, Expr)]
| TyLambda PN [(TYSG1, Identifier)] Expr
| TyLambdaCase PN TYSG1 [(Pattern, Expr)]
| TVar PN Identifier
| TNpl PN Int [Arg]
deriving Show
instance Positioned Term where
pos (TVar p _) = p
pos (TNpl p _ _) = p
pos (TLit l) = pos l
pos (TLambda p _ _) = p
pos (TLambdaCase p _) = p
pos (TyLambda p _ _) = p
pos (TyLambdaCase p _ _) = p
-- | Implicit and explicit arguments
data Arg
= Imp Arg1
| Exp Arg1
deriving Show
instance Positioned Arg where
pos (Imp a) = pos a
pos (Exp a) = pos a
-- | The contents of an actual argument
data Arg1
= EArg Expr
| Wild PN
deriving Show
instance Positioned Arg1 where
pos (EArg e) = pos e
pos (Wild p) = p
-- | Body, explicitly or implicitly typed
data Expr
= TExp TYSG Expr1
| EExp Expr1
deriving Show
instance Positioned Expr where
pos (TExp _ e) = pos e
pos (EExp e) = pos e
-- | Body
data Expr1
= Apply PN Expr [Arg]
| ECase PN Expr [(Pattern, Expr)]
| ELet PN [(Identifier, Expr)] Expr
| Inst PN Identifier [(Identifier, Expr)] -- ^ Instance
| Term Term
deriving Show
instance Positioned Expr1 where
pos (Apply p _ _) = p
pos (ECase p _ _) = p
pos (ELet p _ _) = p
pos (Inst p _ _) = p
pos (Term t) = pos t