diff --git a/src/Dhall.hs b/src/Dhall.hs index cb345ce..d47140f 100644 --- a/src/Dhall.hs +++ b/src/Dhall.hs @@ -325,6 +325,7 @@ import Prelude hiding (maybe) import qualified Control.Exception import qualified Data.Map import qualified Data.Text.Lazy +import qualified Data.Text.Lazy.Builder import qualified Data.Vector import qualified Dhall.Core import qualified Dhall.Import @@ -448,7 +449,7 @@ double = Type {..} text :: Type Text text = Type {..} where - extract (TextLit t) = pure t + extract (TextLit t) = pure (Data.Text.Lazy.Builder.toLazyText t) extract _ = empty expected = Text diff --git a/src/Dhall/Core.hs b/src/Dhall/Core.hs index 248588a..487d4a8 100644 --- a/src/Dhall/Core.hs +++ b/src/Dhall/Core.hs @@ -225,7 +225,7 @@ data Expr a -- | > Text ~ Text | Text -- | > TextLit t ~ t - | TextLit Text + | TextLit Builder -- | > TextAppend x y ~ x <> y | TextAppend (Expr a) (Expr a) -- | > TextConcat ~ Text/concat @@ -1954,7 +1954,7 @@ normalize e = case e of App TextConcat (ListLit _ xs) | Data.Vector.all isText xs -> case traverse extract xs of - Just ys -> normalize (TextLit (Text.concat (toList ys))) + Just ys -> normalize (TextLit (mconcat (toList ys))) _ -> error "normalize: Malformed `Text/concat`" where isText (TextLit _) = True diff --git a/src/Dhall/Lexer.x b/src/Dhall/Lexer.x index 9094f8d..3a1da85 100644 --- a/src/Dhall/Lexer.x +++ b/src/Dhall/Lexer.x @@ -22,6 +22,7 @@ import Data.ByteString.Lazy (ByteString) import Data.Monoid ((<>)) import Data.Text.Buildable (Buildable(..)) import Data.Text.Lazy (Text) +import Data.Text.Lazy.Builder (Builder) import Filesystem.Path (FilePath) import Numeric.Natural (Natural) import Prelude hiding (FilePath) @@ -33,6 +34,7 @@ import qualified Data.Text import qualified Data.Text.Buildable import qualified Data.Text.Lazy import qualified Data.Text.Lazy.Encoding +import qualified Data.Text.Lazy.Builder import qualified Filesystem.Path.CurrentOS import qualified NeatInterpolation } @@ -165,8 +167,11 @@ toText :: ByteString -> Text toText = Data.Text.Lazy.Encoding.decodeUtf8 -- TODO: Properly handle errors here -str :: ByteString -> Text -str = read . Data.Text.Lazy.unpack . Data.Text.Lazy.Encoding.decodeUtf8 +str :: ByteString -> Builder +str = Data.Text.Lazy.Builder.fromLazyText + . read + . Data.Text.Lazy.unpack + . Data.Text.Lazy.Encoding.decodeUtf8 -- | `Alex` action for reading the next token lexer :: (Token -> Alex a) -> Alex a @@ -275,7 +280,7 @@ data Token | ListConcat | Maybe | MaybeFold - | TextLit Text + | TextLit Builder | TextConcat | Absurd | Label Text