@@ -20,6 +20,8 @@
21module Language.PureScript.Externs
21module Language.PureScript.Externs
22 ( ExternsFile(..)
22 ( ExternsFile(..)
23 , ExternsDeclaration(..)
25 , ExternsDeclaration(..)
24 , moduleToExternsFile
26 , moduleToExternsFile
25 , applyExternsFileToEnvironment
27 , applyExternsFileToEnvironment
@@ -55,27 +57,76 @@ data ExternsFile = ExternsFile
55 -- ^ List of module exports
57 -- ^ List of module exports
56 , efExports :: [DeclarationRef]
58 , efExports :: [DeclarationRef]
57 -- ^ List of module imports
59 -- ^ List of module imports
58− , efImports :: [(ModuleName, ImportDeclarationType, Maybe ModuleName)]
60+ , efImports :: [ExternsImport]
59 -- ^ List of operators and their fixities
61 -- ^ List of operators and their fixities
60− , efFixities :: [(Associativity, Precedence, String)]
62+ , efFixities :: [ExternsFixity]
61 -- ^ List of type and value declaration
63 -- ^ List of type and value declaration
62 , efDeclarations :: [ExternsDeclaration]
64 , efDeclarations :: [ExternsDeclaration]
63 } deriving (Show, Read)
65 } deriving (Show, Read)
67+-- | A module import in an externs file
68+data ExternsImport = ExternsImport
70+ -- ^ The imported module
71+ eiModule :: ModuleName
72+ -- ^ The import type: regular, qualified or hiding
73+ , eiImportType :: ImportDeclarationType
74+ -- ^ The imported-as name, for qualified imports
75+ , eiImportedAs :: Maybe ModuleName
76+ } deriving (Show, Read)
78+-- | A fixity declaration in an externs file
79+data ExternsFixity = ExternsFixity
81+ -- ^ The associativity of the operator
82+ efAssociativity :: Associativity
83+ -- ^ The precedence level of the operator
84+ , efPrecedence :: Precedence
85+ -- ^ The operator symbol
86+ , efOperator :: String
87+ } deriving (Show, Read)
65-- | A type or value declaration appearing in an externs file
89-- | A type or value declaration appearing in an externs file
66data ExternsDeclaration =
90data ExternsDeclaration =
67 -- ^ A type declaration
91 -- ^ A type declaration
68− EDType ProperName Kind TypeKind
93+ { edTypeName :: ProperName
95+ , edTypeDeclarationKind :: TypeKind
69 -- ^ A type synonym
97 -- ^ A type synonym
70− | EDTypeSynonym ProperName [(String, Maybe Kind)] Type
98+ | EDTypeSynonym
99+ { edTypeSynonymName :: ProperName
100+ , edTypeSynonymArguments :: [(String, Maybe Kind)]
101+ , edTypeSynonymType :: Type
71 -- ^ A data construtor
103 -- ^ A data construtor
72− | EDDataConstructor ProperName DataDeclType ProperName Type [Ident]
104+ | EDDataConstructor
105+ { edDataCtorName :: ProperName
106+ , edDataCtorOrigin :: DataDeclType
107+ , edDataCtorTypeCtor :: ProperName
108+ , edDataCtorType :: Type
109+ , edDataCtorFields :: [Ident]
73 -- ^ A value declaration
111 -- ^ A value declaration
74− | EDValue Ident Type
112+ | EDValue
113+ { edValueName :: Ident
114+ , edValueType :: Type
75 -- ^ A type class declaration
116 -- ^ A type class declaration
76− | EDClass ProperName [(String, Maybe Kind)] [(Ident, Type)] [Constraint]
117+ | EDClass
118+ { edClassName :: ProperName
119+ , edClassTypeArguments :: [(String, Maybe Kind)]
120+ , edClassMembers :: [(Ident, Type)]
121+ , edClassConstraints :: [Constraint]
77 -- ^ An instance declaration
123 -- ^ An instance declaration
78− | EDInstance (Qualified ProperName) Ident [Type] (Maybe [Constraint])
125+ { edInstanceClassName :: Qualified ProperName
126+ , edInstanceName :: Ident
127+ , edInstanceTypes :: [Type]
128+ , edInstanceConstraints :: Maybe [Constraint]
79 deriving (Show, Read)
130 deriving (Show, Read)
81-- | Convert an externs file back into a module
132-- | Convert an externs file back into a module
@@ -111,8 +162,8 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
111 efFixities = mapMaybe fixityDecl ds
162 efFixities = mapMaybe fixityDecl ds
112 efDeclarations = concatMap toExternsDeclaration efExports
163 efDeclarations = concatMap toExternsDeclaration efExports
114− fixityDecl :: Declaration -> Maybe (Associativity, Precedence, String)
165+ fixityDecl :: Declaration -> Maybe ExternsFixity
115− fixityDecl (FixityDeclaration (Fixity assoc prec) op) = fmap (const (assoc, prec, op)) (find exportsOp exps)
166+ fixityDecl (FixityDeclaration (Fixity assoc prec) op) = fmap (const (ExternsFixity assoc prec op)) (find exportsOp exps)
117 exportsOp :: DeclarationRef -> Bool
168 exportsOp :: DeclarationRef -> Bool
118 exportsOp (PositionedDeclarationRef _ _ r) = exportsOp r
169 exportsOp (PositionedDeclarationRef _ _ r) = exportsOp r
@@ -121,8 +172,8 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
121 fixityDecl (PositionedDeclaration _ _ d) = fixityDecl d
172 fixityDecl (PositionedDeclaration _ _ d) = fixityDecl d
122 fixityDecl _ = Nothing
173 fixityDecl _ = Nothing
124− importDecl :: Declaration -> Maybe (ModuleName, ImportDeclarationType, Maybe ModuleName)
175+ importDecl :: Declaration -> Maybe ExternsImport
125− importDecl (ImportDeclaration m mt qmn) = Just (m, mt, qmn)
176+ importDecl (ImportDeclaration m mt qmn) = Just (ExternsImport m mt qmn)
126 importDecl (PositionedDeclaration _ _ d) = importDecl d
177 importDecl (PositionedDeclaration _ _ d) = importDecl d
127 importDecl _ = Nothing
178 importDecl _ = Nothing
@@ -159,5 +210,7 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
160 toExternsDeclaration _ = []
211 toExternsDeclaration _ = []
213+$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ExternsImport)
214+$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ExternsFixity)
162$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ExternsDeclaration)
215$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ExternsDeclaration)
163$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ExternsFile)
216$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ExternsFile)