Skip to content

Commit

Permalink
Handle licences starting with a digit
Browse files Browse the repository at this point in the history
cabal has a devscript that parses a json file (containing SPDX licences)
and returns a number of of Haskell data constructors.

There have been problems when the SPDX short identifier starts with
a digit (e.g. “0BSD”), as that would generate an data constructor
starting with a digit, which is not valid Haskell.
The way to handle such occourrences was in an ad-hoc basis.

This patch prepends “N_” to the beginning of every SPDX licence starting
with a digit, future-proofing the script.
  • Loading branch information
ffaf1 committed Sep 14, 2024
1 parent efa04f7 commit bfe5e0a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cabal-dev-scripts/src/GenUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Data.Text (Text)
import GHC.Generics (Generic)

import qualified Data.Algorithm.Diff as Diff
import qualified Data.Char as C
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.Text as T
Expand Down Expand Up @@ -160,9 +161,10 @@ toConstructorName t = t
f c = c

special :: Text -> Text
special "0BSD" = "NullBSD"
special "389_exception" = "DS389_exception"
special u = u
special u
| Just (c, _) <- T.uncons u
, C.isDigit c = "N_" <> u
special u = u

mkList :: [Text] -> Text
mkList [] = " []"
Expand Down
11 changes: 11 additions & 0 deletions changelog.d/pr-10356
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
synopsis: New licence constructors for SPDX licences starting with a digit
packages: Cabal-syntax
prs: #10356

description: {

- LicenseId constructor `NullBSD` is now `N_0BSD`.
- LicenseId constructor `DS389_exception` is now and `N_389_exception`.
- LicenseId constructor `X3D_Slicer_1_0` is now and `N_3D_Slicer_1_0`.

}

0 comments on commit bfe5e0a

Please sign in to comment.