on df41ae8 help sign in
elk/src/AST/Declaration.hs
96 lines 1.4 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-- DECLARATION PHASES
28type Source =
29 CommentOr (A.Located Source')
32type Source' =
33 Decl Source.Def Type.Raw Source.Expr
36type Valid =
37 A.Commented Valid'
40type Valid' =
41 Decl Valid.Def Type.Raw Valid.Expr
44type Canonical =
45 A.Commented (Decl Canonical.Def Type.Canonical Canonical.Expr)
49-- COMMENTS
52data CommentOr a
53 = Comment (A.Located String)
54 | Whatever a
58-- INFIX STUFF
61data Assoc = L | N | R
62 deriving (Eq)
65assocToString :: Assoc -> String
66assocToString assoc =
67 case assoc of
68 L ->
69 "left"
71 N ->
72 "non"
74 R ->
75 "right"
79-- BINARY CONVERSION
82instance Binary Assoc where
83 get =
84 do n <- getWord8
85 return $ case n of
86 0 -> L
87 1 -> N
88 2 -> R
89 _ -> error "Error reading valid associativity from serialized string"
91 put assoc =
92 putWord8 $
93 case assoc of
94 L -> 0
95 N -> 1
96 R -> 2