diff options
author | Brad Richardson <everythingfunctional@protonmail.com> | 2020-10-15 10:47:40 -0500 |
---|---|---|
committer | Brad Richardson <everythingfunctional@protonmail.com> | 2020-10-15 10:47:40 -0500 |
commit | 311c695aa30f63fc1be0ef8b8c56ca372e01a31e (patch) | |
tree | fb50d1452fccbdad137b53478e8addc8358194e9 /bootstrap/src | |
parent | 134713a6c3620bf5b71ceaa2b6bed3a228d1c297 (diff) | |
download | fpm-311c695aa30f63fc1be0ef8b8c56ca372e01a31e.tar.gz fpm-311c695aa30f63fc1be0ef8b8c56ca372e01a31e.zip |
Add test for a module's name
Diffstat (limited to 'bootstrap/src')
-rw-r--r-- | bootstrap/src/BuildModel.hs | 18 |
1 files changed, 18 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") |