Skip to content

Commit 231862a

Browse files
committed
Fixed some Hoogle DB parsing errors due to changes in DB format
1 parent 5b2041b commit 231862a

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Main.hs

+10-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import Data.Char
2626
import qualified Data.Text as T
2727
import qualified Data.Text.IO as TI
2828
import Data.Attoparsec.Text hiding (try)
29+
import Data.Attoparsec.Combinator (lookAhead)
2930
import Text.Printf
3031
import Distribution.PackageDescription
3132
import Distribution.PackageDescription.Parse
@@ -237,6 +238,8 @@ computeDiffDownloadHoogleDB ComputeParams { .. } = do
237238
putS "Parsing Hoogle DBs..."
238239
[parsedDBA, parsedDBB] <- forM [dbA, dbB] $ \db ->
239240
either throwError return $ parseOnly (hoogleDBParser <* endOfInput) db
241+
-- Debug parser in GHCi: parseOnly hoogleDBParser <$> TI.readFile "base.txt" >>=
242+
-- \(Right db) -> mapM_ (putStrLn . show) db
240243
-- Compare
241244
putS "Comparing Hoogle DBs..."
242245
return $ diffHoogleDB parsedDBA parsedDBB
@@ -495,10 +498,14 @@ hoogleDBParser = many parseLine
495498
( (DBNewtype <$> takeTill (`elem` [ ' ', '\n' ]) <* endOfLine <*> "") <|>
496499
(DBNewtype <$> takeTill (== ' ') <* skipSpace <*> tillEoL)
497500
)
498-
parseCtor = do peekChar' >>= flip unless (fail "lowercase") . isAsciiUpper
501+
-- TODO: At some point Hoogle DBs started to have Ctors and functions
502+
-- names wrapped in brackets. Not sure what's up with that, just
503+
-- parse them as part of the name so the parser doesn't stop
504+
parseCtor = do void . lookAhead $ satisfy isAsciiUpper <|>
505+
(char '[' *> satisfy isAsciiUpper)
499506
DBCtor <$> takeTill (== ' ') <* string " :: " <*> tillEoL
500-
parseFunction = do peekChar' >>=
501-
flip unless (fail "uppercase") . (\c -> isAsciiLower c || c == '(')
507+
-- TODO: This doesn't parse function lists correctly
508+
parseFunction = do void . lookAhead $ satisfy isAsciiLower <|> char '[' <|> char '('
502509
DBFunction <$> takeTill (== ' ') <* string " :: " <*> tillEoL
503510
parseInstance = do void $ string "instance "
504511
line <- T.words <$> tillEoL

0 commit comments

Comments
 (0)