88-- Stability : experimental
99-- Portability :
1010--
11- -- |
11+ -- | Data types for modules and declarations
1212--
1313-----------------------------------------------------------------------------
1414
@@ -24,59 +24,143 @@ import Language.PureScript.CodeGen.JS.AST
2424
2525import qualified Data.Data as D
2626
27+ -- |
28+ -- A precedence level for an infix operator
29+ --
2730type Precedence = Integer
2831
32+ -- |
33+ -- Associativity for infix operators
34+ --
2935data Associativity = Infixl | Infixr deriving (Show , D.Data , D.Typeable )
3036
37+ -- |
38+ -- Fixity data for infix operators
39+ --
3140data Fixity = Fixity Associativity Precedence deriving (Show , D.Data , D.Typeable )
3241
42+ -- |
43+ -- A module declaration, consisting of a module name and a list of declarations
44+ --
3345data Module = Module ProperName [Declaration ] deriving (Show , D.Data , D.Typeable )
3446
47+ -- |
48+ -- The type of a foreign import
49+ --
3550data ForeignImportType
51+ -- |
52+ -- A regular foreign import
53+ --
3654 = ForeignImport
55+ -- |
56+ -- A type class dictionary import, generated during desugaring of type class declarations
57+ --
3758 | TypeClassDictionaryImport
59+ -- |
60+ -- A type class dictionary member accessor import, generated during desugaring of type class declarations
61+ --
3862 | TypeClassAccessorImport deriving (Show , Eq , D.Data , D.Typeable )
3963
64+ -- |
65+ -- The data type of declarations
66+ --
4067data Declaration
68+ -- |
69+ -- A data type declaration (name, arguments, data constructors)
70+ --
4171 = DataDeclaration ProperName [String ] [(ProperName , Maybe Type )]
72+ -- |
73+ -- A minimal mutually recursive set of data type declarations
74+ --
4275 | DataBindingGroupDeclaration [Declaration ]
76+ -- |
77+ -- A type synonym declaration (name, arguments, type)
78+ --
4379 | TypeSynonymDeclaration ProperName [String ] Type
80+ -- |
81+ -- A type declaration for a value (name, ty)
82+ --
4483 | TypeDeclaration Ident Type
84+ -- |
85+ -- A value declaration (name, top-level binders, optional guard, value)
86+ --
4587 | ValueDeclaration Ident [[Binder ]] (Maybe Guard ) Value
88+ -- |
89+ -- A minimal mutually recursive set of value declarations
90+ --
4691 | BindingGroupDeclaration [(Ident , Value )]
92+ -- |
93+ -- A foreign import declaration (type, name, optional inline Javascript, type)
94+ --
4795 | ExternDeclaration ForeignImportType Ident (Maybe JS ) Type
96+ -- |
97+ -- A data type foreign import (name, kind)
98+ --
4899 | ExternDataDeclaration ProperName Kind
100+ -- |
101+ -- A fixity declaration (fixity data, operator name)
102+ --
49103 | FixityDeclaration Fixity String
104+ -- |
105+ -- A module import (module name, optional set of identifiers to import)
106+ --
50107 | ImportDeclaration ModuleName (Maybe [Either Ident ProperName ])
108+ -- |
109+ -- A type class declaration (name, argument, member declarations)
110+ --
51111 | TypeClassDeclaration ProperName String [Declaration ]
112+ -- |
113+ -- A type instance declaration (dependencies, class name, instance type, member declarations)
114+ --
52115 | TypeInstanceDeclaration [(Qualified ProperName , Type )] (Qualified ProperName ) Type [Declaration ]
53116 deriving (Show , D.Data , D.Typeable )
54117
118+ -- |
119+ -- Test if a declaration is a value declaration
120+ --
55121isValueDecl :: Declaration -> Bool
56122isValueDecl (ValueDeclaration _ _ _ _) = True
57123isValueDecl _ = False
58124
125+ -- |
126+ -- Test if a declaration is a data type or type synonym declaration
127+ --
59128isDataDecl :: Declaration -> Bool
60129isDataDecl (DataDeclaration _ _ _) = True
61130isDataDecl (TypeSynonymDeclaration _ _ _) = True
62131isDataDecl _ = False
63132
133+ -- |
134+ -- Test if a declaration is a module import
135+ --
64136isImportDecl :: Declaration -> Bool
65137isImportDecl (ImportDeclaration _ _) = True
66138isImportDecl _ = False
67139
140+ -- |
141+ -- Test if a declaration is a data type foreign import
142+ --
68143isExternDataDecl :: Declaration -> Bool
69144isExternDataDecl (ExternDataDeclaration _ _) = True
70145isExternDataDecl _ = False
71146
147+ -- |
148+ -- Test if a declaration is a fixity declaration
149+ --
72150isFixityDecl :: Declaration -> Bool
73151isFixityDecl (FixityDeclaration _ _) = True
74152isFixityDecl _ = False
75153
154+ -- |
155+ -- Test if a declaration is a foreign import
156+ --
76157isExternDecl :: Declaration -> Bool
77158isExternDecl (ExternDeclaration _ _ _ _) = True
78159isExternDecl _ = False
79160
161+ -- |
162+ -- Test if a declaration is a type class or instance declaration
163+ --
80164isTypeClassDeclaration :: Declaration -> Bool
81165isTypeClassDeclaration (TypeClassDeclaration _ _ _) = True
82166isTypeClassDeclaration (TypeInstanceDeclaration _ _ _ _) = True
0 commit comments