git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Give names for all JSON fields
commit907ebdabeb75f0ed682e78fa970e130880da7e8b authorPhil Freeman <paf31@cantab.net> dateWed 23 Sep 2015, 20:29 (11 years ago) parentb9cb5d9
3 files changed+68−15
src/Language/PureScript/Externs.hs+65−12 src/Language/PureScript/Sugar/Names.hs+1−1 src/Language/PureScript/Sugar/Operators.hs+2−2
src/Language/PureScript/Externs.hs+65−12
@@ -20,6 +20,8 @@
2020
2121module Language.PureScript.Externs
2222 ( ExternsFile(..)
23+ , ExternsImport(..)
24+ , ExternsFixity(..)
2325 , ExternsDeclaration(..)
2426 , moduleToExternsFile
2527 , applyExternsFileToEnvironment
@@ -55,27 +57,76 @@ data ExternsFile = ExternsFile
5557 -- ^ List of module exports
5658 , efExports :: [DeclarationRef]
5759 -- ^ List of module imports
58− , efImports :: [(ModuleName, ImportDeclarationType, Maybe ModuleName)]
60+ , efImports :: [ExternsImport]
5961 -- ^ List of operators and their fixities
60− , efFixities :: [(Associativity, Precedence, String)]
62+ , efFixities :: [ExternsFixity]
6163 -- ^ List of type and value declaration
6264 , efDeclarations :: [ExternsDeclaration]
6365 } deriving (Show, Read)
6466
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+
6589-- | A type or value declaration appearing in an externs file
6690data ExternsDeclaration =
6791 -- ^ A type declaration
68− EDType ProperName Kind TypeKind
92+ EDType
93+ { edTypeName :: ProperName
94+ , edTypeKind :: Kind
95+ , edTypeDeclarationKind :: TypeKind
96+ }
6997 -- ^ A type synonym
70− | EDTypeSynonym ProperName [(String, Maybe Kind)] Type
98+ | EDTypeSynonym
99+ { edTypeSynonymName :: ProperName
100+ , edTypeSynonymArguments :: [(String, Maybe Kind)]
101+ , edTypeSynonymType :: Type
102+ }
71103 -- ^ 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+ }
73111 -- ^ A value declaration
74− | EDValue Ident Type
112+ | EDValue
113+ { edValueName :: Ident
114+ , edValueType :: Type
115+ }
75116 -- ^ 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+ }
77123 -- ^ An instance declaration
78− | EDInstance (Qualified ProperName) Ident [Type] (Maybe [Constraint])
124+ | EDInstance
125+ { edInstanceClassName :: Qualified ProperName
126+ , edInstanceName :: Ident
127+ , edInstanceTypes :: [Type]
128+ , edInstanceConstraints :: Maybe [Constraint]
129+ }
79130 deriving (Show, Read)
80131
81132-- | Convert an externs file back into a module
@@ -111,8 +162,8 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
111162 efFixities = mapMaybe fixityDecl ds
112163 efDeclarations = concatMap toExternsDeclaration efExports
113164
114− fixityDecl :: Declaration -> Maybe (Associativity, Precedence, String)
115− fixityDecl (FixityDeclaration (Fixity assoc prec) op) = fmap (const (assoc, prec, op)) (find exportsOp exps)
165+ fixityDecl :: Declaration -> Maybe ExternsFixity
166+ fixityDecl (FixityDeclaration (Fixity assoc prec) op) = fmap (const (ExternsFixity assoc prec op)) (find exportsOp exps)
116167 where
117168 exportsOp :: DeclarationRef -> Bool
118169 exportsOp (PositionedDeclarationRef _ _ r) = exportsOp r
@@ -121,8 +172,8 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
121172 fixityDecl (PositionedDeclaration _ _ d) = fixityDecl d
122173 fixityDecl _ = Nothing
123174
124− importDecl :: Declaration -> Maybe (ModuleName, ImportDeclarationType, Maybe ModuleName)
125− importDecl (ImportDeclaration m mt qmn) = Just (m, mt, qmn)
175+ importDecl :: Declaration -> Maybe ExternsImport
176+ importDecl (ImportDeclaration m mt qmn) = Just (ExternsImport m mt qmn)
126177 importDecl (PositionedDeclaration _ _ d) = importDecl d
127178 importDecl _ = Nothing
128179
@@ -159,5 +210,7 @@ moduleToExternsFile (Module _ _ mn ds (Just exps)) env = ExternsFile{..}
159210 ]
160211 toExternsDeclaration _ = []
161212
213+$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ExternsImport)
214+$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ExternsFixity)
162215$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ExternsDeclaration)
163216$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ExternsFile)
src/Language/PureScript/Sugar/Names.hs+1−1
@@ -56,7 +56,7 @@ desugarImports externs modules = do
5656 let members = Exports{..}
5757 ss = internalModuleSourceSpan "<Externs>"
5858 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)])
6060 imps <- foldM (resolveModuleImport efModuleName env') nullImports (map fromEFImport efImports)
6161 exps <- resolveExports env' efModuleName imps members efExports
6262 return $ M.insert efModuleName (ss, imps, exps) env
src/Language/PureScript/Sugar/Operators.hs+2−2
@@ -83,9 +83,9 @@ removeParens =
8383 go val = val
8484
8585externsFixities :: ExternsFile -> [(Qualified Ident, SourceSpan, Fixity)]
86−externsFixities ExternsFile{..} =
86+externsFixities ExternsFile{..} =
8787 [ (Qualified (Just efModuleName) (Op op), internalModuleSourceSpan "", Fixity assoc prec)
88− | (assoc, prec, op) <- efFixities
88+ | ExternsFixity assoc prec op <- efFixities
8989 ]
9090
9191collectFixities :: Module -> [(Qualified Ident, SourceSpan, Fixity)]