git.iko.soy/rowtype-yoga/purescript-native
on 5ce8345 help sign in
167 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 and a list of declarations
44--
45data Module = Module ProperName [Declaration] deriving (Show, D.Data, D.Typeable)
47-- |
48-- The type of a foreign import
49--
50data ForeignImportType
51 -- |
52 -- A regular foreign import
53 --
54 = ForeignImport
55 -- |
56 -- A type class dictionary import, generated during desugaring of type class declarations
57 --
58 | TypeClassDictionaryImport
59 -- |
60 -- A type class dictionary member accessor import, generated during desugaring of type class declarations
61 --
62 | TypeClassAccessorImport deriving (Show, Eq, D.Data, D.Typeable)
64-- |
65-- The data type of declarations
66--
67data Declaration
68 -- |
69 -- A data type declaration (name, arguments, data constructors)
70 --
71 = DataDeclaration ProperName [String] [(ProperName, Maybe Type)]
72 -- |
73 -- A minimal mutually recursive set of data type declarations
74 --
75 | DataBindingGroupDeclaration [Declaration]
76 -- |
77 -- A type synonym declaration (name, arguments, type)
78 --
79 | TypeSynonymDeclaration ProperName [String] Type
80 -- |
81 -- A type declaration for a value (name, ty)
82 --
83 | TypeDeclaration Ident Type
84 -- |
85 -- A value declaration (name, top-level binders, optional guard, value)
86 --
87 | ValueDeclaration Ident [[Binder]] (Maybe Guard) Value
88 -- |
89 -- A minimal mutually recursive set of value declarations
90 --
91 | BindingGroupDeclaration [(Ident, Value)]
92 -- |
93 -- A foreign import declaration (type, name, optional inline Javascript, type)
94 --
95 | ExternDeclaration ForeignImportType Ident (Maybe JS) Type
96 -- |
97 -- A data type foreign import (name, kind)
98 --
99 | ExternDataDeclaration ProperName Kind
100 -- |
101 -- A fixity declaration (fixity data, operator name)
102 --
103 | FixityDeclaration Fixity String
104 -- |
105 -- A module import (module name, optional set of identifiers to import)
106 --
107 | ImportDeclaration ModuleName (Maybe [Either Ident ProperName])
108 -- |
109 -- A type class declaration (name, argument, member declarations)
110 --
111 | TypeClassDeclaration ProperName String [Declaration]
112 -- |
113 -- A type instance declaration (dependencies, class name, instance type, member declarations)
114 --
115 | TypeInstanceDeclaration [(Qualified ProperName, Type)] (Qualified ProperName) Type [Declaration]
116 deriving (Show, D.Data, D.Typeable)
118-- |
119-- Test if a declaration is a value declaration
120--
121isValueDecl :: Declaration -> Bool
122isValueDecl (ValueDeclaration _ _ _ _) = True
123isValueDecl _ = False
125-- |
126-- Test if a declaration is a data type or type synonym declaration
127--
128isDataDecl :: Declaration -> Bool
129isDataDecl (DataDeclaration _ _ _) = True
130isDataDecl (TypeSynonymDeclaration _ _ _) = True
131isDataDecl _ = False
133-- |
134-- Test if a declaration is a module import
135--
136isImportDecl :: Declaration -> Bool
137isImportDecl (ImportDeclaration _ _) = True
138isImportDecl _ = False
140-- |
141-- Test if a declaration is a data type foreign import
142--
143isExternDataDecl :: Declaration -> Bool
144isExternDataDecl (ExternDataDeclaration _ _) = True
145isExternDataDecl _ = False
147-- |
148-- Test if a declaration is a fixity declaration
149--
150isFixityDecl :: Declaration -> Bool
151isFixityDecl (FixityDeclaration _ _) = True
152isFixityDecl _ = False
154-- |
155-- Test if a declaration is a foreign import
156--
157isExternDecl :: Declaration -> Bool
158isExternDecl (ExternDeclaration _ _ _ _) = True
159isExternDecl _ = False
161-- |
162-- Test if a declaration is a type class or instance declaration
163--
164isTypeClassDeclaration :: Declaration -> Bool
165isTypeClassDeclaration (TypeClassDeclaration _ _ _) = True
166isTypeClassDeclaration (TypeInstanceDeclaration _ _ _ _) = True
167isTypeClassDeclaration _ = False