git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #2153 from purescript/imports-first

Require imports to appear before other declarations

commit469214f5ca0650a763b433d05359bfb147cba61a authorPhil Freeman <paf31@cantab.net> dateSun 22 May 2016, 15:52 (10 years ago) parente7ddf823ca5543
1 file changed+7−2
src/Language/PureScript/Parser/Declarations.hs+7−2
src/Language/PureScript/Parser/Declarations.hs+7−2
@@ -234,7 +234,6 @@ parseDeclaration = positioned (P.choice
234234 , parseValueDeclaration
235235 , parseExternDeclaration
236236 , parseFixityDeclaration
237− , parseImportDeclaration
238237 , parseTypeClassDeclaration
239238 , parseTypeInstanceDeclaration
240239 , parseDerivingInstanceDeclaration
@@ -258,7 +257,13 @@ parseModule = do
258257 name <- moduleName
259258 exports <- P.optionMaybe $ parens $ commaSep1 parseDeclarationRef
260259 reserved "where"
261− decls <- mark (P.many (same *> parseDeclaration))
260+ decls <- mark $ do
261+ -- TODO: extract a module header structure here, and provide a
262+ -- parseModuleHeader function. This should allow us to speed up rebuilds
263+ -- by only parsing as far as the module header. See PR #2054.
264+ imports <- P.many (same *> parseImportDeclaration)
265+ decls <- P.many (same *> parseDeclaration)
266+ return (imports ++ decls)
262267 _ <- P.eof
263268 end <- P.getPosition
264269 let ss = SourceSpan (P.sourceName start) (C.toSourcePos start) (C.toSourcePos end)