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' wire 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 | OutputDefinition String Source.Expr
30 | LoopbackAnnotation String T.RawType
31 | LoopbackDefinition String Source.Expr
35 = Output String expr (T.Type var)
36 | Input String (T.Type var)
37 | Loopback String (Maybe expr) (T.Type var)
41 Declaration' RawWire Source.Def Var.Raw
45 Declaration' (Wire Valid.Expr Var.Raw) Valid.Def Var.Raw
49 Declaration' (Wire Canonical.Expr Var.Canonical) Canonical.Def Var.Canonical
52wireName :: Wire expr var -> String
56 Output name _ _ -> name
57 Loopback name _ _ -> name
60assocToString :: Assoc -> String
70instance Binary Assoc where
77 _ -> error "Error reading valid associativity from serialized string"
89instance (Pretty wire, Pretty def, Pretty var, Var.ToString var) =>
90 Pretty (Declaration' wire def var) where
93 Definition def -> pretty def
95 Datatype tipe tvars ctors ->
97 (P.text "type" <+> P.text tipe <+> P.hsep (map P.text tvars))
99 (P.sep $ zipWith (<+>) seperators (map prettyCtor ctors))
102 map P.text ("=" : repeat "|")
104 prettyCtor (name, tipes) =
105 P.hang (P.text name) 2 (P.sep (map T.prettyParens tipes))
107 TypeAlias name tvars tipe ->
109 (P.text "type" <+> P.text "alias" <+> name' <+> P.equals)
114 P.text name <+> P.hsep (map P.text tvars)
116 Wire wire -> pretty wire
118 Fixity assoc prec op ->
119 P.text "infix" <> assoc' <+> P.int prec <+> P.text op
128instance Pretty RawWire where
131 InputAnnotation name tipe ->
132 prettyWire "input" name ":" tipe
134 OutputAnnotation name tipe ->
135 prettyWire "output" name ":" tipe
137 OutputDefinition name expr ->
138 prettyWire "output" name "=" expr
140 LoopbackAnnotation name tipe ->
141 prettyWire "loopback" name ":" tipe
143 LoopbackDefinition name expr ->
144 prettyWire "loopback" name "=" expr
147instance (Pretty expr, Pretty var, Var.ToString var) => Pretty (Wire expr var) where
151 prettyWire "input" name ":" tipe
153 Output name expr tipe ->
155 [ prettyWire "output" name ":" tipe
156 , prettyWire "output" name "=" expr
159 Loopback name maybeExpr tipe ->
161 [ prettyWire "loopback" name ":" tipe
164 prettyWire "loopback" name "=" expr
170prettyWire :: (Pretty a) => String -> String -> String -> a -> Doc
171prettyWire keyword name op e =
172 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