-
Notifications
You must be signed in to change notification settings - Fork 711
Make more dependency types #4067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,56 @@ | ||
-- | *Dependency Text instances moved from Distribution.Package | ||
{-# OPTIONS_GHC -fno-warn-orphans #-} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK for now. Let's refactor it away later. |
||
module Distribution.Package.TextClass () where | ||
|
||
import Prelude () | ||
import Distribution.Compat.Prelude | ||
|
||
import Distribution.Package | ||
import Distribution.ParseUtils | ||
import Distribution.Version (anyVersion) | ||
|
||
import qualified Distribution.Compat.ReadP as Parse | ||
import qualified Text.PrettyPrint as Disp | ||
import Distribution.Compat.ReadP | ||
import Distribution.Text | ||
|
||
import Text.PrettyPrint ((<+>)) | ||
|
||
|
||
instance Text Dependency where | ||
disp (Dependency name ver) = | ||
disp name <+> disp ver | ||
|
||
parse = do name <- parse | ||
Parse.skipSpaces | ||
ver <- parse <++ return anyVersion | ||
Parse.skipSpaces | ||
return (Dependency name ver) | ||
|
||
instance Text LegacyExeDependency where | ||
disp (LegacyExeDependency name ver) = | ||
Disp.text name <+> disp ver | ||
|
||
parse = do name <- parseMaybeQuoted parseBuildToolName | ||
Parse.skipSpaces | ||
ver <- parse <++ return anyVersion | ||
Parse.skipSpaces | ||
return $ LegacyExeDependency name ver | ||
where | ||
-- like parsePackageName but accepts symbols in components | ||
parseBuildToolName :: Parse.ReadP r String | ||
parseBuildToolName = do ns <- sepBy1 component (Parse.char '-') | ||
return (intercalate "-" ns) | ||
where component = do | ||
cs <- munch1 (\c -> isAlphaNum c || c == '+' || c == '_') | ||
if all isDigit cs then pfail else return cs | ||
|
||
instance Text PkgconfigDependency where | ||
disp (PkgconfigDependency name ver) = | ||
disp name <+> disp ver | ||
|
||
parse = do name <- parse | ||
Parse.skipSpaces | ||
ver <- parse <++ return anyVersion | ||
Parse.skipSpaces | ||
return $ PkgconfigDependency name ver |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
-- This module is meant to be local-only to Distribution... | ||
|
||
{-# OPTIONS_HADDOCK hide #-} | ||
{-# LANGUAGE Rank2Types #-} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, excellent use of rank 2 types :) |
||
module Distribution.ParseUtils ( | ||
LineNo, PError(..), PWarning(..), locatedErrorMsg, syntaxError, warning, | ||
runP, runE, ParseResult(..), catchParseError, parseFail, showPWarning, | ||
|
@@ -27,14 +28,14 @@ module Distribution.ParseUtils ( | |
showFields, showSingleNamedField, showSimpleSingleNamedField, | ||
parseFields, parseFieldsFlat, | ||
parseFilePathQ, parseTokenQ, parseTokenQ', | ||
parseModuleNameQ, parseBuildTool, parsePkgconfigDependency, | ||
parseModuleNameQ, | ||
parseOptVersion, parsePackageNameQ, | ||
parseTestedWithQ, parseLicenseQ, parseLanguageQ, parseExtensionQ, | ||
parseSepList, parseCommaList, parseOptCommaList, | ||
showFilePath, showToken, showTestedWith, showFreeText, parseFreeText, | ||
field, simpleField, listField, listFieldWithSep, spaceListField, | ||
commaListField, commaListFieldWithSep, commaNewLineListField, | ||
optsField, liftField, boolField, parseQuoted, indentWith, | ||
optsField, liftField, boolField, parseQuoted, parseMaybeQuoted, indentWith, | ||
|
||
UnrecFieldParser, warnUnrec, ignoreUnrec, | ||
) where | ||
|
@@ -611,7 +612,7 @@ ifelse (f:fs) = do fs' <- ifelse fs | |
|
||
-- |parse a module name | ||
parseModuleNameQ :: ReadP r ModuleName | ||
parseModuleNameQ = parseQuoted parse <++ parse | ||
parseModuleNameQ = parseMaybeQuoted parse | ||
|
||
parseFilePathQ :: ReadP r FilePath | ||
parseFilePathQ = parseTokenQ | ||
|
@@ -624,62 +625,35 @@ betweenSpaces act = do skipSpaces | |
skipSpaces | ||
return res | ||
|
||
parseBuildTool :: ReadP r Dependency | ||
parseBuildTool = do name <- parseBuildToolNameQ | ||
ver <- betweenSpaces $ | ||
parse <++ return anyVersion | ||
return $ Dependency name ver | ||
|
||
parseBuildToolNameQ :: ReadP r PackageName | ||
parseBuildToolNameQ = parseQuoted parseBuildToolName <++ parseBuildToolName | ||
|
||
-- like parsePackageName but accepts symbols in components | ||
parseBuildToolName :: ReadP r PackageName | ||
parseBuildToolName = do ns <- sepBy1 component (ReadP.char '-') | ||
return (mkPackageName (intercalate "-" ns)) | ||
where component = do | ||
cs <- munch1 (\c -> isAlphaNum c || c == '+' || c == '_') | ||
if all isDigit cs then pfail else return cs | ||
|
||
-- pkg-config allows versions and other letters in package names, | ||
-- eg "gtk+-2.0" is a valid pkg-config package _name_. | ||
-- It then has a package version number like 2.10.13 | ||
parsePkgconfigDependency :: ReadP r Dependency | ||
parsePkgconfigDependency = do name <- munch1 | ||
(\c -> isAlphaNum c || c `elem` "+-._") | ||
ver <- betweenSpaces $ | ||
parse <++ return anyVersion | ||
return $ Dependency (mkPackageName name) ver | ||
|
||
parsePackageNameQ :: ReadP r PackageName | ||
parsePackageNameQ = parseQuoted parse <++ parse | ||
parsePackageNameQ = parseMaybeQuoted parse | ||
|
||
parseOptVersion :: ReadP r Version | ||
parseOptVersion = parseQuoted ver <++ ver | ||
parseOptVersion = parseMaybeQuoted ver | ||
where ver :: ReadP r Version | ||
ver = parse <++ return nullVersion | ||
|
||
parseTestedWithQ :: ReadP r (CompilerFlavor,VersionRange) | ||
parseTestedWithQ = parseQuoted tw <++ tw | ||
parseTestedWithQ = parseMaybeQuoted tw | ||
where | ||
tw :: ReadP r (CompilerFlavor,VersionRange) | ||
tw = do compiler <- parseCompilerFlavorCompat | ||
version <- betweenSpaces $ parse <++ return anyVersion | ||
return (compiler,version) | ||
|
||
parseLicenseQ :: ReadP r License | ||
parseLicenseQ = parseQuoted parse <++ parse | ||
parseLicenseQ = parseMaybeQuoted parse | ||
|
||
-- urgh, we can't define optQuotes :: ReadP r a -> ReadP r a | ||
-- because the "compat" version of ReadP isn't quite powerful enough. In | ||
-- particular, the type of <++ is ReadP r r -> ReadP r a -> ReadP r a | ||
-- Hence the trick above to make 'lic' polymorphic. | ||
|
||
parseLanguageQ :: ReadP r Language | ||
parseLanguageQ = parseQuoted parse <++ parse | ||
parseLanguageQ = parseMaybeQuoted parse | ||
|
||
parseExtensionQ :: ReadP r Extension | ||
parseExtensionQ = parseQuoted parse <++ parse | ||
parseExtensionQ = parseMaybeQuoted parse | ||
|
||
parseHaskellString :: ReadP r String | ||
parseHaskellString = readS_to_P reads | ||
|
@@ -711,5 +685,8 @@ parseOptCommaList = parseSepList (optional (ReadP.char ',')) | |
parseQuoted :: ReadP r a -> ReadP r a | ||
parseQuoted = between (ReadP.char '"') (ReadP.char '"') | ||
|
||
parseMaybeQuoted :: (forall r. ReadP r a) -> ReadP r' a | ||
parseMaybeQuoted p = parseQuoted p <++ p | ||
|
||
parseFreeText :: ReadP.ReadP s String | ||
parseFreeText = ReadP.munch (const True) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is "legacy" because we do not know if the build-tool referred to, refers to a pkg-config executable, or an internal executable (thus it is stringly typed.)