Skip to content

Commit 85aa1c9

Browse files
committed
Add pattern SString
1 parent d155e79 commit 85aa1c9

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

.hlint.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,6 @@
6060
name: Avoid return
6161
lhs: return
6262
rhs: pure
63+
64+
# hlint fails to account for ViewPatterns usage inside PatternSynonyms
65+
- ignore: {name: Unused LANGUAGE pragma, within: Prettyprinter.Internal}

aux/version-compatibility-macros.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@
2020

2121
#define FAIL_IN_MONAD !(MIN_VERSION_base(4,13,0))
2222

23+
#define BIDI_PATTERN_SYNONYMS MIN_VERSION_base(4,8,0)
24+
#define PATTERN_SYNONYM_SIGNATURES MIN_VERSION_base(4,9,0)
25+
#define COMPLETE_PRAGMA MIN_VERSION_base(4,10,0)
26+
2327
#endif

prettyprinter/src/Prettyprinter/Internal.hs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010

1111
#include "version-compatibility-macros.h"
1212

13+
#if BIDI_PATTERN_SYNONYMS
14+
{-# LANGUAGE PatternSynonyms #-}
15+
{-# LANGUAGE ViewPatterns #-}
16+
#if PATTERN_SYNONYM_SIGNATURES
17+
{-# OPTIONS_GHC -fno-warn-missing-pattern-synonym-signatures #-}
18+
#endif
19+
#endif
20+
1321
-- | __Warning: internal module!__ This means that the API may change
1422
-- arbitrarily between versions without notice. Depending on this module may
1523
-- lead to unexpected breakages, so proceed with caution!
@@ -68,6 +76,9 @@ module Prettyprinter.Internal (
6876

6977
-- * Layout
7078
SimpleDocStream(..),
79+
#if BIDI_PATTERN_SYNONYMS
80+
pattern SString,
81+
#endif
7182
PageWidth(..), defaultPageWidth,
7283
LayoutOptions(..), defaultLayoutOptions,
7384
layoutPretty, layoutCompact, layoutSmart,
@@ -1596,6 +1607,23 @@ data SimpleDocStream ann =
15961607
| SAnnPop (SimpleDocStream ann)
15971608
deriving (Eq, Ord, Show, Generic, Typeable)
15981609

1610+
#if BIDI_PATTERN_SYNONYMS
1611+
1612+
#ifdef MIN_VERSION_text
1613+
-- | 'length' is /O(n)/, so we cache it in the 'Int' field.
1614+
pattern SString a b c <- SText a (T.unpack -> b) c where
1615+
SString a b c = SText a (T.pack b) c
1616+
#else
1617+
-- | 'length' is /O(n)/, so we cache it in the 'Int' field.
1618+
pattern SString a b c = SText a b c
1619+
#endif
1620+
1621+
#if COMPLETE_PRAGMA
1622+
{-# COMPLETE SFail, SEmpty, SChar, SString, SLine, SAnnPush, SAnnPop #-}
1623+
#endif
1624+
1625+
#endif
1626+
15991627
-- | Remove all trailing space characters.
16001628
--
16011629
-- This has some performance impact, because it does an entire additional pass

0 commit comments

Comments
 (0)