on bfae985 help sign in
elk/src/AST/Exposing.hs
80 lines 973 B history raw
1{-# OPTIONS_GHC -Wall #-}
2module AST.Exposing
3 ( Canonical(..)
4 , nothing
5 , Raw
6 , Exposing(..)
7 , closed
8 , Entry(..)
9 , getName
10 )
11 where
13import Data.Binary (Binary, get, put)
14import Data.Text (Text)
16import qualified Reporting.Annotation as A
20-- CANONICAL
23data Canonical =
24 Canonical
25 { _values :: ![Text]
26 , _aliases :: ![Text]
27 , _unions :: ![(Text, [Text])]
28 }
31nothing :: Canonical
32nothing =
33 Canonical [] [] []
37-- RAW
40type Raw = Exposing Entry
43data Exposing a
44 = Open
45 | Explicit ![A.Located a]
48closed :: Exposing a
49closed =
50 Explicit []
53data Entry
54 = Lower !Text
55 | Upper !Text (Maybe (Exposing Text))
58getName :: Entry -> Text
59getName entry =
60 case entry of
61 Lower name ->
62 name
64 Upper name _ ->
65 name
69-- BINARY
72instance Binary Canonical where
73 get =
74 Canonical <$> get <*> get <*> get
76 put (Canonical values aliases unions) =
77 do put values
78 put aliases
79 put unions