From f72bf16e2edc8d654e661cd59f820409219e5f27 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 25 Feb 2024 21:01:13 +0100 Subject: Add HSVIS module prefix --- src/HSVIS/AST.hs | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/HSVIS/AST.hs (limited to 'src/HSVIS/AST.hs') diff --git a/src/HSVIS/AST.hs b/src/HSVIS/AST.hs new file mode 100644 index 0000000..5a90205 --- /dev/null +++ b/src/HSVIS/AST.hs @@ -0,0 +1,68 @@ +module HSVIS.AST where + +import Data.List.NonEmpty (NonEmpty) + +import HSVIS.Pretty + + +newtype Name = Name String + deriving (Show, Eq) + +data Program t = Program [DataDef] [FunDef t] + deriving (Show) + +data DataDef = DataDef Name [Name] [(Name, [Type])] + deriving (Show) + +data FunDef t = FunDef Name (Maybe Type) (NonEmpty (FunEq t)) + deriving (Show) + +data FunEq t = FunEq Name [Pattern t] (RHS t) + deriving (Show) + +data Type + = TApp Type [Type] + | TTup [Type] + | TList Type + | TFun Type Type + | TCon Name + | TVar Name + deriving (Show) + +data Pattern t + = PWildcard t + | PVar t Name + | PAs t Name (Pattern t) + | PCon t Name [Pattern t] + | POp t (Pattern t) Operator (Pattern t) + | PList t [Pattern t] + | PTup t [Pattern t] + deriving (Show) + +data RHS t + = Guarded [(Expr t, Expr t)] -- currently not parsed + | Plain (Expr t) + deriving (Show) + +data Expr t + = ELit t Literal + | EVar t Name + | ECon t Name + | EList t [Expr t] + | ETup t [Expr t] + | EApp t (Expr t) [Expr t] + | EOp t (Expr t) Operator (Expr t) + | EIf t (Expr t) (Expr t) (Expr t) + | ECase t (Expr t) [(Pattern t, RHS t)] + | ELet t [FunDef t] (Expr t) + deriving (Show) + +data Literal = LInt Integer | LFloat Rational | LChar Char | LString String + deriving (Show) + +data Operator = OAdd | OSub | OMul | ODiv | OMod | OEqu | OPow + | OCons + deriving (Show) + +instance Pretty Name where + prettysPrec _ (Name n) = showString ("\"" ++ n ++ "\"") -- cgit v1.2.3-70-g09d2