git.iko.soy/rowtype-yoga/purescript-native
on b314ba1 help sign in
186 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
24import Language.PureScript.Environment
26import qualified Data.Data as D
28-- |
29-- A precedence level for an infix operator
30--
31type Precedence = Integer
33-- |
34-- Associativity for infix operators
35--
36data Associativity = Infixl | Infixr deriving (Show, D.Data, D.Typeable)
38-- |
39-- Fixity data for infix operators
40--
41data Fixity = Fixity Associativity Precedence deriving (Show, D.Data, D.Typeable)
43-- |
44-- A module declaration, consisting of a module name, a list of declarations, and a list of the
45-- declarations that are explicitly imported. If the export list is Nothing, everything is exported.
46--
47data Module = Module ModuleName [Declaration] (Maybe [DeclarationRef]) deriving (Show, D.Data, D.Typeable)
49-- |
50-- An item in a list of explicit imports or exports
51--
52data DeclarationRef
53 -- |
54 -- A type constructor with data constructors
55 --
56 = TypeRef ProperName (Maybe [ProperName])
57 -- |
58 -- A value
59 --
60 | ValueRef Ident
61 -- |
62 -- A type class
63 --
64 | TypeClassRef ProperName
65 -- |
66 -- A type class instance, created during typeclass desugaring (name, class name, instance types)
67 --
68 | TypeInstanceRef Ident
69 deriving (Show, Eq, D.Data, D.Typeable)
71-- |
72-- The data type of declarations
73--
74data Declaration
75 -- |
76 -- A data type declaration (name, arguments, data constructors)
77 --
78 = DataDeclaration ProperName [String] [(ProperName, [Type])]
79 -- |
80 -- A minimal mutually recursive set of data type declarations
81 --
82 | DataBindingGroupDeclaration [Declaration]
83 -- |
84 -- A type synonym declaration (name, arguments, type)
85 --
86 | TypeSynonymDeclaration ProperName [String] Type
87 -- |
88 -- A type declaration for a value (name, ty)
89 --
90 | TypeDeclaration Ident Type
91 -- |
92 -- A value declaration (name, top-level binders, optional guard, value)
93 --
94 | ValueDeclaration Ident NameKind [Binder] (Maybe Guard) Value
95 -- |
96 -- A minimal mutually recursive set of value declarations
97 --
98 | BindingGroupDeclaration [(Ident, NameKind, Value)]
99 -- |
100 -- A foreign import declaration (type, name, optional inline Javascript, type)
101 --
102 | ExternDeclaration ForeignImportType Ident (Maybe JS) Type
103 -- |
104 -- A data type foreign import (name, kind)
105 --
106 | ExternDataDeclaration ProperName Kind
107 -- |
108 -- A type class instance foreign import
109 --
110 | ExternInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type]
111 -- |
112 -- A fixity declaration (fixity data, operator name)
113 --
114 | FixityDeclaration Fixity String
115 -- |
116 -- A module import (module name, optional set of identifiers to import)
117 --
118 | ImportDeclaration ModuleName (Maybe [DeclarationRef])
119 -- |
120 -- A type class declaration (name, argument, member declarations)
121 --
122 | TypeClassDeclaration ProperName [String] [Declaration]
123 -- |
124 -- A type instance declaration (name, dependencies, class name, instance types, member
125 -- declarations)
126 --
127 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
128 deriving (Show, D.Data, D.Typeable)
130-- |
131-- Test if a declaration is a value declaration
132--
133isValueDecl :: Declaration -> Bool
134isValueDecl ValueDeclaration{} = True
135isValueDecl _ = False
137-- |
138-- Test if a declaration is a data type or type synonym declaration
139--
140isDataDecl :: Declaration -> Bool
141isDataDecl DataDeclaration{} = True
142isDataDecl TypeSynonymDeclaration{} = True
143isDataDecl _ = False
145-- |
146-- Test if a declaration is a module import
147--
148isImportDecl :: Declaration -> Bool
149isImportDecl ImportDeclaration{} = True
150isImportDecl _ = False
152-- |
153-- Test if a declaration is a data type foreign import
154--
155isExternDataDecl :: Declaration -> Bool
156isExternDataDecl ExternDataDeclaration{} = True
157isExternDataDecl _ = False
159-- |
160-- Test if a declaration is a type class instance foreign import
161--
162isExternInstanceDecl :: Declaration -> Bool
163isExternInstanceDecl ExternInstanceDeclaration{} = True
164isExternInstanceDecl _ = False
166-- |
167-- Test if a declaration is a fixity declaration
168--
169isFixityDecl :: Declaration -> Bool
170isFixityDecl FixityDeclaration{} = True
171isFixityDecl _ = False
173-- |
174-- Test if a declaration is a foreign import
175--
176isExternDecl :: Declaration -> Bool
177isExternDecl ExternDeclaration{} = True
178isExternDecl _ = False
180-- |
181-- Test if a declaration is a type class or instance declaration
182--
183isTypeClassDeclaration :: Declaration -> Bool
184isTypeClassDeclaration TypeClassDeclaration{} = True
185isTypeClassDeclaration TypeInstanceDeclaration{} = True
186isTypeClassDeclaration _ = False