Skip to content

Commit bb132d5

Browse files
committed
implement GPD Barbie
fix build error don't allow other types as modifiers stop using undecidable instances rewrite condtree as barbie rewrite condbranch as barbie fix build add ExactParsec class simple example for dependency make PackageName a barbie fix build pass down modifier to package name barbie update Dependency's ExactParsec instance complete PackageName exactparse proof of concept use exactparsec to define parsec parameterize VersionRange parameterize Version pass down modifier to version barbie remove ExactParsec class Rename Barbie -> With, WithTrivia -> Ann implement VersionRangeAnn Parsec instance define Parsec without ann remodel trivia representation remodel version range fix trailing / leading string implement pretty VersionRangeAnn use VersionRangeAnn in DependencyAnn implement pretty DependencyAnn parameterize BuildInfo parameterize Library parameterize GenericPackageDescription refactor modify rename type variable for consistency Modifiers now have kind type make buildinfo lens polymorphic update codebase to match HasBuildInfo change introduce constraint alias fix compilation run formatter implement Ann variant of HasBuildInfoWith class make buildInfoFieldGrammar generic make optionsFieldGrammar generic make profOptionsfieldGrammar generic make sharedOptionsFieldGrammar generic make profSharedOptionsFieldGrammar generic make hsSourceDirsGrammar generic export GenericPackageDescriptionAnn alias run formatter clean up make library's lens polymorphic make libraryFieldGrammar polymorphic add dependency parsec/pretty instance tests complete dependency roundtrip refactor cabal versioned tests test entirety of cabal dependency specification parameterize newtype combinators fix compile errors make testcases names more descriptive implement trivia-aware commavcat run fourmolu fix warnings implement trivia-aware commafcat implement trivia-aware vcatann run fourmolu implement trivia-aware fsepann implement trivia-aware NoCommaFSepAnn only guard ^>= bound test behind cabal version 2 implement parsec instance of trivia-aware polymorphic list combinator implement pretty instance of trivia-aware list combinator add all tests for combinators fix VCatAnn and FSepAnn leading trivia parsing fix VCatAnn and FSepAnn optional comma fix CommaVCatAnn and CommaFSepAnn trailing correct parsec pretty test names factor out parsecSpaceAnn pattern include position in trivia model refactor cabal-syntax to use DataKinds This makes the modifier closed fix project wide compilation errors create PrettPos as subclass of Pretty add todos Revert "create PrettPos as subclass of Pretty" Retrieve stored position from the Pretty instances and pass them to FieldGrammar. What was tried: - [x] MultiParamTypeClasses Breaking all downstream instances due to instance head change. - [x] TypeFamilies: Impossible to use injectivity because one modifier has more than one `a`. Otherwise requires all sites to define the associated type modifier. - [x] PrettyPos as subclass of Pretty. Use PrettyPos in FieldGrammar. Enforces all field grammar to have position. Not all of them have position. - [ ] Combine MultiParamTypeClasses and PrettyPos subclass: Flexibility: not all field grammar need to have the same output type. No breakage: downstream instance heads aren't changed. We create a new class. make trivia type parameterized In some situations we want to pass around not only the whitespaces trivia, but also Position. This makes it possible to reuse the Trivia type for Position. implement model for position tracking WIP: figure out how to thread position in field grammar implement example of build depends with positions implement pretty version of field grammar make targetBuildDepends field hold position if needed field BuildInfo type family simplify TargetBuildDepends type class mini example of field grammar with position retention checkpoint checkpoint conversion example allow contramapping field grammar and leave some notes attepmt to make position registering also controllable in field grammar attempt to parameterize field gramamr output implement field grammar fully generically Split out Annotate type family move AttachPos type family remove TargetBuildDepends type family rewrite with proxy introduce one more type argument in Field Grammar add a field to attepmt polymorphic monoidalFieldAla output reimplement minibuildinfo with generic monoidalFieldAla' implement monoidalFieldAla' export miniBuildInfoFieldGrammar for a demo implement demo for miniBuildInfoDemo add note demonstrate that NoAnn works implement buildable field in BuildInfo implement buildable split AttachPos into AttachPos and PreserveGrouping implement buildTools remove some redundant type application implement BuildtoolDepends use mod to choose ListWith instance fix buildinfo example add cppOptions field add asmOptions field add cmmOptions field inline newtypes with new helpers test out specialization idea add ccOptions field add cxxOptions field implement jsppOptions add ldOptions field add hsc2hsOptions field add pkgConfigDependency field stuck at frameworks field implement framework field add extraFrameworkDirs field add asmSources field add cmmSources field add cSources field add cxxSources field add jsSources field add hsSourceDirs field make hsSourceDirs polymorphic /and/ backward compatible add other modules field example implementation of printer monoidalFieldAla attach trivia to boolean relax pretty field grammar output type leave some notes insert real position in cabalparsec and parsecparser thread through real offsetted position remodel buildable boolean field annotation - position can never appear when inserted - there is no string annotation (we ignore the casing here because warning means the cabal file is not valid) remove random comment push out fieldname position run fourmolu distinguish AttachPositions and AttachPosition patch pretty for now so it builds and runs most tests fine test displaying mini build info, add note about model add parsec combinator to store position register each element's position in list combinators fix minibuildinfo register each field position for hsSourceDirs make buildinfofieldgrammar' polymorphic again remove unused prototype methods leave notes for newtype ListWith update comments on future direction regarding pretty include ExactDoc module from trivia tree attempt for full roundtrip reimplement prettyfield to exactdoc demonstrate roundtrip in cli add a small cabal file test XXX tree-wide change is necessary to parse with current entrypoint To parse with parseGenericPackageDescription, it is necessary to use buildInfoFieldGrammar. However, it is not yet fully generic. Revert "XXX tree-wide change is necessary to parse with current entrypoint" This reverts commit d3e5d79. update buildinfofieldgrammar' to compile again parse all fields of build info rewire buildinfofieldgrammar polymorphize libraryFieldGrammar checkpoint fully generalize goSection && parseGenericParsecDescription fix test suite compilation run parser against hackage implement smallCabalFile test implement part of ppGenericPackageDescriptionAnn did thing repair boolean field! Implement position preserving optionalfieldAla' implement position preserving optionalfieldala' (printer) preserve cabal-version position make uniqueField polymorphic implement parsec implement pretty use uniqueField in pkgName use uniqueField in pkgVersion filter out zeroPos fields for now render pretty fields with exactdoc retain section position push out section position to pretty field (WIP) float out position in pretty printer float out positions from condtrees inject lens into pretty printer when running add field to Library to store section position add lens for the aforementioned field add method to parser to register section position change printer to use this lens rewire the parser to insert the position properly provide lens in printing functions make lens' focus polymorphic rewrite with Maybe for post section position insertion store section position in condtree library retrieve section position from sub library clean up previous experiments some clean up and prepare smallCabalFile for demo try hackage roundtrip tests remove dead code run fourmolu refactor modules rename modifiers simplify type families add experimental type aliases add type alias for ParsecFieldGrammar add type alias for PrettyFieldGrammar fix ParsecFG compilation errors fix some export/import errors fix test import mark -any as inserted test -any and -none fix hackage tests add backward compatible method stubs for now restore TestSuite parsing and validation restore Benchmark parsing and validation restore specialization pragma use MonoidalFieldAla alias refactor hssourcedirconstraint use monolocalbind fix most compilation warnings clean up constraints refactor constraints run fourmolu restore buildinfofieldgrammar constraints remove redundant constraints remove redundant constraints push out gpd validation, validate only abst syntax remove redundant constraints restore validation restore error message restore mixins version guard update golden test files use compact diff when displaying errors run fourmolu clean up and fix test suite compilation
1 parent 5def3e8 commit bb132d5

165 files changed

Lines changed: 4499 additions & 1243 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cabal-described/src/Distribution/Described.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{-# LANGUAGE FlexibleInstances #-}
2+
{-# LANGUAGE DataKinds #-}
3+
{-# LANGUAGE FlexibleContexts #-}
24
{-# LANGUAGE OverloadedStrings #-}
35
{-# LANGUAGE ScopedTypeVariables #-}
46
module Distribution.Described (
@@ -71,6 +73,7 @@ import Distribution.PackageDescription.FieldGrammar (CompatLicenseFile, CompatDa
7173
import Distribution.FieldGrammar.Newtypes
7274
import Distribution.ModuleName (ModuleName)
7375
import Distribution.System (Arch, OS, knownArches, knownOSs)
76+
import Distribution.Types.Annotation
7477
import Distribution.Types.AbiDependency (AbiDependency)
7578
import Distribution.Types.AbiHash (AbiHash)
7679
import Distribution.Types.BenchmarkType (BenchmarkType)
@@ -546,7 +549,7 @@ instance Described UnqualComponentName where
546549
-- Instances: Newtypes
547550
-------------------------------------------------------------------------------
548551

549-
class Sep sep => DescribeSep sep where
552+
class Sep Abst sep => DescribeSep sep where
550553
describeSep :: Proxy sep -> GrammarRegex a -> GrammarRegex a
551554

552555
instance DescribeSep CommaVCat where describeSep _ = reCommaList

Cabal-syntax/Cabal-syntax.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,14 @@ library
113113
Distribution.PackageDescription.Quirks
114114
Distribution.PackageDescription.Utils
115115
Distribution.Parsec
116+
Distribution.Types.Trivia
116117
Distribution.Parsec.Error
117118
Distribution.Parsec.FieldLineStream
118119
Distribution.Parsec.Position
119120
Distribution.Parsec.Warning
120121
Distribution.Parsec.Source
121122
Distribution.Pretty
123+
Distribution.Pretty.ExactDoc
122124
Distribution.SPDX
123125
Distribution.SPDX.License
124126
Distribution.SPDX.LicenseExceptionId
@@ -135,6 +137,7 @@ library
135137
Distribution.Types.BenchmarkInterface
136138
Distribution.Types.BenchmarkType
137139
Distribution.Types.BuildInfo
140+
Distribution.Types.Annotation
138141
Distribution.Types.BuildInfo.Lens
139142
Distribution.Types.BuildType
140143
Distribution.Types.Component

Cabal-syntax/src/Distribution/Compat/CharParsing.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ module Distribution.Compat.CharParsing
2424
oneOf -- :: CharParsing m => [Char] -> m Char
2525
, noneOf -- :: CharParsing m => [Char] -> m Char
2626
, spaces -- :: CharParsing m => m ()
27+
, spaces' -- :: CharParsing m => m ()
2728
, space -- :: CharParsing m => m Char
2829
, newline -- :: CharParsing m => m Char
2930
, tab -- :: CharParsing m => m Char
@@ -90,6 +91,9 @@ spaces :: CharParsing m => m ()
9091
spaces = skipMany space <?> "white space"
9192
{-# INLINE spaces #-}
9293

94+
spaces' :: CharParsing m => m String
95+
spaces' = many space <?> "white space"
96+
9397
-- | Parses a white space character (any character which satisfies 'isSpace')
9498
-- Returns the parsed character.
9599
space :: CharParsing m => m Char

Cabal-syntax/src/Distribution/Compat/Parsing.hs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
{-# LANGUAGE ApplicativeDo #-}
12
{-# LANGUAGE GADTs #-}
3+
{-# LANGUAGE ScopedTypeVariables #-}
24
{-# LANGUAGE UndecidableInstances #-}
35

46
-----------------------------------------------------------------------------
@@ -27,9 +29,13 @@ module Distribution.Compat.Parsing
2729
, some -- from Control.Applicative, parsec many1
2830
, many -- from Control.Applicative
2931
, sepBy
32+
, sepByAnn
3033
, sepByNonEmpty
34+
, sepByNonEmptyAnn
3135
, sepEndByNonEmpty
36+
, sepEndByNonEmptyAnn
3237
, sepEndBy
38+
, sepEndByAnn
3339
, endByNonEmpty
3440
, endBy
3541
, count
@@ -44,6 +50,7 @@ module Distribution.Compat.Parsing
4450
) where
4551

4652
import Distribution.Compat.Prelude
53+
import Distribution.Types.Trivia
4754
import Prelude ()
4855

4956
import Control.Applicative (optional, (<**>))
@@ -101,18 +108,42 @@ sepBy :: Alternative m => m a -> m sep -> m [a]
101108
sepBy p sep = toList <$> sepByNonEmpty p sep <|> pure []
102109
{-# INLINE sepBy #-}
103110

111+
sepByAnn :: Alternative m => m (Ann SurroundingText a) -> m String -> m [Ann SurroundingText a]
112+
sepByAnn p sep = toList <$> sepByNonEmptyAnn p sep <|> pure []
113+
{-# INLINE sepByAnn #-}
114+
104115
-- | @sepByNonEmpty p sep@ parses /one/ or more occurrences of @p@, separated
105116
-- by @sep@. Returns a non-empty list of values returned by @p@.
106117
sepByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a)
107118
sepByNonEmpty p sep = (:|) <$> p <*> many (sep *> p)
108119
{-# INLINE sepByNonEmpty #-}
109120

121+
sepByNonEmptyAnn :: forall m a. Alternative m => m (Ann SurroundingText a) -> m String -> m (NonEmpty (Ann SurroundingText a))
122+
sepByNonEmptyAnn p sep =
123+
(:|)
124+
<$> p
125+
<*> many
126+
( do
127+
leading <- sep
128+
x <- p
129+
pure (mapAnn (preTrivia leading <>) x)
130+
)
131+
110132
-- | @sepEndByNonEmpty p sep@ parses /one/ or more occurrences of @p@,
111133
-- separated and optionally ended by @sep@. Returns a non-empty list of values
112134
-- returned by @p@.
113135
sepEndByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a)
114136
sepEndByNonEmpty p sep = (:|) <$> p <*> ((sep *> sepEndBy p sep) <|> pure [])
115137

138+
sepEndByNonEmptyAnn :: Alternative m => m (Ann SurroundingText a) -> m String -> m (NonEmpty (Ann SurroundingText a))
139+
sepEndByNonEmptyAnn p sep = do
140+
x <- p
141+
(trailing, xs) <-
142+
( (,) <$> sep <*> sepEndByAnn p sep
143+
)
144+
<|> pure (mempty, [])
145+
pure (mapAnn (<> postTrivia trailing) x :| xs)
146+
116147
-- | @sepEndBy p sep@ parses /zero/ or more occurrences of @p@,
117148
-- separated and optionally ended by @sep@, ie. haskell style
118149
-- statements. Returns a list of values returned by @p@.
@@ -122,6 +153,10 @@ sepEndBy :: Alternative m => m a -> m sep -> m [a]
122153
sepEndBy p sep = toList <$> sepEndByNonEmpty p sep <|> pure []
123154
{-# INLINE sepEndBy #-}
124155

156+
-- | @sepEndByAnn@ is like @sepEndBy@, but it keeps the trivia.
157+
sepEndByAnn :: Alternative m => m (Ann SurroundingText a) -> m String -> m [Ann SurroundingText a]
158+
sepEndByAnn p sep = toList <$> sepEndByNonEmptyAnn p sep <|> pure []
159+
125160
-- | @endByNonEmpty p sep@ parses /one/ or more occurrences of @p@, separated
126161
-- and ended by @sep@. Returns a non-empty list of values returned by @p@.
127162
endByNonEmpty :: Alternative m => m a -> m sep -> m (NonEmpty a)

Cabal-syntax/src/Distribution/Compat/Prelude.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Distribution.Compat.Prelude
1313

1414
--
1515
-- Prelude is re-exported, following is hidden:
16-
module BasePrelude
16+
module BasePrelude
1717

1818
-- * Common type-classes
1919
, Semigroup (..)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Distribution.ExactParsec
2+
( ExactParsec (..)
3+
)
4+
where
5+
6+
import Distribution.Parsec
7+
import Distribution.Types.Trivia

Cabal-syntax/src/Distribution/FieldGrammar.hs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
1+
{-# LANGUAGE DataKinds #-}
12
{-# LANGUAGE FlexibleContexts #-}
23
{-# LANGUAGE FlexibleInstances #-}
4+
{-# LANGUAGE KindSignatures #-}
35
{-# LANGUAGE ScopedTypeVariables #-}
46

57
-- | This module provides a way to specify a grammar of @.cabal@ -like files.
68
module Distribution.FieldGrammar
79
( -- * Field grammar type
8-
FieldGrammar (..)
10+
FieldGrammar
11+
, FieldGrammarWith (..)
912
, uniqueField
13+
, uniqueField'
1014
, optionalField
1115
, optionalFieldDef
1216
, monoidalField
1317

1418
-- * Concrete grammar implementations
1519
, ParsecFieldGrammar
20+
, ParsecFieldGrammarWith
1621
, ParsecFieldGrammar'
22+
, ParsecFieldGrammarWith'
1723
, parseFieldGrammar
1824
, parseFieldGrammarCheckingStanzas
1925
, fieldGrammarKnownFieldList
2026
, PrettyFieldGrammar
27+
, PrettyFieldGrammarWith
2128
, PrettyFieldGrammar'
29+
, PrettyFieldGrammarWith'
2230
, prettyFieldGrammar
2331

2432
-- * Auxiliary
@@ -47,10 +55,14 @@ import Distribution.FieldGrammar.Newtypes
4755
import Distribution.FieldGrammar.Parsec
4856
import Distribution.FieldGrammar.Pretty
4957
import Distribution.Fields.Field
58+
import Distribution.Types.Annotation
5059
import Distribution.Utils.Generic (spanMaybe)
5160

52-
type ParsecFieldGrammar' a = ParsecFieldGrammar a a
53-
type PrettyFieldGrammar' a = PrettyFieldGrammar a a
61+
type ParsecFieldGrammarWith' (mod :: ParsingPhase) a = ParsecFieldGrammarWith mod a a
62+
type PrettyFieldGrammarWith' (mod :: ParsingPhase) a = PrettyFieldGrammarWith mod a a
63+
64+
type ParsecFieldGrammar' a = ParsecFieldGrammarWith Abst a a
65+
type PrettyFieldGrammar' a = PrettyFieldGrammarWith Abst a a
5466

5567
infixl 5 ^^^
5668

0 commit comments

Comments
 (0)