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
14data Declaration' port def var
16 | Datatype String [String] [(String, [T.Type var])]
17 | TypeAlias String [String] (T.Type var)
19 | Fixity Assoc Int String
27 = InputAnnotation String T.RawType
28 | OutputAnnotation String T.RawType
29 | OutputDef String Source.Expr
33 = Out String expr (T.Type var)
34 | In String (T.Type var)
38 Declaration' RawPort Source.Def Var.Raw
42 Declaration' (Port Valid.Expr Var.Raw) Valid.Def Var.Raw
46 Declaration' (Port Canonical.Expr Var.Canonical) Canonical.Def Var.Canonical
49portName :: Port expr var -> String
56assocToString :: Assoc -> String
66instance Binary Assoc where
73 _ -> error "Error reading valid associativity from serialized string"
85instance (Pretty port, Pretty def, Pretty var, Var.ToString var) =>
86 Pretty (Declaration' port def var) where
89 Definition def -> pretty def
91 Datatype tipe tvars ctors ->
93 (P.text "type" <+> P.text tipe <+> P.hsep (map P.text tvars))
95 (P.sep $ zipWith (<+>) seperators (map prettyCtor ctors))
98 map P.text ("=" : repeat "|")
100 prettyCtor (name, tipes) =
101 P.hang (P.text name) 2 (P.sep (map T.prettyParens tipes))
103 TypeAlias name tvars tipe ->
105 (P.text "type" <+> P.text "alias" <+> name' <+> P.equals)
110 P.text name <+> P.hsep (map P.text tvars)
112 Port port -> pretty port
114 Fixity assoc prec op ->
115 P.text "infix" <> assoc' <+> P.int prec <+> P.text op
124instance Pretty RawPort where
127 InputAnnotation name tipe ->
128 prettyPort "input" name ":" tipe
130 OutputAnnotation name tipe ->
131 prettyPort "output" name ":" tipe
133 OutputDef name expr ->
134 prettyPort "output" name "=" expr
137instance (Pretty expr, Pretty var, Var.ToString var) => Pretty (Port expr var) where
141 prettyPort "input" name ":" tipe
143 Out name expr tipe ->
145 [ prettyPort "output" name ":" tipe
146 , prettyPort "output" name "=" expr
150prettyPort :: (Pretty a) => String -> String -> String -> a -> Doc
151prettyPort keyword name op e =
152 P.text keyword <+> P.text name <+> P.text op <+> pretty e
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