Commit 3a07215f authored by ijones's avatar ijones
Browse files

cvs patches from Ross. mostly parser work

** add a newline to the end of the installed package description
** When pretty-printing free-format text fields, align the lines vertically
  (so that following lines will be seen as continuations) and replace empty
  lines with "." (so they'll be correctly re-parsed, instead of looking
  like a stanza separator).
parent 872227c2
......@@ -58,7 +58,8 @@ import Distribution.ParseUtils (
StanzaField(..), singleStanza, PError(..),
simpleField, listField, licenseField,
parseFilePathQ, parseLibNameQ, parseModuleNameQ, parsePackageNameQ,
showFilePath, parseReadS, parseOptVersion, parseQuoted)
showFilePath, parseReadS, parseOptVersion, parseQuoted,
showFreeText)
import Distribution.License ( License(..) )
import Distribution.Extension ( Opt )
import Distribution.Package ( PackageIdentifier(..), showPackageId,
......@@ -191,28 +192,28 @@ basicStanzaFields =
, licenseField "license-file" True
license (\l pkg -> pkg{license=l})
, simpleField "copyright"
text (munch (const True))
showFreeText (munch (const True))
copyright (\val pkg -> pkg{copyright=val})
, simpleField "maintainer"
text (munch (const True))
showFreeText (munch (const True))
maintainer (\val pkg -> pkg{maintainer=val})
, simpleField "stability"
text (munch (const True))
showFreeText (munch (const True))
stability (\val pkg -> pkg{stability=val})
, simpleField "homepage"
text (munch (const True))
showFreeText (munch (const True))
homepage (\val pkg -> pkg{homepage=val})
, simpleField "package-url"
text (munch (const True))
showFreeText (munch (const True))
pkgUrl (\val pkg -> pkg{pkgUrl=val})
, simpleField "description"
text (munch (const True))
showFreeText (munch (const True))
description (\val pkg -> pkg{description=val})
, simpleField "category"
text (munch (const True))
showFreeText (munch (const True))
category (\val pkg -> pkg{category=val})
, simpleField "author"
text (munch (const True))
showFreeText (munch (const True))
author (\val pkg -> pkg{author=val})
]
......
......@@ -246,7 +246,6 @@ setupMessage :: String -> PackageDescription -> IO ()
setupMessage msg pkg_descr =
putStrLn (msg ++ ' ':showPackageId (package pkg_descr) ++ "...")
-- ------------------------------------------------------------
-- * Parsing & Pretty printing
-- ------------------------------------------------------------
......@@ -264,28 +263,28 @@ basicStanzaFields =
, licenseField "license-file" True
license (\l pkg -> pkg{license=l})
, simpleField "copyright"
text (munch (const True))
showFreeText (munch (const True))
copyright (\val pkg -> pkg{copyright=val})
, simpleField "maintainer"
text (munch (const True))
showFreeText (munch (const True))
maintainer (\val pkg -> pkg{maintainer=val})
, simpleField "stability"
text (munch (const True))
showFreeText (munch (const True))
stability (\val pkg -> pkg{stability=val})
, simpleField "homepage"
text (munch (const True))
showFreeText (munch (const True))
homepage (\val pkg -> pkg{homepage=val})
, simpleField "package-url"
text (munch (const True))
showFreeText (munch (const True))
pkgUrl (\val pkg -> pkg{pkgUrl=val})
, simpleField "description"
text (munch (const True))
showFreeText (munch (const True))
description (\val pkg -> pkg{description=val})
, simpleField "category"
text (munch (const True))
showFreeText (munch (const True))
category (\val pkg -> pkg{category=val})
, simpleField "author"
text (munch (const True))
showFreeText (munch (const True))
author (\val pkg -> pkg{author=val})
, listField "tested-with"
showTestedWith parseTestedWithQ
......@@ -308,7 +307,7 @@ basicStanzaFields =
executableStanzaFields :: [StanzaField Executable]
executableStanzaFields =
[ simpleField "executable"
text (munch (const True))
showFreeText (munch (const True))
exeName (\xs exe -> exe{exeName=xs})
, simpleField "main-is"
showFilePath parseFilePathQ
......@@ -369,7 +368,7 @@ readPackageDescription fpath = do
str <- readFile fpath
case parseDescription str of
Left e -> error (showError e) -- FIXME
Right PackageDescription{library=Nothing, executables=[]} -> error "no library listed, and no executable stanza."
-- Right PackageDescription{library=Nothing, executables=[]} -> error "no library listed, and no executable stanza."
Right x -> return x
parseDescription :: String -> Either PError PackageDescription
......
......@@ -50,7 +50,7 @@ module Distribution.ParseUtils (
parseModuleNameQ, parseDependency, parseOptVersion,
parsePackageNameQ, parseVersionRangeQ,
parseTestedWithQ, parseLicenseQ, parseExtensionQ, parseCommaList,
showFilePath, showTestedWith, showDependency,
showFilePath, showTestedWith, showDependency, showFreeText,
simpleField, listField, licenseField, optsField,
parseReadS, parseQuoted,
) where
......@@ -280,3 +280,8 @@ showTestedWith (compiler,version) = text (show compiler ++ " " ++ showVersionRan
showDependency :: Dependency -> Doc
showDependency (Dependency name ver) = text name <+> text (showVersionRange ver)
-- | Pretty-print free-format text, ensuring that it is vertically aligned,
-- and with blank lines replaced by dots for correct re-parsing.
showFreeText :: String -> Doc
showFreeText s = vcat [text (if null l then "." else l) | l <- lines s]
......@@ -147,7 +147,7 @@ writeInstalledConfig pkg_descr lbi = do
GHC | compilerVersion hc < Version [6,3] [] ->
showGHCPackageConfig (mkGHCPackageConfig pkg_descr lbi)
_ -> showInstalledPackageInfo (mkInstalledPackageInfo pkg_descr lbi)
writeFile installedPkgConfigFile pkg_config
writeFile installedPkgConfigFile (pkg_config ++ "\n")
removeInstalledConfig :: IO ()
removeInstalledConfig = try (removeFile installedPkgConfigFile) >> return ()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment