1{-# OPTIONS_GHC -Wall #-}
2module SourceSyntax.Declaration where
5import qualified SourceSyntax.Expression as Expr
6import qualified SourceSyntax.Type as T
7import SourceSyntax.PrettyPrint
8import Text.PrettyPrint as P
10data Declaration' port def
12 | Datatype String [String] [(String,[T.Type])]
13 | TypeAlias String [String] T.Type
15 | Fixity Assoc Int String
22 = PPAnnotation String T.Type
23 | PPDef String Expr.ParseExpr
27 = Out String Expr.Expr T.Type
31portName :: Port -> String
37type ParseDeclaration = Declaration' ParsePort Expr.ParseDef
38type Declaration = Declaration' Port Expr.Def
40instance Show Assoc where
47instance Binary Assoc where
48 get = do n <- getWord8
53 _ -> error "Error reading valid associativity from serialized string"
55 put assoc = putWord8 $ case assoc of { L -> 0 ; N -> 1 ; R -> 2 }
57instance (Pretty port, Pretty def) => Pretty (Declaration' port def) where
60 Definition def -> pretty def
62 Datatype tipe tvars ctors ->
63 P.hang (P.text "data" <+> P.text tipe <+> P.hsep (map P.text tvars)) 4
64 (P.sep $ zipWith join ("=" : repeat "|") ctors)
66 join c ctor = P.text c <+> prettyCtor ctor
67 prettyCtor (name, tipes) =
68 P.hang (P.text name) 2 (P.sep (map T.prettyParens tipes))
70 TypeAlias name tvars tipe ->
71 P.hang (P.text "type" <+> name' <+> P.equals) 4 (pretty tipe)
73 name' = P.text name <+> P.hsep (map P.text tvars)
75 Port port -> pretty port
77 Fixity assoc prec op -> P.text "infix" <> assoc' <+> P.int prec <+> P.text op
79 assoc' = case assoc of
84instance Pretty ParsePort where
87 PPAnnotation name tipe -> prettyPort name ":" tipe
88 PPDef name expr -> prettyPort name "=" expr
90instance Pretty Port where
93 In name tipe -> prettyPort name ":" tipe
94 Out name expr tipe -> P.vcat [ prettyPort name ":" tipe
95 , prettyPort name "=" expr ]
98prettyPort :: (Pretty a) => String -> String -> a -> Doc
99prettyPort name op e = 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