git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Give names for all JSON fields
907ebdaPhil Freeman
src/Language/PureScript/Externs.hs+65−12
@@ -20,6 +20,8 @@
20
20
21module Language.PureScript.Externs
21module Language.PureScript.Externs
22 ( ExternsFile(..)
22 ( ExternsFile(..)
23+ , ExternsImport(..)
24+ , ExternsFixity(..)
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)
64
66
67+-- | A module import in an externs file
68+data ExternsImport = ExternsImport
69+ {
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)
77+
78+-- | A fixity declaration in an externs file
79+data ExternsFixity = ExternsFixity
80+ {
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)
88+
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
92+ EDType
68− EDType ProperName Kind TypeKind
93+ { edTypeName :: ProperName
94+ , edTypeKind :: Kind
95+ , edTypeDeclarationKind :: TypeKind
96+ }
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
102+ }
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]
110+ }
73 -- ^ A value declaration
111 -- ^ A value declaration
74− | EDValue Ident Type
112+ | EDValue
113+ { edValueName :: Ident
114+ , edValueType :: Type
115+ }
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]
122+ }
77 -- ^ An instance declaration
123 -- ^ An instance declaration
124+ | EDInstance
78− | EDInstance (Qualified ProperName) Ident [Type] (Maybe [Constraint])
125+ { edInstanceClassName :: Qualified ProperName
126+ , edInstanceName :: Ident
127+ , edInstanceTypes :: [Type]
128+ , edInstanceConstraints :: Maybe [Constraint]
129+ }
79 deriving (Show, Read)
130 deriving (Show, Read)
80
131
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
113
164
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)
116 where
167 where
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
123
174
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
128
179
@@ -159,5 +210,7 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
159 ]
210 ]
160 toExternsDeclaration _ = []
211 toExternsDeclaration _ = []
161
212
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)
src/Language/PureScript/Sugar/Names.hs+1−1
@@ -56,7 +56,7 @@ desugarImports externs modules = do
56 let members = Exports{..}
56 let members = Exports{..}
57 ss = internalModuleSourceSpan "<Externs>"
57 ss = internalModuleSourceSpan "<Externs>"
58 env' = M.insert efModuleName (ss, nullImports, members) env
58 env' = M.insert efModuleName (ss, nullImports, members) env
59− fromEFImport (mn, mt, qmn) = (mn, [(Nothing, mt, qmn)])
59+ fromEFImport (ExternsImport mn mt qmn) = (mn, [(Nothing, mt, qmn)])
60 imps <- foldM (resolveModuleImport efModuleName env') nullImports (map fromEFImport efImports)
60 imps <- foldM (resolveModuleImport efModuleName env') nullImports (map fromEFImport efImports)
61 exps <- resolveExports env' efModuleName imps members efExports
61 exps <- resolveExports env' efModuleName imps members efExports
62 return $ M.insert efModuleName (ss, imps, exps) env
62 return $ M.insert efModuleName (ss, imps, exps) env
src/Language/PureScript/Sugar/Operators.hs+2−2
@@ -83,9 +83,9 @@ removeParens =
83 go val = val
83 go val = val
84
84
85externsFixities :: ExternsFile -> [(Qualified Ident, SourceSpan, Fixity)]
85externsFixities :: ExternsFile -> [(Qualified Ident, SourceSpan, Fixity)]
86−externsFixities ExternsFile{..} =
86+externsFixities ExternsFile{..} =
87 [ (Qualified (Just efModuleName) (Op op), internalModuleSourceSpan "", Fixity assoc prec)
87 [ (Qualified (Just efModuleName) (Op op), internalModuleSourceSpan "", Fixity assoc prec)
88− | (assoc, prec, op) <- efFixities
88+ | ExternsFixity assoc prec op <- efFixities
89 ]
89 ]
90
90
91collectFixities :: Module -> [(Qualified Ident, SourceSpan, Fixity)]
91collectFixities :: Module -> [(Qualified Ident, SourceSpan, Fixity)]