-
Notifications
You must be signed in to change notification settings - Fork 726
Versioned grammars + leading comma support for build-depends #4953
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| {-# LANGUAGE FlexibleContexts, RankNTypes #-} | ||
| module Distribution.CabalSpecVersion where | ||
|
|
||
| import Distribution.Parsec.Class (Parsec (..), ParsecParser) | ||
|
|
||
| -- A class to select how to parse different fields. | ||
| class CabalSpecVersion v where | ||
| -- | @v@ can act as own proxy | ||
| cabalSpecVersion :: v | ||
|
|
||
| -- | Parsec parser according to the spec version | ||
| specParsec :: Parsec a => v -> ParsecParser a | ||
|
|
||
| -- given a version, whether this spec knows about it's fields | ||
| specKnows :: v -> [Int] -> Bool | ||
|
|
||
| specHasElif :: v -> HasElif | ||
| specHasCommonStanzas :: v -> HasCommonStanzas | ||
|
|
||
| data CabalSpecOld = CabalSpecOld | ||
| data CabalSpecV20 = CabalSpecV20 | ||
| data CabalSpecV22 = CabalSpecV22 | ||
|
|
||
| instance CabalSpecVersion CabalSpecOld where | ||
| cabalSpecVersion = CabalSpecOld | ||
| specParsec _ = parsec | ||
| specKnows _ vs = vs < [1,25] | ||
| specHasElif _ = NoElif | ||
| specHasCommonStanzas _ = NoCommonStanzas | ||
|
|
||
| instance CabalSpecVersion CabalSpecV20 where | ||
| cabalSpecVersion = CabalSpecV20 | ||
| specParsec _ = parsec | ||
| specKnows _ vs = vs < [2,1] | ||
| specHasElif _ = NoElif | ||
| specHasCommonStanzas _ = NoCommonStanzas | ||
|
|
||
| instance CabalSpecVersion CabalSpecV22 where | ||
| cabalSpecVersion = CabalSpecV22 | ||
| specParsec _ = parsec22 | ||
| specKnows _ _ = True | ||
| specHasElif _ = HasElif | ||
| specHasCommonStanzas _ = HasCommonStanzas | ||
|
|
||
| type CabalSpecLatest = CabalSpecV22 | ||
|
|
||
| ------------------------------------------------------------------------------- | ||
| -- "Booleans" | ||
| ------------------------------------------------------------------------------- | ||
|
|
||
| data HasElif = HasElif | NoElif | ||
|
Member
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. Alternatively, we could just do something like to make it more consistent with
Collaborator
Author
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. Yes, have to think how to deal with expanding feature set. But not now. (maybe in follow-up PR)
Collaborator
Author
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. One way is to encode |
||
| deriving (Eq, Show) | ||
|
|
||
| data HasCommonStanzas = HasCommonStanzas | NoCommonStanzas | ||
| deriving (Eq, Show) | ||
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.
Looks like it should be easy to convert this type class to a GADT? Then we could have
etc.
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.
If you really need
data CabalSpecOld = CabalSpecOld / ..., you can make that a phantom type parameter.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.
hmm, GADT is not a bad idea. I however abuse implicit dictionary passing, so I'd need a class for that anyway... :)