Skip to content

Commit 7b01614

Browse files
committed
Undo annotations
1 parent ca02c8e commit 7b01614

File tree

5 files changed

+44
-102
lines changed

5 files changed

+44
-102
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: 19 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)
@@ -141,19 +140,15 @@ briefDesc' showOptional pprefs = fmap (annTrace 2 "briefDesc'")
141140
-- | Wrap a doc in parentheses or brackets if required.
142141
wrapOver :: AltNodeType -> Parenthetic -> (Chunk Doc, Parenthetic) -> Chunk Doc
143142
wrapOver altnode mustWrapBeyond (chunk, wrapping)
144-
| chunkIsEffectivelyEmpty chunk =
145-
annTrace 3 "wrapOver0" <$> chunk
146-
| altnode == MarkDefault =
147-
annTrace 3 "wrapOver1" <$> fmap brackets chunk
148-
| wrapping > mustWrapBeyond =
149-
annTrace 3 "wrapOver2" <$> fmap parens chunk
150-
| otherwise =
151-
annTrace 3 "wrapOver3" chunk
143+
| chunkIsEffectivelyEmpty chunk = chunk
144+
| altnode == MarkDefault = fmap brackets chunk
145+
| wrapping > mustWrapBeyond = fmap parens chunk
146+
| otherwise = chunk
152147

153148
-- Fold a tree of option docs into a single doc with fully marked
154149
-- optional areas and groups.
155150
foldTree :: ParserPrefs -> OptDescStyle -> OptTree (Chunk Doc, Parenthetic) -> (Chunk Doc, Parenthetic)
156-
foldTree _ _ (Leaf x) = first (annTrace 3 "foldTree1")
151+
foldTree _ _ (Leaf x) =
157152
x
158153
foldTree prefs s (MultNode xs) =
159154
( let generous :: Chunk Doc
@@ -179,7 +174,7 @@ foldTree prefs s (MultNode xs) =
179174
leads :: [Chunk Doc]
180175
leads = fmap pure (pretty " ":repeat (line <> pretty " "))
181176

182-
foldTree prefs s (AltNode b xs) = first (annTrace 3 "foldTree2") $
177+
foldTree prefs s (AltNode b xs) =
183178
(\x -> (x, NeverRequired))
184179
. fmap groupOrNestLine
185180
. wrapOver b MaybeRequired
@@ -211,7 +206,7 @@ foldTree prefs s (AltNode b xs) = first (annTrace 3 "foldTree2") $
211206
leads :: [Chunk Doc]
212207
leads = fmap pure (pretty " ":repeat (line <> pretty "| "))
213208

214-
foldTree prefs s (BindNode x) = first (annTrace 3 "foldTree3") $
209+
foldTree prefs s (BindNode x) =
215210
let rendered =
216211
wrapOver NoDefault NeverRequired (foldTree prefs s x)
217212

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

224219
-- | Generate a full help text for a parser
225220
fullDesc :: ParserPrefs -> Parser a -> Chunk Doc
226-
fullDesc = fmap (annTrace 2 "fullDesc") <$> optionsDesc False
221+
fullDesc = optionsDesc False
227222

228223
-- | Generate a help text for the parser, showing
229224
-- only what is relevant in the "Global options: section"
230225
globalDesc :: ParserPrefs -> Parser a -> Chunk Doc
231-
globalDesc = fmap (annTrace 2 "globalDesc") <$> optionsDesc True
226+
globalDesc = optionsDesc True
232227

233228
-- | Common generator for full descriptions and globals
234229
optionsDesc :: Bool -> ParserPrefs -> Parser a -> Chunk Doc
235-
optionsDesc global pprefs = fmap (annTrace 2 "optionsDesc")
236-
. tabulate (prefTabulateFill pprefs)
230+
optionsDesc global pprefs =
231+
tabulate (prefTabulateFill pprefs)
237232
. catMaybes
238233
. mapParser doc
239234
where
@@ -292,7 +287,7 @@ parserHelp pprefs p =
292287
vcatChunks (snd <$> a)
293288
group_title _ = mempty
294289

295-
with_title title = annTrace 1 "with_title" . fmap (string title .$.)
290+
with_title title = fmap (string title .$.)
296291

297292

298293
parserGlobals :: ParserPrefs -> Parser a -> ParserHelp
@@ -305,7 +300,7 @@ parserGlobals pprefs p =
305300

306301
-- | Generate option summary.
307302
parserUsage :: ParserPrefs -> Parser a -> String -> Doc
308-
parserUsage pprefs p progn = annTrace 2 "parserUsage" $
303+
parserUsage pprefs p progn =
309304
case prefUsageOverflow pprefs of
310305
UsageOverflowAlign ->
311306
hsep

src/Options/Applicative/Help/Pretty.hs

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

1110
, enclose
12-
, parens
13-
, brackets
1411
, hang
1512
, indent
1613
, nest
@@ -32,23 +29,22 @@ import Control.Applicative
3229
import Data.Semigroup ((<>))
3330
#endif
3431

35-
import Options.Applicative.Help.Ann
36-
import Prettyprinter hiding ((<>), Doc, enclose, parens, brackets, hang, indent, nest)
32+
import Prettyprinter hiding ((<>), Doc)
3733
import qualified Prettyprinter as PP
3834
import qualified Prettyprinter.Internal as PPI
3935
import Prettyprinter.Render.String (renderShowS)
4036

4137
import Prelude
4238

43-
type Doc = PPI.Doc Ann
39+
type Doc = PPI.Doc ()
4440

4541
(.$.) :: Doc -> Doc -> Doc
46-
(.$.) x y = annTrace 1 "(.$.)" (x <> line <> y)
42+
(.$.) x y = x <> line <> y
4743

4844
-- | Apply the function if we're not at the
4945
-- start of our nesting level.
5046
ifNotAtRoot :: (Doc -> Doc) -> Doc -> Doc
51-
ifNotAtRoot f doc = annTrace 1 "ifNotAtRoot" $
47+
ifNotAtRoot f doc =
5248
PPI.Nesting $ \i ->
5349
PPI.Column $ \j ->
5450
if i == j
@@ -62,10 +58,10 @@ ifNotAtRoot f doc = annTrace 1 "ifNotAtRoot" $
6258
-- This will also nest subsequent lines in the
6359
-- group.
6460
groupOrNestLine :: Doc -> Doc
65-
groupOrNestLine d = annTrace 1 "groupOrNestLine" $
66-
(PPI.Union
61+
groupOrNestLine =
62+
PPI.Union
6763
<$> flatten
68-
<*> ifNotAtRoot (line <>)) d
64+
<*> ifNotAtRoot (line <>)
6965
where flatten :: Doc -> Doc
7066
flatten doc = case doc of
7167
PPI.FlatAlt _ y -> flatten y
@@ -94,59 +90,39 @@ groupOrNestLine d = annTrace 1 "groupOrNestLine" $
9490
-- but it's possible for y to still appear on the
9591
-- next line.
9692
altSep :: Doc -> Doc -> Doc
97-
altSep x y = annTrace 1 "altSep" $
93+
altSep x y =
9894
group (x <+> pretty "|" <> line) <> softline' <> y
9995

10096

10197
-- (<$>) :: Doc -> Doc -> Doc
10298
-- (<$>) = \x y -> x <> line <> y
10399

104100
(</>) :: Doc -> Doc -> Doc
105-
(</>) x y = annTrace 1 "(</>)" $ x <> softline <> y
101+
(</>) x y = x <> softline <> y
106102

107103
(<$$>) :: Doc -> Doc -> Doc
108-
(<$$>) x y = annTrace 1 "(<$$>)" $x <> linebreak <> y
104+
(<$$>) x y = x <> linebreak <> y
109105

110106
(<//>) :: Doc -> Doc -> Doc
111-
(<//>) x y = annTrace 1 "(<//>)" $ x <> softbreak <> y
107+
(<//>) x y = x <> softbreak <> y
112108

113109
linebreak :: Doc
114-
linebreak = annTrace 0 "linebreak" $ flatAlt line mempty
110+
linebreak = flatAlt line mempty
115111

116112
softbreak :: Doc
117-
softbreak = annTrace 0 "softbreak" $ group linebreak
113+
softbreak = group linebreak
118114

119115
-- | Traced version of 'PP.string'.
120116
string :: String -> Doc
121-
string = annTrace 0 "string" . PP.pretty
117+
string = PP.pretty
122118

123119
-- | Traced version of 'PP.parens'.
124120
parens :: Doc -> Doc
125-
parens = annTrace 1 "parens" . PP.parens
121+
parens = PP.parens
126122

127123
-- | Traced version of 'PP.brackets'.
128124
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
125+
brackets = PP.brackets
150126

151127
-- | Determine if the document is empty when rendered
152128
isEffectivelyEmpty :: Doc -> Bool

0 commit comments

Comments
 (0)