@@ -53,20 +53,41 @@ parseAndDesugar inputFiles depsFiles callback = do
5353 depsFiles' <- mapM (\(pkgName, f) -> parseAs (FromDep pkgName) f) depsFiles
5454
5555 runExceptT $ do
56− let eParsed = P.parseModulesFromFiles fileInfoToString (inputFiles' ++ depsFiles')
57− ms <- throwLeft ParseError eParsed
56+ ms <- parseFiles (inputFiles' ++ depsFiles')
57+ ms' <- sortModules (map snd ms)
58+ (bs, ms'') <- desugarWithBookmarks ms ms'
59+ liftIO $ callback bs ms''
60+
61+parseFiles ::
62+ [(FileInfo, FilePath)]
63+ -> ExceptT ParseDesugarError IO [(FileInfo, P.Module)]
64+parseFiles =
65+ throwLeft ParseError . P.parseModulesFromFiles fileInfoToString
66+
67+sortModules ::
68+ [P.Module]
69+ -> ExceptT ParseDesugarError IO [P.Module]
70+sortModules =
71+ fmap fst . throwLeft SortModulesError . sortModules' . map importPrim
72+ where
73+ sortModules' :: [P.Module] -> Either P.MultipleErrors ([P.Module], P.ModuleGraph)
74+ sortModules' = P.sortModules
5875
59− let depsModules = getDepsModuleNames (map (\(fp, m) -> (,m) <$> fp) ms)
60− let eSorted = P.sortModules . map (importPrim . snd) $ ms
61− (ms', _) <- throwLeft SortModulesError eSorted
76+desugarWithBookmarks ::
77+ [(FileInfo, P.Module)]
78+ -> [P.Module]
79+ -> ExceptT ParseDesugarError IO ([Bookmark], [P.Module])
80+desugarWithBookmarks msInfo msSorted = do
81+ msDesugared <- throwLeft DesugarError (desugar msSorted)
6282
63− modules <- throwLeft DesugarError (desugar ms')
64− let modules' = map (addPackage depsModules) modules
65− bookmarks = concatMap collectBookmarks modules'
66− liftIO (callback bookmarks (takeLocals modules'))
83+ let msDeps = getDepsModuleNames (map (\(fp, m) -> (,m) <$> fp) msInfo)
84+ msPackages = map (addPackage msDeps) msDesugared
85+ bookmarks = concatMap collectBookmarks msPackages
6786
68− where
69− throwLeft f = either (throwError . f) return
87+ return (bookmarks, takeLocals msPackages)
88+
89+throwLeft :: (MonadError e m) => (l -> e) -> Either l r -> m r
90+throwLeft f = either (throwError . f) return
7091
7192-- | Specifies whether a PureScript source file is considered as:
7293--