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
15data Declaration' port def var
17 | Datatype String [String] [(String, [T.Type var])]
18 | TypeAlias String [String] (T.Type var)
20 | Fixity Assoc Int String
28 = PPAnnotation String T.RawType
29 | PPDef String Source.Expr
33 = Out String expr (T.Type var)
34 | In String (T.Type var)
37type SourceDecl = Declaration' RawPort Source.Def Var.Raw
38type ValidDecl = Declaration' (Port Valid.Expr Var.Raw) Valid.Def Var.Raw
39type CanonicalDecl = Declaration' (Port Canonical.Expr Var.Canonical)
44portName :: Port expr var -> String
51assocToString :: Assoc -> String
61instance Binary Assoc where
68 _ -> error "Error reading valid associativity from serialized string"
80instance (Pretty port, Pretty def, Pretty var, Var.ToString var) =>
81 Pretty (Declaration' port def var) where
84 Definition def -> pretty def
86 Datatype tipe tvars ctors ->
88 (P.text "type" <+> P.text tipe <+> P.hsep (map P.text tvars))
90 (P.sep $ zipWith (<+>) seperators (map prettyCtor ctors))
93 map P.text ("=" : repeat "|")
95 prettyCtor (name, tipes) =
96 P.hang (P.text name) 2 (P.sep (map T.prettyParens tipes))
98 TypeAlias name tvars tipe ->
100 (P.text "type" <+> P.text "alias" <+> name' <+> P.equals)
105 P.text name <+> P.hsep (map P.text tvars)
107 Port port -> pretty port
109 Fixity assoc prec op ->
110 P.text "infix" <> assoc' <+> P.int prec <+> P.text op
119instance Pretty RawPort where
122 PPAnnotation name tipe ->
123 prettyPort name ":" tipe
126 prettyPort name "=" expr
129instance (Pretty expr, Pretty var, Var.ToString var) => Pretty (Port expr var) where
133 prettyPort name ":" tipe
135 Out name expr tipe ->
137 [ prettyPort name ":" tipe
138 , prettyPort name "=" expr
142prettyPort :: (Pretty a) => String -> String -> a -> Doc
143prettyPort name op e =
144 P.text "port" <+> 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