-
Notifications
You must be signed in to change notification settings - Fork 702
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10644 from cabalism/fix/import-parse-error-location
Add source file to project parse errors and warnings
- Loading branch information
Showing
26 changed files
with
727 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
cabal-install/src/Distribution/Deprecated/ProjectParseUtils.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{-# OPTIONS_HADDOCK hide #-} | ||
|
||
module Distribution.Deprecated.ProjectParseUtils | ||
( ProjectParseError (..) | ||
, ProjectParseWarning | ||
, ProjectParseResult (..) | ||
, projectParseFail | ||
, projectParse | ||
) where | ||
|
||
import Distribution.Client.Compat.Prelude hiding (get) | ||
import Prelude () | ||
|
||
import qualified Distribution.Deprecated.ParseUtils as Pkg (PError, PWarning, ParseResult (..)) | ||
import Distribution.Solver.Types.ProjectConfigPath (ProjectConfigPath) | ||
|
||
type ProjectParseWarning = (ProjectConfigPath, Pkg.PWarning) | ||
|
||
data ProjectParseError = ProjectParseError | ||
{ projectParseSnippet :: Maybe String | ||
, projectParseSource :: Maybe ProjectConfigPath | ||
, projectParseError :: Pkg.PError | ||
} | ||
deriving (Show) | ||
|
||
data ProjectParseResult a | ||
= ProjectParseFailed ProjectParseError | ||
| ProjectParseOk [ProjectParseWarning] a | ||
deriving (Show) | ||
|
||
projectParse :: Maybe String -> ProjectConfigPath -> Pkg.ParseResult a -> ProjectParseResult a | ||
projectParse s path (Pkg.ParseFailed err) = ProjectParseFailed $ ProjectParseError s (Just path) err | ||
projectParse _ path (Pkg.ParseOk ws x) = ProjectParseOk [(path, w) | w <- ws] x | ||
|
||
instance Functor ProjectParseResult where | ||
fmap _ (ProjectParseFailed err) = ProjectParseFailed err | ||
fmap f (ProjectParseOk ws x) = ProjectParseOk ws $ f x | ||
|
||
instance Applicative ProjectParseResult where | ||
pure = ProjectParseOk [] | ||
(<*>) = ap | ||
|
||
instance Monad ProjectParseResult where | ||
return = pure | ||
ProjectParseFailed err >>= _ = ProjectParseFailed err | ||
ProjectParseOk ws x >>= f = case f x of | ||
ProjectParseFailed err -> ProjectParseFailed err | ||
ProjectParseOk ws' x' -> ProjectParseOk (ws' ++ ws) x' | ||
|
||
projectParseFail :: Maybe String -> Maybe ProjectConfigPath -> Pkg.PError -> ProjectParseResult a | ||
projectParseFail s p e = ProjectParseFailed $ ProjectParseError s p e |
Oops, something went wrong.