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' port def var expr
18 | Datatype String [String] [(String, [T.Type var])]
19 | TypeAlias String [String] (T.Type var)
21 | Fixity Assoc Int String
31 Declaration' RawPort Source.Def Var.Raw Source.Expr
35 Declaration' (Port Valid.Expr T.RawType) Valid.Def Var.Raw Valid.Expr
39 Declaration' CanonicalPort Canonical.Def Var.Canonical Canonical.Expr
45 = PortAnnotation String T.RawType
46 | PortDefinition String Source.Expr
51 | Outbound String expr tipe
55 Port Canonical.Expr (T.PortType Var.Canonical)
58getName :: Port expr tipe -> String
61 Inbound name _ -> name
62 Outbound name _ _ -> name
67instance Binary Assoc where
74 _ -> error "Error reading valid associativity from serialized string"
86assocToString :: Assoc -> String
94instance (Pretty port, Pretty def, Pretty var, Var.ToString var, Pretty expr) =>
95 Pretty (Declaration' port def var expr) where
98 Definition def -> pretty def
100 Datatype tipe tvars ctors ->
102 (P.text "type" <+> P.text tipe <+> P.hsep (map P.text tvars))
104 (P.sep $ zipWith (<+>) seperators (map prettyCtor ctors))
107 map P.text ("=" : repeat "|")
109 prettyCtor (name, tipes) =
110 P.hang (P.text name) 2 (P.sep (map T.prettyParens tipes))
112 TypeAlias name tvars tipe ->
114 (P.text "type" <+> P.text "alias" <+> name' <+> P.equals)
119 P.text name <+> P.hsep (map P.text tvars)
124 Fixity assoc prec op ->
125 P.text "infix" <> assoc' <+> P.int prec <+> P.text op
134instance Pretty RawPort where
137 PortAnnotation name tipe ->
138 P.text "port" <+> P.text name <+> P.colon <+> pretty tipe
140 PortDefinition name expr ->
141 P.text "port" <+> P.text name <+> P.equals <+> pretty expr
144instance (Pretty expr, Pretty tipe) => Pretty (Port expr tipe) where
148 P.text "port" <+> P.text name <+> P.colon <+> pretty tipe
150 Outbound name expr tipe ->
152 [ P.text "port" <+> P.text name <+> P.colon <+> pretty tipe
153 , P.hang (P.text "port" <+> P.text name <+> P.equals) 4 (pretty expr)
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