git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1236 from hdgarrood/refactor-parse-and-desugar
6f20955Phil Freeman
src/Language/PureScript/Docs/ParseAndDesugar.hs+32−11
@@ -53,20 +53,41 @@ parseAndDesugar inputFiles depsFiles callback = do
53 depsFiles' <- mapM (\(pkgName, f) -> parseAs (FromDep pkgName) f) depsFiles
53 depsFiles' <- mapM (\(pkgName, f) -> parseAs (FromDep pkgName) f) depsFiles
54
54
55 runExceptT $ do
55 runExceptT $ do
56− let eParsed = P.parseModulesFromFiles fileInfoToString (inputFiles' ++ depsFiles')
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 =
57− ms <- throwLeft ParseError eParsed
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
58
75
59− let depsModules = getDepsModuleNames (map (\(fp, m) -> (,m) <$> fp) ms)
76+desugarWithBookmarks ::
60− let eSorted = P.sortModules . map (importPrim . snd) $ ms
77+ [(FileInfo, P.Module)]
61− (ms', _) <- throwLeft SortModulesError eSorted
78+ -> [P.Module]
79+ -> ExceptT ParseDesugarError IO ([Bookmark], [P.Module])
80+desugarWithBookmarks msInfo msSorted = do
81+ msDesugared <- throwLeft DesugarError (desugar msSorted)
62
82
63− modules <- throwLeft DesugarError (desugar ms')
83+ let msDeps = getDepsModuleNames (map (\(fp, m) -> (,m) <$> fp) msInfo)
64− let modules' = map (addPackage depsModules) modules
84+ msPackages = map (addPackage msDeps) msDesugared
65− bookmarks = concatMap collectBookmarks modules'
85+ bookmarks = concatMap collectBookmarks msPackages
66− liftIO (callback bookmarks (takeLocals modules'))
67
86
68− where
87+ return (bookmarks, takeLocals msPackages)
88+
89+throwLeft :: (MonadError e m) => (l -> e) -> Either l r -> m r
69− throwLeft f = either (throwError . f) return
90+throwLeft f = either (throwError . f) return
70
91
71-- | Specifies whether a PureScript source file is considered as:
92-- | Specifies whether a PureScript source file is considered as:
72--
93--