mirror of
https://github.com/joshuaclayton/unused.git
synced 2024-09-11 04:45:28 +03:00
Move parsing response entirely to Parser
This commit is contained in:
parent
d0fcb42535
commit
8f5446a414
@ -9,7 +9,7 @@ main :: IO ()
|
||||
main = do
|
||||
terms <- pure . lines =<< getContents
|
||||
results <- pure . concat =<< mapM search terms
|
||||
let response = responseFromParse $ parseLines $ unlines results
|
||||
let response = parseLines $ unlines results
|
||||
|
||||
case withOneOccurrence $ withOneFile response of
|
||||
Right termMatchSet ->
|
||||
|
@ -3,14 +3,20 @@ module Unused.Parser
|
||||
) where
|
||||
|
||||
import Control.Monad (void)
|
||||
import Data.Map.Strict (fromList)
|
||||
import Text.Parsec.String (Parser)
|
||||
import Data.Bifunctor (second)
|
||||
import Text.Parsec
|
||||
import Unused.Types
|
||||
import Text.Parsec.String (Parser)
|
||||
import qualified Data.Map.Strict as Map
|
||||
import Unused.Util (groupBy)
|
||||
import Unused.Types (TermMatch(..), ParseResponse, resultsFromMatches)
|
||||
|
||||
parseLines :: String -> Either ParseError [TermMatch]
|
||||
parseLines :: String -> ParseResponse
|
||||
parseLines =
|
||||
parse parseTermMatches "matches"
|
||||
responseFromParse . parse parseTermMatches "matches"
|
||||
|
||||
responseFromParse :: Either ParseError [TermMatch] -> ParseResponse
|
||||
responseFromParse =
|
||||
fmap $ Map.fromList . map (second resultsFromMatches) . groupBy term
|
||||
|
||||
parseTermMatches :: Parser [TermMatch]
|
||||
parseTermMatches = do
|
||||
|
@ -2,17 +2,15 @@ module Unused.Types
|
||||
( TermMatch(..)
|
||||
, TermMatchSet
|
||||
, ParseResponse(..)
|
||||
, responseFromParse
|
||||
, listFromMatchSet
|
||||
, withOneFile
|
||||
, withOneOccurrence
|
||||
, resultsFromMatches
|
||||
) where
|
||||
|
||||
import Text.Parsec (ParseError)
|
||||
import Data.Bifunctor (second)
|
||||
import qualified Data.Map.Strict as Map
|
||||
import Data.List (isInfixOf)
|
||||
import Unused.Util (groupBy)
|
||||
|
||||
data TermMatch = TermMatch
|
||||
{ term :: String
|
||||
@ -41,10 +39,6 @@ resultsFromMatches m =
|
||||
totalFiles' = length m
|
||||
totalOccurrences' = sum $ fmap occurrences m
|
||||
|
||||
responseFromParse :: Either ParseError [TermMatch] -> ParseResponse
|
||||
responseFromParse =
|
||||
fmap $ Map.fromList . map (second resultsFromMatches) . groupBy term
|
||||
|
||||
withOneFile :: ParseResponse -> ParseResponse
|
||||
withOneFile = fmap $ Map.filterWithKey (\_ a -> totalFiles a == 1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user