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
18 | Datatype String [String] [(String, [T.Type var])]
19 | TypeAlias String [String] (T.Type var)
20 | Port String portType
21 | Fixity Assoc Int String
31 Declaration' T.RawType Source.Def Var.Raw
35 Declaration' T.RawType Valid.Def Var.Raw
39 Declaration' (T.PortType Var.Canonical) Canonical.Def Var.Canonical
44instance Binary Assoc where
51 _ -> error "Error reading valid associativity from serialized string"
63assocToString :: Assoc -> String
71instance (Pretty portType, Pretty def, Pretty var, Var.ToString var) =>
72 Pretty (Declaration' portType def var) where
75 Definition def -> pretty def
77 Datatype tipe tvars ctors ->
79 (P.text "type" <+> P.text tipe <+> P.hsep (map P.text tvars))
81 (P.sep $ zipWith (<+>) seperators (map prettyCtor ctors))
84 map P.text ("=" : repeat "|")
86 prettyCtor (name, tipes) =
87 P.hang (P.text name) 2 (P.sep (map T.prettyParens tipes))
89 TypeAlias name tvars tipe ->
91 (P.text "type" <+> P.text "alias" <+> name' <+> P.equals)
96 P.text name <+> P.hsep (map P.text tvars)
99 P.text "port" <+> P.text name <+> P.colon <+> pretty tipe
101 Fixity assoc prec op ->
102 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