Skip to content

Commit

Permalink
Language selection (#8281)
Browse files Browse the repository at this point in the history
* Remove alphanum check from language prompt

* Remove unneded whitespace

* Add changelog for #8281

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
ffaf1 and mergify[bot] authored Jul 12, 2022
1 parent 680d4fa commit 1fcf56a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cabal-syntax/src/Language/Haskell/Extension.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ instance Pretty Language where
pretty other = Disp.text (show other)

instance Parsec Language where
parsec = classifyLanguage <$> P.munch1 isAlphaNum
parsec = classifyLanguage <$> P.some P.anyChar

classifyLanguage :: String -> Language
classifyLanguage = \str -> case lookup str langTable of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ languagePrompt flags pkgType = getLanguage flags $ do
let h2010 = "Haskell2010"
h98 = "Haskell98"
ghc2021 = "GHC2021 (requires at least GHC 9.2)"

l <- promptList ("Choose a language for your " ++ pkgType)
[h2010, h98, ghc2021]
(DefaultPrompt h2010)
Expand All @@ -427,13 +427,7 @@ languagePrompt flags pkgType = getLanguage flags $ do
| l == h2010 -> return Haskell2010
| l == h98 -> return Haskell98
| l == ghc2021 -> return GHC2021
| all isAlphaNum l -> return $ UnknownLanguage l
| otherwise -> do
putStrLn
$ "\nThe language must be alphanumeric. "
++ "Please enter a different language."

languagePrompt flags pkgType
| otherwise -> return $ UnknownLanguage l

noCommentsPrompt :: Interactive m => InitFlags -> m Bool
noCommentsPrompt flags = getNoComments flags $ do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,10 +919,9 @@ interactiveTests srcDb = testGroup "Check top level getter functions"
, "Haskell2022"
]
, testSimplePrompt "Invalid language"
(`languagePrompt` "test") Haskell2010
(`languagePrompt` "test") (UnknownLanguage "Lang_TS!")
[ "4"
, "Lang_TS!"
, "1"
]
]
, testGroup "Check srcDirsPrompt output"
Expand Down
4 changes: 4 additions & 0 deletions changelog.d/pr-8281
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
synopsis: Relax language selection parsing in `cabal init`
packages: Cabal-syntax
prs: #8281
issues: #8278

0 comments on commit 1fcf56a

Please sign in to comment.