git.iko.soy/rowtype-yoga/purescript-native
on 973babe help sign in
190 lines 5.2 kB history raw
1-----------------------------------------------------------------------------
2--
3-- Module : Language.PureScript.Declarations
4-- Copyright : (c) Phil Freeman 2013
5-- License : MIT
6--
7-- Maintainer : Phil Freeman <paf31@cantab.net>
8-- Stability : experimental
9-- Portability :
10--
11-- | Data types for modules and declarations
12--
13-----------------------------------------------------------------------------
15{-# LANGUAGE DeriveDataTypeable #-}
17module Language.PureScript.Declarations where
19import Language.PureScript.Values
20import Language.PureScript.Types
21import Language.PureScript.Names
22import Language.PureScript.Kinds
23import Language.PureScript.CodeGen.JS.AST
25import qualified Data.Data as D
27-- |
28-- A precedence level for an infix operator
29--
30type Precedence = Integer
32-- |
33-- Associativity for infix operators
34--
35data Associativity = Infixl | Infixr deriving (Show, D.Data, D.Typeable)
37-- |
38-- Fixity data for infix operators
39--
40data Fixity = Fixity Associativity Precedence deriving (Show, D.Data, D.Typeable)
42-- |
43-- A module declaration, consisting of a module name, a list of declarations, and a list of the
44-- declarations that are explicitly imported. If the export list is Nothing, everything is exported.
45--
46data Module = Module ModuleName [Declaration] (Maybe [DeclarationRef]) deriving (Show, D.Data, D.Typeable)
48-- |
49-- The type of a foreign import
50--
51data ForeignImportType
52 -- |
53 -- A regular foreign import
54 --
55 = ForeignImport
56 -- |
57 -- A foreign import which contains inline Javascript as a string literal
58 --
59 | InlineJavascript
60 -- |
61 -- A type class dictionary import, generated during desugaring of type class declarations
62 --
63 | TypeClassDictionaryImport
64 -- |
65 -- A type class dictionary member accessor import, generated during desugaring of type class declarations
66 --
67 | TypeClassAccessorImport deriving (Show, Eq, D.Data, D.Typeable)
69-- |
70-- An item in a list of explicit imports or exports
71--
72data DeclarationRef
73 -- |
74 -- A type constructor with data constructors
75 --
76 = TypeRef ProperName (Maybe [ProperName])
77 -- |
78 -- A value
79 --
80 | ValueRef Ident
81 -- |
82 -- A type class
83 --
84 | TypeClassRef ProperName
85 deriving (Show, Eq, D.Data, D.Typeable)
87-- |
88-- The data type of declarations
89--
90data Declaration
91 -- |
92 -- A data type declaration (name, arguments, data constructors)
93 --
94 = DataDeclaration ProperName [String] [(ProperName, [Type])]
95 -- |
96 -- A minimal mutually recursive set of data type declarations
97 --
98 | DataBindingGroupDeclaration [Declaration]
99 -- |
100 -- A type synonym declaration (name, arguments, type)
101 --
102 | TypeSynonymDeclaration ProperName [String] Type
103 -- |
104 -- A type declaration for a value (name, ty)
105 --
106 | TypeDeclaration Ident Type
107 -- |
108 -- A value declaration (name, top-level binders, optional guard, value)
109 --
110 | ValueDeclaration Ident [Binder] (Maybe Guard) Value
111 -- |
112 -- A minimal mutually recursive set of value declarations
113 --
114 | BindingGroupDeclaration [(Ident, Value)]
115 -- |
116 -- A foreign import declaration (type, name, optional inline Javascript, type)
117 --
118 | ExternDeclaration ForeignImportType Ident (Maybe JS) Type
119 -- |
120 -- A data type foreign import (name, kind)
121 --
122 | ExternDataDeclaration ProperName Kind
123 -- |
124 -- A fixity declaration (fixity data, operator name)
125 --
126 | FixityDeclaration Fixity String
127 -- |
128 -- A module import (module name, optional set of identifiers to import)
129 --
130 | ImportDeclaration ModuleName (Maybe [DeclarationRef])
131 -- |
132 -- A type class declaration (name, argument, member declarations)
133 --
134 | TypeClassDeclaration ProperName [String] [Declaration]
135 -- |
136 -- A type instance declaration (dependencies, class name, instance type, member declarations)
137 --
138 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
139 deriving (Show, D.Data, D.Typeable)
141-- |
142-- Test if a declaration is a value declaration
143--
144isValueDecl :: Declaration -> Bool
145isValueDecl ValueDeclaration{} = True
146isValueDecl _ = False
148-- |
149-- Test if a declaration is a data type or type synonym declaration
150--
151isDataDecl :: Declaration -> Bool
152isDataDecl DataDeclaration{} = True
153isDataDecl TypeSynonymDeclaration{} = True
154isDataDecl _ = False
156-- |
157-- Test if a declaration is a module import
158--
159isImportDecl :: Declaration -> Bool
160isImportDecl ImportDeclaration{} = True
161isImportDecl _ = False
163-- |
164-- Test if a declaration is a data type foreign import
165--
166isExternDataDecl :: Declaration -> Bool
167isExternDataDecl ExternDataDeclaration{} = True
168isExternDataDecl _ = False
170-- |
171-- Test if a declaration is a fixity declaration
172--
173isFixityDecl :: Declaration -> Bool
174isFixityDecl FixityDeclaration{} = True
175isFixityDecl _ = False
177-- |
178-- Test if a declaration is a foreign import
179--
180isExternDecl :: Declaration -> Bool
181isExternDecl ExternDeclaration{} = True
182isExternDecl _ = False
184-- |
185-- Test if a declaration is a type class or instance declaration
186--
187isTypeClassDeclaration :: Declaration -> Bool
188isTypeClassDeclaration TypeClassDeclaration{} = True
189isTypeClassDeclaration TypeInstanceDeclaration{} = True
190isTypeClassDeclaration _ = False