From b39bed0669b0ce85fee32f27837fee0d396ab547 Mon Sep 17 00:00:00 2001 From: Harendra Kumar Date: Wed, 17 Jan 2024 00:14:34 +0530 Subject: [PATCH] Refactor the "str" code --- core/src/Streamly/Internal/Unicode/String.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/src/Streamly/Internal/Unicode/String.hs b/core/src/Streamly/Internal/Unicode/String.hs index 5cadc22b8..2a6b18ccf 100644 --- a/core/src/Streamly/Internal/Unicode/String.hs +++ b/core/src/Streamly/Internal/Unicode/String.hs @@ -39,14 +39,14 @@ module Streamly.Internal.Unicode.String -- -- $setup - str + str ) where import Control.Applicative (Alternative(..)) import Control.Exception (displayException) import Data.Functor.Identity (runIdentity) -import Streamly.Internal.Data.Parser (Parser) +import Streamly.Internal.Data.Parser (Parser, ParseError) import Language.Haskell.TH import Language.Haskell.TH.Quote @@ -106,9 +106,12 @@ strSegmentExp (StrVar name) = do strExp :: [StrSegment] -> Q Exp strExp xs = appE [| concat |] $ listE $ map strSegmentExp xs +parseStr :: String -> Either ParseError [StrSegment] +parseStr = runIdentity . Stream.parse strParser . Stream.fromList + expandVars :: String -> Q Exp -expandVars ln = - case runIdentity $ Stream.parse strParser (Stream.fromList ln) of +expandVars input = + case parseStr input of Left e -> fail $ "str QuasiQuoter parse error: " ++ displayException e Right x ->