mirror of
https://github.com/github/semantic.git
synced 2024-12-27 17:05:33 +03:00
Reduce duplication for hlint
This commit is contained in:
parent
7eb207dace
commit
267de9d896
@ -188,7 +188,23 @@ instance Exception ParserCancelled
|
|||||||
|
|
||||||
-- | Parse a 'Blob' in 'IO'.
|
-- | Parse a 'Blob' in 'IO'.
|
||||||
runParser :: (Member (Exc SomeException) effs, Member IO effs, Member (Reader Config) effs, Member Telemetry effs, Member Trace effs) => Blob -> Parser term -> Eff effs term
|
runParser :: (Member (Exc SomeException) effs, Member IO effs, Member (Reader Config) effs, Member Telemetry effs, Member Trace effs) => Blob -> Parser term -> Eff effs term
|
||||||
runParser blob@Blob{..} parser = case parser of
|
runParser blob@Blob{..} parser =
|
||||||
|
let
|
||||||
|
parseFailureHandler (SomeException err) = do
|
||||||
|
writeStat (increment "parse.parse_failures" languageTag)
|
||||||
|
writeLog Error "failed parsing" (("task", "parse") : blobFields)
|
||||||
|
throwError (toException err)
|
||||||
|
writeErrorStats errors = for_ errors $ \ err -> case Error.errorActual err of
|
||||||
|
Just "ParseError" -> do
|
||||||
|
writeStat (increment "parse.parse_errors" languageTag)
|
||||||
|
logError config Warning blob err (("task", "parse") : blobFields)
|
||||||
|
_ -> do
|
||||||
|
writeStat (increment "parse.assign_warnings" languageTag)
|
||||||
|
logError config Warning blob err (("task", "assign") : blobFields)
|
||||||
|
when (optionsFailOnWarning (configOptions config)) $ throwError (toException err)
|
||||||
|
|
||||||
|
in
|
||||||
|
case parser of
|
||||||
ASTParser language ->
|
ASTParser language ->
|
||||||
time "parse.tree_sitter_ast_parse" languageTag $ do
|
time "parse.tree_sitter_ast_parse" languageTag $ do
|
||||||
config <- ask
|
config <- ask
|
||||||
@ -196,10 +212,7 @@ runParser blob@Blob{..} parser = case parser of
|
|||||||
>>= maybeM (throwError (SomeException ParserTimedOut))
|
>>= maybeM (throwError (SomeException ParserTimedOut))
|
||||||
|
|
||||||
AssignmentParser parser assignment -> do
|
AssignmentParser parser assignment -> do
|
||||||
ast <- runParser blob parser `catchError` \ (SomeException err) -> do
|
ast <- runParser blob parser `catchError` parseFailureHandler
|
||||||
writeStat (increment "parse.parse_failures" languageTag)
|
|
||||||
writeLog Error "failed parsing" (("task", "parse") : blobFields)
|
|
||||||
throwError (toException err)
|
|
||||||
config <- ask
|
config <- ask
|
||||||
time "parse.assign" languageTag $
|
time "parse.assign" languageTag $
|
||||||
case Assignment.assign blobSource assignment ast of
|
case Assignment.assign blobSource assignment ast of
|
||||||
@ -208,22 +221,12 @@ runParser blob@Blob{..} parser = case parser of
|
|||||||
logError config Error blob err (("task", "assign") : blobFields)
|
logError config Error blob err (("task", "assign") : blobFields)
|
||||||
throwError (toException err)
|
throwError (toException err)
|
||||||
Right term -> do
|
Right term -> do
|
||||||
for_ (errors term) $ \ err -> case Error.errorActual err of
|
writeErrorStats term
|
||||||
Just "ParseError" -> do
|
|
||||||
writeStat (increment "parse.parse_errors" languageTag)
|
|
||||||
logError config Warning blob err (("task", "parse") : blobFields)
|
|
||||||
_ -> do
|
|
||||||
writeStat (increment "parse.assign_warnings" languageTag)
|
|
||||||
logError config Warning blob err (("task", "assign") : blobFields)
|
|
||||||
when (optionsFailOnWarning (configOptions config)) $ throwError (toException err)
|
|
||||||
writeStat (count "parse.nodes" (length term) languageTag)
|
writeStat (count "parse.nodes" (length term) languageTag)
|
||||||
pure term
|
pure term
|
||||||
|
|
||||||
DeterministicParser parser assignment -> do
|
DeterministicParser parser assignment -> do
|
||||||
ast <- runParser blob parser `catchError` \ (SomeException err) -> do
|
ast <- runParser blob parser `catchError` parseFailureHandler
|
||||||
writeStat (increment "parse.parse_failures" languageTag)
|
|
||||||
writeLog Error "failed parsing" (("task", "parse") : blobFields)
|
|
||||||
throwError (toException err)
|
|
||||||
config <- ask
|
config <- ask
|
||||||
time "parse.assign_deterministic" languageTag $
|
time "parse.assign_deterministic" languageTag $
|
||||||
case Deterministic.runAssignment (Deterministic.runTermAssignment assignment) blobSource (Deterministic.State 0 lowerBound [ast]) of
|
case Deterministic.runAssignment (Deterministic.runTermAssignment assignment) blobSource (Deterministic.State 0 lowerBound [ast]) of
|
||||||
@ -232,14 +235,7 @@ runParser blob@Blob{..} parser = case parser of
|
|||||||
logError config Error blob (either id show <$> err) (("task", "assign") : blobFields)
|
logError config Error blob (either id show <$> err) (("task", "assign") : blobFields)
|
||||||
throwError (toException (either id show <$> err))
|
throwError (toException (either id show <$> err))
|
||||||
Right (_, term) -> do
|
Right (_, term) -> do
|
||||||
for_ (errors term) $ \ err -> case Error.errorActual err of
|
writeErrorStats (errors term)
|
||||||
Just "ParseError" -> do
|
|
||||||
writeStat (increment "parse.parse_errors" languageTag)
|
|
||||||
logError config Warning blob err (("task", "parse") : blobFields)
|
|
||||||
_ -> do
|
|
||||||
writeStat (increment "parse.assign_warnings" languageTag)
|
|
||||||
logError config Warning blob err (("task", "assign") : blobFields)
|
|
||||||
when (optionsFailOnWarning (configOptions config)) $ throwError (toException err)
|
|
||||||
writeStat (count "parse.nodes" (length term) languageTag)
|
writeStat (count "parse.nodes" (length term) languageTag)
|
||||||
pure term
|
pure term
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user