1module SourceSyntax.Declaration where
4import qualified SourceSyntax.Expression as Expr
5import SourceSyntax.Type
6import SourceSyntax.PrettyPrint
7import Text.PrettyPrint as P
9data Declaration tipe var
10 = Definition (Expr.Def tipe var)
11 | Datatype String [String] [(String,[Type])] [Derivation]
12 | TypeAlias String [String] Type [Derivation]
13 | Port String Type (Maybe (Expr.LExpr tipe var))
14 | Fixity Assoc Int String
20data Derivation = Json | Binary | RecordConstructor
23instance Binary Derivation where
24 get = do n <- getWord8
28 2 -> RecordConstructor
34 RecordConstructor -> putWord8 2
36instance Show Assoc where
43instance Pretty (Declaration t v) where
46 Definition def -> pretty def
48 Datatype tipe tvars ctors deriveables ->
49 P.hang (P.text "data" <+> P.text tipe <+> P.hsep (map P.text tvars)) 4
50 (P.sep $ zipWith join ("=" : repeat "|") ctors) <+> prettyDeriving deriveables
52 join c ctor = P.text c <+> prettyCtor ctor
53 prettyCtor (name, tipes) =
54 P.hang (P.text name) 2 (P.sep (map prettyParens tipes))
56 TypeAlias name tvars tipe deriveables ->
57 alias <+> prettyDeriving deriveables
59 name' = P.text name <+> P.hsep (map P.text tvars)
60 alias = P.hang (P.text "type" <+> name' <+> P.equals) 4 (pretty tipe)
62 Port name tipe maybeExpr ->
63 let port = P.text "port" <+> P.text name in
64 P.vcat [ port <+> P.colon <+> pretty tipe
65 , maybe P.empty (\expr -> port <+> P.equals <+> pretty expr) maybeExpr
68 Fixity assoc prec op -> P.text "infix" <> assoc' <+> P.int prec <+> P.text op
70 assoc' = case assoc of
75prettyDeriving :: [Derivation] -> Doc
76prettyDeriving deriveables =
79 [d] -> P.text "deriving" <+> P.text (show d)
80 ds -> P.text "deriving" <+>
81 P.parens (P.hsep $ P.punctuate P.comma $ map (P.text . show) ds)
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