on 455dcb2 help sign in
elk/src/AST/Declaration.hs
101 lines 1.5 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2module AST.Declaration where
4import Data.Binary
6import qualified AST.Expression.Source as Source
7import qualified AST.Expression.Valid as Valid
8import qualified AST.Expression.Canonical as Canonical
9import qualified AST.Type as Type
10import qualified Reporting.Annotation as A
14-- DECLARATIONS
17data Decl def tipe expr
18 = Def def
19 | Union String [String] [(String, [tipe])]
20 | Alias String [String] tipe
21 | Fixity Assoc Int String
25-- INFIX STUFF
28data Assoc = L | N | R
29 deriving (Eq)
32assocToString :: Assoc -> String
33assocToString assoc =
34 case assoc of
35 L ->
36 "left"
38 N ->
39 "non"
41 R ->
42 "right"
46-- COMMENTS
49data CommentOr a
50 = Comment (A.Located String)
51 | Whatever a
55-- DECLARATION PHASES
58type Source =
59 CommentOr (A.Located SourceOrDefine)
62data SourceOrDefine
63 = Source Source'
64 | Define String [CommentOr (A.Located Source.Effect)]
67type Source' =
68 Decl Source.Def Type.Raw Source.Expr
71type Valid =
72 A.Commented Valid'
75type Valid' =
76 Decl Valid.Def Type.Raw Valid.Expr
79type Canonical =
80 A.Commented (Decl Canonical.Def Type.Canonical Canonical.Expr)
84-- BINARY CONVERSION
87instance Binary Assoc where
88 get =
89 do n <- getWord8
90 return $ case n of
91 0 -> L
92 1 -> N
93 2 -> R
94 _ -> error "Error reading valid associativity from serialized string"
96 put assoc =
97 putWord8 $
98 case assoc of
99 L -> 0
100 N -> 1
101 R -> 2