git.iko.soy/rowtype-yoga/purescript-native
on eb505ed help sign in
190 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)
121 --
122 | ImportDeclaration ModuleName (Maybe [DeclarationRef])
123 -- |
124 -- A type class declaration (name, argument, member declarations)
125 --
126 | TypeClassDeclaration ProperName [String] [Declaration]
127 -- |
128 -- A type instance declaration (name, dependencies, class name, instance types, member
129 -- declarations)
130 --
131 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
132 deriving (Show, D.Data, D.Typeable)
134-- |
135-- Test if a declaration is a value declaration
136--
137isValueDecl :: Declaration -> Bool
138isValueDecl ValueDeclaration{} = True
139isValueDecl _ = False
141-- |
142-- Test if a declaration is a data type or type synonym declaration
143--
144isDataDecl :: Declaration -> Bool
145isDataDecl DataDeclaration{} = True
146isDataDecl TypeSynonymDeclaration{} = True
147isDataDecl _ = False
149-- |
150-- Test if a declaration is a module import
151--
152isImportDecl :: Declaration -> Bool
153isImportDecl ImportDeclaration{} = True
154isImportDecl _ = False
156-- |
157-- Test if a declaration is a data type foreign import
158--
159isExternDataDecl :: Declaration -> Bool
160isExternDataDecl ExternDataDeclaration{} = True
161isExternDataDecl _ = False
163-- |
164-- Test if a declaration is a type class instance foreign import
165--
166isExternInstanceDecl :: Declaration -> Bool
167isExternInstanceDecl ExternInstanceDeclaration{} = True
168isExternInstanceDecl _ = 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