From 3457efd4cbb806118f7893f452bc1dd016e53390 Mon Sep 17 00:00:00 2001 From: Brad Richardson Date: Wed, 14 Oct 2020 15:35:00 -0500 Subject: Refactor parsing process a bit --- bootstrap/src/BuildModel.hs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'bootstrap/src/BuildModel.hs') diff --git a/bootstrap/src/BuildModel.hs b/bootstrap/src/BuildModel.hs index dab8aed..aa720f9 100644 --- a/bootstrap/src/BuildModel.hs +++ b/bootstrap/src/BuildModel.hs @@ -41,6 +41,7 @@ data Source = Program { processRawSource :: RawSource -> Source processRawSource rawSource = let sourceFileName = rawSourceFilename rawSource + parsedContents = parseContents rawSource in Program { programSourceFileName = sourceFileName , programObjectFileName = \buildDirectory -> @@ -49,25 +50,25 @@ processRawSource rawSource = sourceFileName ) <.> "o" - , programModulesUsed = getModulesUsed rawSource + , programModulesUsed = getModulesUsed parsedContents } pathSeparatorsToUnderscores :: FilePath -> FilePath pathSeparatorsToUnderscores fileName = intercalate "_" (splitDirectories fileName) -getModulesUsed :: RawSource -> [String] -getModulesUsed rawSource = - let fileLines = lines $ rawSourceContents rawSource - lineContents = map parseFortranLine fileLines - in contentsToModuleNames lineContents - -contentsToModuleNames :: [LineContents] -> [String] -contentsToModuleNames = mapMaybe contentToMaybeModuleName - where - contentToMaybeModuleName content = case content of - ModuleUsed moduleName -> Just moduleName - _ -> Nothing +parseContents :: RawSource -> [LineContents] +parseContents rawSource = + let fileLines = lines $ rawSourceContents rawSource in + map parseFortranLine fileLines + +getModulesUsed :: [LineContents] -> [String] +getModulesUsed = + mapMaybe contentToMaybeModuleName + where + contentToMaybeModuleName content = case content of + ModuleUsed moduleName -> Just moduleName + _ -> Nothing readFileLinesIO :: FilePath -> IO [String] readFileLinesIO file = do -- cgit v1.2.3