git.iko.soy/rowtype-yoga/purescript-native
on 415a33f help sign in
185 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-- An item in a list of explicit imports or exports
50--
51data DeclarationRef
52 -- |
53 -- A type constructor with data constructors
54 --
55 = TypeRef ProperName (Maybe [ProperName])
56 -- |
57 -- A value
58 --
59 | ValueRef Ident
60 -- |
61 -- A type class
62 --
63 | TypeClassRef ProperName
64 -- |
65 -- A type class instance, created during typeclass desugaring (name, class name, instance types)
66 --
67 | TypeInstanceRef Ident (Qualified ProperName) [Type]
68 deriving (Show, Eq, D.Data, D.Typeable)
70-- |
71-- The data type of declarations
72--
73data Declaration
74 -- |
75 -- A data type declaration (name, arguments, data constructors)
76 --
77 = DataDeclaration ProperName [String] [(ProperName, [Type])]
78 -- |
79 -- A minimal mutually recursive set of data type declarations
80 --
81 | DataBindingGroupDeclaration [Declaration]
82 -- |
83 -- A type synonym declaration (name, arguments, type)
84 --
85 | TypeSynonymDeclaration ProperName [String] Type
86 -- |
87 -- A type declaration for a value (name, ty)
88 --
89 | TypeDeclaration Ident Type
90 -- |
91 -- A value declaration (name, top-level binders, optional guard, value)
92 --
93 | ValueDeclaration Ident NameKind [Binder] (Maybe Guard) Value
94 -- |
95 -- A minimal mutually recursive set of value declarations
96 --
97 | BindingGroupDeclaration [(Ident, NameKind, Value)]
98 -- |
99 -- A foreign import declaration (type, name, optional inline Javascript, type)
100 --
101 | ExternDeclaration ForeignImportType Ident (Maybe JS) Type
102 -- |
103 -- A data type foreign import (name, kind)
104 --
105 | ExternDataDeclaration ProperName Kind
106 -- |
107 -- A type class instance foreign import
108 --
109 | ExternInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type]
110 -- |
111 -- A fixity declaration (fixity data, operator name)
112 --
113 | FixityDeclaration Fixity String
114 -- |
115 -- A module import (module name, optional set of identifiers to import)
116 --
117 | ImportDeclaration ModuleName (Maybe [DeclarationRef])
118 -- |
119 -- A type class declaration (name, argument, member declarations)
120 --
121 | TypeClassDeclaration ProperName [String] [Declaration]
122 -- |
123 -- A type instance declaration (name, dependencies, class name, instance types, member
124 -- declarations)
125 --
126 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
127 deriving (Show, D.Data, D.Typeable)
129-- |
130-- Test if a declaration is a value declaration
131--
132isValueDecl :: Declaration -> Bool
133isValueDecl ValueDeclaration{} = True
134isValueDecl _ = False
136-- |
137-- Test if a declaration is a data type or type synonym declaration
138--
139isDataDecl :: Declaration -> Bool
140isDataDecl DataDeclaration{} = True
141isDataDecl TypeSynonymDeclaration{} = True
142isDataDecl _ = False
144-- |
145-- Test if a declaration is a module import
146--
147isImportDecl :: Declaration -> Bool
148isImportDecl ImportDeclaration{} = True
149isImportDecl _ = False
151-- |
152-- Test if a declaration is a data type foreign import
153--
154isExternDataDecl :: Declaration -> Bool
155isExternDataDecl ExternDataDeclaration{} = True
156isExternDataDecl _ = False
158-- |
159-- Test if a declaration is a type class instance foreign import
160--
161isExternInstanceDecl :: Declaration -> Bool
162isExternInstanceDecl ExternInstanceDeclaration{} = True
163isExternInstanceDecl _ = False
165-- |
166-- Test if a declaration is a fixity declaration
167--
168isFixityDecl :: Declaration -> Bool
169isFixityDecl FixityDeclaration{} = True
170isFixityDecl _ = False
172-- |
173-- Test if a declaration is a foreign import
174--
175isExternDecl :: Declaration -> Bool
176isExternDecl ExternDeclaration{} = True
177isExternDecl _ = False
179-- |
180-- Test if a declaration is a type class or instance declaration
181--
182isTypeClassDeclaration :: Declaration -> Bool
183isTypeClassDeclaration TypeClassDeclaration{} = True
184isTypeClassDeclaration TypeInstanceDeclaration{} = True
185isTypeClassDeclaration _ = False