git.iko.soy/rowtype-yoga/purescript-native
on dc01fc5 help sign in
169 lines 4.7 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 deriving (Show, Eq, D.Data, D.Typeable)
66-- |
67-- The data type of declarations
68--
69data Declaration
70 -- |
71 -- A data type declaration (name, arguments, data constructors)
72 --
73 = DataDeclaration ProperName [String] [(ProperName, [Type])]
74 -- |
75 -- A minimal mutually recursive set of data type declarations
76 --
77 | DataBindingGroupDeclaration [Declaration]
78 -- |
79 -- A type synonym declaration (name, arguments, type)
80 --
81 | TypeSynonymDeclaration ProperName [String] Type
82 -- |
83 -- A type declaration for a value (name, ty)
84 --
85 | TypeDeclaration Ident Type
86 -- |
87 -- A value declaration (name, top-level binders, optional guard, value)
88 --
89 | ValueDeclaration Ident NameKind [Binder] (Maybe Guard) Value
90 -- |
91 -- A minimal mutually recursive set of value declarations
92 --
93 | BindingGroupDeclaration [(Ident, NameKind, Value)]
94 -- |
95 -- A foreign import declaration (type, name, optional inline Javascript, type)
96 --
97 | ExternDeclaration ForeignImportType Ident (Maybe JS) Type
98 -- |
99 -- A data type foreign import (name, kind)
100 --
101 | ExternDataDeclaration ProperName Kind
102 -- |
103 -- A fixity declaration (fixity data, operator name)
104 --
105 | FixityDeclaration Fixity String
106 -- |
107 -- A module import (module name, optional set of identifiers to import)
108 --
109 | ImportDeclaration ModuleName (Maybe [DeclarationRef])
110 -- |
111 -- A type class declaration (name, argument, member declarations)
112 --
113 | TypeClassDeclaration ProperName [String] [Declaration]
114 -- |
115 -- A type instance declaration (dependencies, class name, instance type, member declarations)
116 --
117 | TypeInstanceDeclaration Ident [(Qualified ProperName, [Type])] (Qualified ProperName) [Type] [Declaration]
118 deriving (Show, D.Data, D.Typeable)
120-- |
121-- Test if a declaration is a value declaration
122--
123isValueDecl :: Declaration -> Bool
124isValueDecl ValueDeclaration{} = True
125isValueDecl _ = False
127-- |
128-- Test if a declaration is a data type or type synonym declaration
129--
130isDataDecl :: Declaration -> Bool
131isDataDecl DataDeclaration{} = True
132isDataDecl TypeSynonymDeclaration{} = True
133isDataDecl _ = False
135-- |
136-- Test if a declaration is a module import
137--
138isImportDecl :: Declaration -> Bool
139isImportDecl ImportDeclaration{} = True
140isImportDecl _ = False
142-- |
143-- Test if a declaration is a data type foreign import
144--
145isExternDataDecl :: Declaration -> Bool
146isExternDataDecl ExternDataDeclaration{} = True
147isExternDataDecl _ = False
149-- |
150-- Test if a declaration is a fixity declaration
151--
152isFixityDecl :: Declaration -> Bool
153isFixityDecl FixityDeclaration{} = True
154isFixityDecl _ = False
156-- |
157-- Test if a declaration is a foreign import
158--
159isExternDecl :: Declaration -> Bool
160isExternDecl ExternDeclaration{} = True
161isExternDecl _ = False
163-- |
164-- Test if a declaration is a type class or instance declaration
165--
166isTypeClassDeclaration :: Declaration -> Bool
167isTypeClassDeclaration TypeClassDeclaration{} = True
168isTypeClassDeclaration TypeInstanceDeclaration{} = True
169isTypeClassDeclaration _ = False