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