never executed always true always false
1 {-# LANGUAGE TypeSynonymInstances #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE TypeFamilies #-}
4 {-# LANGUAGE StandaloneDeriving #-}
5 {-# LANGUAGE DataKinds #-}
6
7 module AST.Module
8 ( Module(..), Header(..), SourceTag(..), SourceSettings
9 , UserImport, ImportMethod(..)
10 , DetailedListing(..)
11 , defaultHeader
12 ) where
13
14 import AST.Listing (Listing)
15 import qualified AST.Listing as Listing
16 import qualified Cheapskate.Types as Markdown
17 import Data.Map.Strict (Map)
18 import qualified Reporting.Annotation as A
19 import AST.V0_16
20
21
22 -- MODULES
23
24
25 data Module ns body =
26 Module
27 { initialComments :: Comments
28 , header :: Maybe Header
29 , docs :: A.Located (Maybe Markdown.Blocks)
30 , imports :: C1 'BeforeTerm (Map ns (C1 'BeforeTerm ImportMethod))
31 , body :: body
32 }
33 deriving (Eq, Show, Functor)
34
35
36 -- HEADERS
37
38 data SourceTag
39 = Normal
40 | Effect Comments
41 | Port Comments
42 deriving (Eq, Show)
43
44
45 {-| Basic info needed to identify modules and determine dependencies. -}
46 data Header = Header
47 { srcTag :: SourceTag
48 , name :: C2 'BeforeTerm 'AfterTerm [UppercaseIdentifier]
49 , moduleSettings :: Maybe (C2 'BeforeSeparator 'AfterSeparator SourceSettings)
50 , exports :: Maybe (C2 'BeforeSeparator 'AfterSeparator (Listing DetailedListing))
51 }
52 deriving (Eq, Show)
53
54
55 defaultHeader :: Header
56 defaultHeader =
57 Header
58 Normal
59 (C ([], []) [UppercaseIdentifier "Main"])
60 Nothing
61 Nothing
62
63
64 data DetailedListing = DetailedListing
65 { values :: Listing.CommentedMap LowercaseIdentifier ()
66 , operators :: Listing.CommentedMap SymbolIdentifier ()
67 , types :: Listing.CommentedMap UppercaseIdentifier (C1 'BeforeTerm (Listing (Listing.CommentedMap UppercaseIdentifier ())))
68 }
69 deriving (Eq, Show)
70
71 instance Semigroup DetailedListing where
72 (DetailedListing av ao at) <> (DetailedListing bv bo bt) = DetailedListing (av <> bv) (ao <> bo) (at <> bt)
73
74 instance Monoid DetailedListing where
75 mempty = DetailedListing mempty mempty mempty
76
77
78 type SourceSettings =
79 [ ( C2 'BeforeTerm 'AfterTerm LowercaseIdentifier
80 , C2 'BeforeTerm 'AfterTerm UppercaseIdentifier
81 )
82 ]
83
84 -- IMPORTs
85
86 type UserImport
87 = (C1 'BeforeTerm [UppercaseIdentifier], ImportMethod)
88
89
90 data ImportMethod = ImportMethod
91 { alias :: Maybe (C2 'BeforeSeparator 'AfterSeparator UppercaseIdentifier)
92 , exposedVars :: C2 'BeforeSeparator 'AfterSeparator (Listing DetailedListing)
93 }
94 deriving (Eq, Show)