Skip to content

Commit 243771c

Browse files
committed
Undo annotations
1 parent ca02c8e commit 243771c

File tree

5 files changed

+43
-111
lines changed

5 files changed

+43
-111
lines changed

optparse-applicative.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ library
8787
, Options.Applicative.Common
8888
, Options.Applicative.Extra
8989
, Options.Applicative.Help
90-
, Options.Applicative.Help.Ann
9190
, Options.Applicative.Help.Chunk
9291
, Options.Applicative.Help.Core
9392
, Options.Applicative.Help.Levenshtein

src/Options/Applicative/Help/Ann.hs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Options/Applicative/Help/Chunk.hs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,13 @@ import Data.Maybe
2424
import Data.Semigroup
2525
import Prelude
2626

27-
import Options.Applicative.Help.Ann
2827
import Options.Applicative.Help.Pretty
2928

3029
-- | The free monoid on a semigroup 'a'.
3130
newtype Chunk a = Chunk
3231
{ unChunk :: Maybe a }
3332
deriving (Eq, Show)
3433

35-
instance CanAnnotate (Chunk Doc) where
36-
annTrace n = fmap . annTrace n
37-
3834
instance Functor Chunk where
3935
fmap f = Chunk . fmap f . unChunk
4036

@@ -97,20 +93,20 @@ extractChunk = fromMaybe mempty . unChunk
9793
-- Unlike '<+>' for 'Doc', this operation has a unit element, namely the empty
9894
-- 'Chunk'.
9995
(<<+>>) :: Chunk Doc -> Chunk Doc -> Chunk Doc
100-
(<<+>>) = fmap (annTrace 1 "(<<+>>)") . chunked (<+>)
96+
(<<+>>) = chunked (<+>)
10197

10298
-- | Concatenate two 'Chunk's with a softline in between. This is exactly like
10399
-- '<<+>>', but uses a softline instead of a space.
104100
(<</>>) :: Chunk Doc -> Chunk Doc -> Chunk Doc
105-
(<</>>) = fmap (annTrace 1 "(<</>>)") . chunked (</>)
101+
(<</>>) = chunked (</>)
106102

107103
-- | Concatenate 'Chunk's vertically.
108104
vcatChunks :: [Chunk Doc] -> Chunk Doc
109-
vcatChunks = fmap (annTrace 1 "vcatChunks") . foldr (chunked (.$.)) mempty
105+
vcatChunks = foldr (chunked (.$.)) mempty
110106

111107
-- | Concatenate 'Chunk's vertically separated by empty lines.
112108
vsepChunks :: [Chunk Doc] -> Chunk Doc
113-
vsepChunks = annTrace 1 "vsepChunks" . foldr (chunked (\x y -> x .$. mempty .$. y)) mempty
109+
vsepChunks = foldr (chunked (\x y -> x .$. mempty .$. y)) mempty
114110

115111
-- | Whether a 'Chunk' is empty. Note that something like 'pure mempty' is not
116112
-- considered an empty chunk, even though the underlying 'Doc' is empty.
@@ -122,8 +118,8 @@ isEmpty = isNothing . unChunk
122118
-- > isEmpty . stringChunk = null
123119
-- > extractChunk . stringChunk = string
124120
stringChunk :: String -> Chunk Doc
125-
stringChunk "" = annTrace 0 "stringChunk" mempty
126-
stringChunk s = annTrace 0 "stringChunk" $ pure (string s)
121+
stringChunk "" = mempty
122+
stringChunk s = pure (string s)
127123

128124
-- | Convert a paragraph into a 'Chunk'. The resulting chunk is composed by the
129125
-- words of the original paragraph separated by softlines, so it will be
@@ -133,14 +129,12 @@ stringChunk s = annTrace 0 "stringChunk" $ pure (string s)
133129
--
134130
-- > isEmpty . paragraph = null . words
135131
paragraph :: String -> Chunk Doc
136-
paragraph = annTrace 0 "paragraph"
137-
. foldr (chunked (</>) . stringChunk) mempty
138-
. words
132+
paragraph = foldr (chunked (</>) . stringChunk) mempty . words
139133

140134
-- | Display pairs of strings in a table.
141135
tabulate :: Int -> [(Doc, Doc)] -> Chunk Doc
142-
tabulate _ [] = annTrace 1 "tabulate" mempty
143-
tabulate size table = annTrace 1 "tabulate" . pure $ vcat
136+
tabulate _ [] = mempty
137+
tabulate size table = pure $ vcat
144138
[ indent 2 (fillBreak size key <+> value)
145139
| (key, value) <- table ]
146140

src/Options/Applicative/Help/Core.hs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import Prelude hiding (any)
3636

3737
import Options.Applicative.Common
3838
import Options.Applicative.Types
39-
import Options.Applicative.Help.Ann
4039
import Options.Applicative.Help.Chunk
4140
import Options.Applicative.Help.Pretty
4241

@@ -57,7 +56,7 @@ safelast = foldl' (const Just) Nothing
5756

5857
-- | Generate description for a single option.
5958
optDesc :: ParserPrefs -> OptDescStyle -> ArgumentReachability -> Option a -> (Chunk Doc, Parenthetic)
60-
optDesc pprefs style _reachability opt = first (annTrace 2 "optDesc") $
59+
optDesc pprefs style _reachability opt =
6160
let names =
6261
sort . optionNames . optMain $ opt
6362
meta =
@@ -96,7 +95,7 @@ optDesc pprefs style _reachability opt = first (annTrace 2 "optDesc") $
9695

9796
-- | Generate descriptions for commands.
9897
cmdDesc :: ParserPrefs -> Parser a -> [(Maybe String, Chunk Doc)]
99-
cmdDesc pprefs = fmap (fmap (annTrace 2 "cmdDesc")) <$> mapParser desc
98+
cmdDesc pprefs = mapParser desc
10099
where
101100
desc _ opt =
102101
case optMain opt of
@@ -111,18 +110,18 @@ cmdDesc pprefs = fmap (fmap (annTrace 2 "cmdDesc")) <$> mapParser desc
111110

112111
-- | Generate a brief help text for a parser.
113112
briefDesc :: ParserPrefs -> Parser a -> Chunk Doc
114-
briefDesc = fmap (annTrace 2 "briefDesc") . briefDesc' True
113+
briefDesc = briefDesc' True
115114

116115
-- | Generate a brief help text for a parser, only including mandatory
117116
-- options and arguments.
118117
missingDesc :: ParserPrefs -> Parser a -> Chunk Doc
119-
missingDesc = fmap (annTrace 2 "missingDesc") . briefDesc' False
118+
missingDesc = briefDesc' False
120119

121120
-- | Generate a brief help text for a parser, allowing the specification
122121
-- of if optional arguments are show.
123122
briefDesc' :: Bool -> ParserPrefs -> Parser a -> Chunk Doc
124-
briefDesc' showOptional pprefs = fmap (annTrace 2 "briefDesc'")
125-
. wrapOver NoDefault MaybeRequired
123+
briefDesc' showOptional pprefs =
124+
wrapOver NoDefault MaybeRequired
126125
. foldTree pprefs style
127126
. mfilterOptional
128127
. treeMapParser (optDesc pprefs style)
@@ -142,18 +141,17 @@ briefDesc' showOptional pprefs = fmap (annTrace 2 "briefDesc'")
142141
wrapOver :: AltNodeType -> Parenthetic -> (Chunk Doc, Parenthetic) -> Chunk Doc
143142
wrapOver altnode mustWrapBeyond (chunk, wrapping)
144143
| chunkIsEffectivelyEmpty chunk =
145-
annTrace 3 "wrapOver0" <$> chunk
144+
chunk
146145
| altnode == MarkDefault =
147-
annTrace 3 "wrapOver1" <$> fmap brackets chunk
146+
fmap brackets chunk
148147
| wrapping > mustWrapBeyond =
149-
annTrace 3 "wrapOver2" <$> fmap parens chunk
150-
| otherwise =
151-
annTrace 3 "wrapOver3" chunk
148+
fmap parens chunk
149+
| otherwise = chunk
152150

153151
-- Fold a tree of option docs into a single doc with fully marked
154152
-- optional areas and groups.
155153
foldTree :: ParserPrefs -> OptDescStyle -> OptTree (Chunk Doc, Parenthetic) -> (Chunk Doc, Parenthetic)
156-
foldTree _ _ (Leaf x) = first (annTrace 3 "foldTree1")
154+
foldTree _ _ (Leaf x) =
157155
x
158156
foldTree prefs s (MultNode xs) =
159157
( let generous :: Chunk Doc
@@ -179,7 +177,7 @@ foldTree prefs s (MultNode xs) =
179177
leads :: [Chunk Doc]
180178
leads = fmap pure (pretty " ":repeat (line <> pretty " "))
181179

182-
foldTree prefs s (AltNode b xs) = first (annTrace 3 "foldTree2") $
180+
foldTree prefs s (AltNode b xs) =
183181
(\x -> (x, NeverRequired))
184182
. fmap groupOrNestLine
185183
. wrapOver b MaybeRequired
@@ -211,7 +209,7 @@ foldTree prefs s (AltNode b xs) = first (annTrace 3 "foldTree2") $
211209
leads :: [Chunk Doc]
212210
leads = fmap pure (pretty " ":repeat (line <> pretty "| "))
213211

214-
foldTree prefs s (BindNode x) = first (annTrace 3 "foldTree3") $
212+
foldTree prefs s (BindNode x) =
215213
let rendered =
216214
wrapOver NoDefault NeverRequired (foldTree prefs s x)
217215

@@ -223,21 +221,17 @@ foldTree prefs s (BindNode x) = first (annTrace 3 "foldTree3") $
223221

224222
-- | Generate a full help text for a parser
225223
fullDesc :: ParserPrefs -> Parser a -> Chunk Doc
226-
fullDesc = fmap (annTrace 2 "fullDesc") <$> optionsDesc False
224+
fullDesc = optionsDesc False
227225

228226
-- | Generate a help text for the parser, showing
229227
-- only what is relevant in the "Global options: section"
230228
globalDesc :: ParserPrefs -> Parser a -> Chunk Doc
231-
globalDesc = fmap (annTrace 2 "globalDesc") <$> optionsDesc True
229+
globalDesc = optionsDesc True
232230

233231
-- | Common generator for full descriptions and globals
234232
optionsDesc :: Bool -> ParserPrefs -> Parser a -> Chunk Doc
235-
optionsDesc global pprefs = fmap (annTrace 2 "optionsDesc")
236-
. tabulate (prefTabulateFill pprefs)
237-
. catMaybes
238-
. mapParser doc
233+
optionsDesc global pprefs = tabulate (prefTabulateFill pprefs) . catMaybes . mapParser doc
239234
where
240-
doc :: MonadPlus m => ArgumentReachability -> Option a -> m (Doc, Doc)
241235
doc info opt = do
242236
guard . not . isEmpty $ n
243237
guard . not . isEmpty $ h
@@ -292,7 +286,7 @@ parserHelp pprefs p =
292286
vcatChunks (snd <$> a)
293287
group_title _ = mempty
294288

295-
with_title title = annTrace 1 "with_title" . fmap (string title .$.)
289+
with_title title = fmap (string title .$.)
296290

297291

298292
parserGlobals :: ParserPrefs -> Parser a -> ParserHelp
@@ -305,7 +299,7 @@ parserGlobals pprefs p =
305299

306300
-- | Generate option summary.
307301
parserUsage :: ParserPrefs -> Parser a -> String -> Doc
308-
parserUsage pprefs p progn = annTrace 2 "parserUsage" $
302+
parserUsage pprefs p progn =
309303
case prefUsageOverflow pprefs of
310304
UsageOverflowAlign ->
311305
hsep

src/Options/Applicative/Help/Pretty.hs

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,8 @@ module Options.Applicative.Help.Pretty
55
, (.$.)
66
, groupOrNestLine
77
, altSep
8-
, Ann(..)
98
, Doc
109

11-
, enclose
12-
, parens
13-
, brackets
14-
, hang
15-
, indent
16-
, nest
17-
1810
-- TODO Remove these
1911
-- , (<$>)
2012
, (</>)
@@ -32,23 +24,22 @@ import Control.Applicative
3224
import Data.Semigroup ((<>))
3325
#endif
3426

35-
import Options.Applicative.Help.Ann
36-
import Prettyprinter hiding ((<>), Doc, enclose, parens, brackets, hang, indent, nest)
27+
import Prettyprinter hiding ((<>), Doc)
3728
import qualified Prettyprinter as PP
3829
import qualified Prettyprinter.Internal as PPI
3930
import Prettyprinter.Render.String (renderShowS)
4031

4132
import Prelude
4233

43-
type Doc = PPI.Doc Ann
34+
type Doc = PPI.Doc ()
4435

4536
(.$.) :: Doc -> Doc -> Doc
46-
(.$.) x y = annTrace 1 "(.$.)" (x <> line <> y)
37+
(.$.) x y = x <> line <> y
4738

4839
-- | Apply the function if we're not at the
4940
-- start of our nesting level.
5041
ifNotAtRoot :: (Doc -> Doc) -> Doc -> Doc
51-
ifNotAtRoot f doc = annTrace 1 "ifNotAtRoot" $
42+
ifNotAtRoot f doc =
5243
PPI.Nesting $ \i ->
5344
PPI.Column $ \j ->
5445
if i == j
@@ -62,10 +53,10 @@ ifNotAtRoot f doc = annTrace 1 "ifNotAtRoot" $
6253
-- This will also nest subsequent lines in the
6354
-- group.
6455
groupOrNestLine :: Doc -> Doc
65-
groupOrNestLine d = annTrace 1 "groupOrNestLine" $
66-
(PPI.Union
56+
groupOrNestLine =
57+
PPI.Union
6758
<$> flatten
68-
<*> ifNotAtRoot (line <>)) d
59+
<*> ifNotAtRoot (line <>)
6960
where flatten :: Doc -> Doc
7061
flatten doc = case doc of
7162
PPI.FlatAlt _ y -> flatten y
@@ -94,59 +85,35 @@ groupOrNestLine d = annTrace 1 "groupOrNestLine" $
9485
-- but it's possible for y to still appear on the
9586
-- next line.
9687
altSep :: Doc -> Doc -> Doc
97-
altSep x y = annTrace 1 "altSep" $
88+
altSep x y =
9889
group (x <+> pretty "|" <> line) <> softline' <> y
9990

100-
101-
-- (<$>) :: Doc -> Doc -> Doc
102-
-- (<$>) = \x y -> x <> line <> y
103-
10491
(</>) :: Doc -> Doc -> Doc
105-
(</>) x y = annTrace 1 "(</>)" $ x <> softline <> y
92+
(</>) x y = x <> softline <> y
10693

10794
(<$$>) :: Doc -> Doc -> Doc
108-
(<$$>) x y = annTrace 1 "(<$$>)" $x <> linebreak <> y
95+
(<$$>) x y = x <> linebreak <> y
10996

11097
(<//>) :: Doc -> Doc -> Doc
111-
(<//>) x y = annTrace 1 "(<//>)" $ x <> softbreak <> y
98+
(<//>) x y = x <> softbreak <> y
11299

113100
linebreak :: Doc
114-
linebreak = annTrace 0 "linebreak" $ flatAlt line mempty
101+
linebreak = flatAlt line mempty
115102

116103
softbreak :: Doc
117-
softbreak = annTrace 0 "softbreak" $ group linebreak
104+
softbreak = group linebreak
118105

119106
-- | Traced version of 'PP.string'.
120107
string :: String -> Doc
121-
string = annTrace 0 "string" . PP.pretty
108+
string = PP.pretty
122109

123110
-- | Traced version of 'PP.parens'.
124111
parens :: Doc -> Doc
125-
parens = annTrace 1 "parens" . PP.parens
112+
parens = PP.parens
126113

127114
-- | Traced version of 'PP.brackets'.
128115
brackets :: Doc -> Doc
129-
brackets = annTrace 1 "brackets" . PP.brackets
130-
131-
-- | Traced version of 'PP.enclose'.
132-
enclose
133-
:: Doc -- ^ L
134-
-> Doc -- ^ R
135-
-> Doc -- ^ x
136-
-> Doc -- ^ LxR
137-
enclose l r x = annTrace 1 "enclose" (PP.enclose l r x)
138-
139-
-- | Traced version of 'PP.hang'.
140-
hang :: Int -> Doc -> Doc
141-
hang n = annTrace 1 "hang" . PP.hang n
142-
143-
-- | Traced version of 'PP.nest'.
144-
nest :: Int -> Doc -> Doc
145-
nest n = annTrace 1 "nest" . PP.nest n
146-
147-
-- | Traced version of 'PP.indent'.
148-
indent :: Int -> Doc -> Doc
149-
indent n = annTrace 1 "indent" . PP.indent n
116+
brackets = PP.brackets
150117

151118
-- | Determine if the document is empty when rendered
152119
isEffectivelyEmpty :: Doc -> Bool

0 commit comments

Comments
 (0)