1{-# OPTIONS_GHC -Wall #-}
2module AST.Declaration where
5import qualified AST.Expression.Source as Source
6import qualified AST.Expression.Valid as Valid
7import qualified AST.Expression.Canonical as Canonical
8import qualified AST.Type as T
9import qualified AST.Variable as Var
11import Text.PrettyPrint as P
16data Declaration' portType def var expr
18 | Datatype String [String] [(String, [T.Type var])]
19 | TypeAlias String [String] (T.Type var)
20 | Port String portType
22 | Fixity Assoc Int String
32 Declaration' T.RawType Source.Def Var.Raw Source.Expr
36 Declaration' T.RawType Valid.Def Var.Raw Valid.Expr
40 Declaration' (T.PortType Var.Canonical) Canonical.Def Var.Canonical Canonical.Expr
45instance Binary Assoc where
52 _ -> error "Error reading valid associativity from serialized string"
64assocToString :: Assoc -> String
72instance (Pretty portType, Pretty def, Pretty var, Var.ToString var, Pretty expr) =>
73 Pretty (Declaration' portType def var expr) where
76 Definition def -> pretty def
78 Datatype tipe tvars ctors ->
80 (P.text "type" <+> P.text tipe <+> P.hsep (map P.text tvars))
82 (P.sep $ zipWith (<+>) seperators (map prettyCtor ctors))
85 map P.text ("=" : repeat "|")
87 prettyCtor (name, tipes) =
88 P.hang (P.text name) 2 (P.sep (map T.prettyParens tipes))
90 TypeAlias name tvars tipe ->
92 (P.text "type" <+> P.text "alias" <+> name' <+> P.equals)
97 P.text name <+> P.hsep (map P.text tvars)
100 P.text "port" <+> P.text name <+> P.colon <+> pretty tipe
103 P.text "perform" <+> pretty expr
105 Fixity assoc prec op ->
106 P.text "infix" <> assoc' <+> P.int prec <+> P.text op
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list