Skip to content

Commit 52cc82d

Browse files
ffaf1mergify[bot]
andauthored
Use munch1 to parse Language (#8508)
* Add regression test for #8507 * Use munch1 to parse Language If you use `some anyChar` trailing whitespace will be part of the parsed value, see #8507. Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent a49c1dd commit 52cc82d

File tree

7 files changed

+36
-1
lines changed

7 files changed

+36
-1
lines changed

Cabal-syntax/src/Language/Haskell/Extension.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ instance Pretty Language where
7777
pretty other = Disp.text (show other)
7878

7979
instance Parsec Language where
80-
parsec = classifyLanguage <$> P.some P.anyChar
80+
parsec = classifyLanguage <$> P.munch1 isAlphaNum
8181

8282
classifyLanguage :: String -> Language
8383
classifyLanguage = \str -> case lookup str langTable of
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Foo where
2+
3+
foo :: a
4+
foo = undefined
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# cabal v2-build
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- pkg-0 (lib) (first run)
6+
Configuring library for pkg-0..
7+
Preprocessing library for pkg-0..
8+
Building library for pkg-0..
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages:
2+
./
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Test.Cabal.Prelude
2+
3+
-- Issue #8507: trailing space in `default-language` should not make
4+
-- `cabal build` complain.
5+
main = cabalTest $ cabal "v2-build" ["all"]
6+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cabal-version: 3.0
2+
name: pkg
3+
synopsis: synopsis
4+
description: description
5+
version: 0
6+
category: example
7+
maintainer: [email protected]
8+
license: GPL-3.0-or-later
9+
10+
library
11+
exposed-modules: Foo,
12+
build-depends: base == 4.*
13+
default-language: Haskell2010
14+
-- Note whitespace after “Haskell 2010”.

fix-whitespace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ excluded-files:
9292
- Cabal-syntax/src/Distribution/Fields/Lexer.hs
9393
- Cabal-tests/tests/ParserTests/warnings/tab.cabal
9494
- Cabal-tests/tests/ParserTests/warnings/utf8.cabal
95+
- cabal-testsuite/PackageTests/Regression/T8507/pkg.cabal
9596

9697
# These also contain tabs that affect the golden value:
9798
# Could be removed from exceptions, but then the tab warning

0 commit comments

Comments
 (0)