diff options
-rw-r--r-- | bootstrap/src/BuildModel.hs | 18 | ||||
-rw-r--r-- | bootstrap/unit_test/ModuleSourceConstructionTest.hs | 5 |
2 files changed, 23 insertions, 0 deletions
diff --git a/bootstrap/src/BuildModel.hs b/bootstrap/src/BuildModel.hs index 1610784..baefda9 100644 --- a/bootstrap/src/BuildModel.hs +++ b/bootstrap/src/BuildModel.hs @@ -46,6 +46,7 @@ data Source = { moduleSourceFileName :: FilePath , moduleObjectFileName :: FilePath -> FilePath , moduleModulesUsed :: [String] + , moduleName :: String } processRawSource :: RawSource -> Source @@ -64,6 +65,7 @@ processRawSource rawSource = then Module { moduleSourceFileName = sourceFileName , moduleObjectFileName = objectFileName , moduleModulesUsed = modulesUsed + , moduleName = getModuleName parsedContents } else undefined @@ -101,6 +103,13 @@ getModulesUsed = mapMaybe contentToMaybeModuleName ModuleUsed moduleName -> Just moduleName _ -> Nothing +getModuleName :: [LineContents] -> String +getModuleName pc = head $ mapMaybe contentToMaybeModuleName pc + where + contentToMaybeModuleName content = case content of + ModuleDeclaration moduleName -> Just moduleName + _ -> Nothing + readFileLinesIO :: FilePath -> IO [String] readFileLinesIO file = do contents <- readFile file @@ -137,6 +146,7 @@ moduleDeclaration = do _ <- string "module" skipAtLeastOneWhiteSpace moduleName <- validIdentifier + skipSpaceCommentOrEnd return $ ModuleDeclaration moduleName useStatement :: ReadP LineContents @@ -159,11 +169,19 @@ skipSpaceOrEnd = eof <|> skipAtLeastOneWhiteSpace skipSpaceCommaOrEnd :: ReadP () skipSpaceCommaOrEnd = eof <|> skipComma <|> skipAtLeastOneWhiteSpace +skipSpaceCommentOrEnd :: ReadP () +skipSpaceCommentOrEnd = eof <|> skipComment <|> skipAtLeastOneWhiteSpace + skipComma :: ReadP () skipComma = do _ <- char ',' return () +skipComment :: ReadP () +skipComment = do + _ <- char '!' + return () + whiteSpace :: ReadP Char whiteSpace = satisfy (`elem` " \t") diff --git a/bootstrap/unit_test/ModuleSourceConstructionTest.hs b/bootstrap/unit_test/ModuleSourceConstructionTest.hs index 20bc011..26f08b2 100644 --- a/bootstrap/unit_test/ModuleSourceConstructionTest.hs +++ b/bootstrap/unit_test/ModuleSourceConstructionTest.hs @@ -32,6 +32,7 @@ test = return $ givenInput "its object file name is the 'flattened' path of the source file with '.o' appeneded" checkModuleObjectFileName , then' "it knows what modules it uses directly" checkModuleModulesUsed + , then' "it knows its name" checkModuleName ] ] @@ -61,3 +62,7 @@ checkModuleModulesUsed :: Source -> Result checkModuleModulesUsed m@(Module{}) = assertEquals ["module1", "module2"] $ moduleModulesUsed m checkModuleModulesUsed _ = fail' "wasn't a Module" + +checkModuleName :: Source -> Result +checkModuleName m@(Module{}) = assertEquals "some_module" $ moduleName m +checkModuleName _ = fail' "wasn't a Module" |