on master help sign in
Refactor the "str" code
b39bed0Harendra Kumar
core/src/Streamly/Internal/Unicode/String.hs+7−4
@@ -39,14 +39,14 @@ module Streamly.Internal.Unicode.String
39 --
39 --
40 -- $setup
40 -- $setup
41
41
42− str
42+ str
43 ) where
43 ) where
44
44
45
45
46import Control.Applicative (Alternative(..))
46import Control.Applicative (Alternative(..))
47import Control.Exception (displayException)
47import Control.Exception (displayException)
48import Data.Functor.Identity (runIdentity)
48import Data.Functor.Identity (runIdentity)
49−import Streamly.Internal.Data.Parser (Parser)
49+import Streamly.Internal.Data.Parser (Parser, ParseError)
50
50
51import Language.Haskell.TH
51import Language.Haskell.TH
52import Language.Haskell.TH.Quote
52import Language.Haskell.TH.Quote
@@ -106,9 +106,12 @@ strSegmentExp (StrVar name) = do
106strExp :: [StrSegment] -> Q Exp
106strExp :: [StrSegment] -> Q Exp
107strExp xs = appE [| concat |] $ listE $ map strSegmentExp xs
107strExp xs = appE [| concat |] $ listE $ map strSegmentExp xs
108
108
109+parseStr :: String -> Either ParseError [StrSegment]
110+parseStr = runIdentity . Stream.parse strParser . Stream.fromList
111+
109expandVars :: String -> Q Exp
112expandVars :: String -> Q Exp
110−expandVars ln =
113+expandVars input =
111− case runIdentity $ Stream.parse strParser (Stream.fromList ln) of
114+ case parseStr input of
112 Left e ->
115 Left e ->
113 fail $ "str QuasiQuoter parse error: " ++ displayException e
116 fail $ "str QuasiQuoter parse error: " ++ displayException e
114 Right x ->
117 Right x ->