Skip to content

Commit b23c526

Browse files
authored
Marshal Data.Text.Short.ShortText (#2433)
...so that proto3-suite can use it as a string representation within generated Haskell code while still supporting Dhall marshaling.
1 parent 5d9f0cc commit b23c526

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

dhall/dhall.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ Common common
246246
template-haskell >= 2.13.0.0 && < 2.19,
247247
text >= 0.11.1.0 && < 2.1 ,
248248
text-manipulate >= 0.2.0.1 && < 0.4 ,
249+
text-short >= 0.1 && < 0.2 ,
249250
th-lift-instances >= 0.1.13 && < 0.2 ,
250251
time >= 1.1.4 && < 1.13,
251252
transformers >= 0.5.2.0 && < 0.6 ,

dhall/src/Dhall/Marshal/Decode.hs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ module Dhall.Marshal.Decode
5555
, string
5656
, lazyText
5757
, strictText
58+
, shortText
5859
-- ** Time
5960
, timeOfDay
6061
, day
@@ -176,6 +177,7 @@ import qualified Data.Sequence
176177
import qualified Data.Set
177178
import qualified Data.Text
178179
import qualified Data.Text.Lazy
180+
import qualified Data.Text.Short
179181
import qualified Data.Time as Time
180182
import qualified Data.Vector
181183
import qualified Dhall.Core as Core
@@ -303,6 +305,9 @@ instance FromDhall Double where
303305
instance {-# OVERLAPS #-} FromDhall [Char] where
304306
autoWith _ = string
305307

308+
instance FromDhall Data.Text.Short.ShortText where
309+
autoWith _ = shortText
310+
306311
instance FromDhall Data.Text.Lazy.Text where
307312
autoWith _ = lazyText
308313

@@ -912,6 +917,14 @@ double = Decoder {..}
912917

913918
expected = pure Double
914919

920+
{-| Decode `Data.Text.Short.ShortText`.
921+
922+
>>> input shortText "\"Test\""
923+
"Test"
924+
-}
925+
shortText :: Decoder Data.Text.Short.ShortText
926+
shortText = fmap Data.Text.Short.fromText strictText
927+
915928
{-| Decode lazy `Data.Text.Text`.
916929
917930
>>> input lazyText "\"Test\""

dhall/src/Dhall/Marshal/Encode.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import qualified Data.Sequence
8383
import qualified Data.Set
8484
import qualified Data.Text
8585
import qualified Data.Text.Lazy
86+
import qualified Data.Text.Short
8687
import qualified Data.Time as Time
8788
import qualified Data.Vector
8889
import qualified Data.Void
@@ -166,6 +167,14 @@ instance ToDhall Bool where
166167

167168
declared = Bool
168169

170+
instance ToDhall Data.Text.Short.ShortText where
171+
injectWith _ = Encoder {..}
172+
where
173+
embed text =
174+
TextLit (Chunks [] (Data.Text.Short.toText text))
175+
176+
declared = Text
177+
169178
instance ToDhall Data.Text.Lazy.Text where
170179
injectWith _ = Encoder {..}
171180
where

0 commit comments

Comments
 (0)