mirror of
https://github.com/composewell/streamly.git
synced 2024-09-19 15:37:48 +03:00
Refactor the "str" code
This commit is contained in:
parent
207f948d22
commit
b39bed0669
@ -39,14 +39,14 @@ module Streamly.Internal.Unicode.String
|
|||||||
--
|
--
|
||||||
-- $setup
|
-- $setup
|
||||||
|
|
||||||
str
|
str
|
||||||
) where
|
) where
|
||||||
|
|
||||||
|
|
||||||
import Control.Applicative (Alternative(..))
|
import Control.Applicative (Alternative(..))
|
||||||
import Control.Exception (displayException)
|
import Control.Exception (displayException)
|
||||||
import Data.Functor.Identity (runIdentity)
|
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
|
||||||
import Language.Haskell.TH.Quote
|
import Language.Haskell.TH.Quote
|
||||||
@ -106,9 +106,12 @@ strSegmentExp (StrVar name) = do
|
|||||||
strExp :: [StrSegment] -> Q Exp
|
strExp :: [StrSegment] -> Q Exp
|
||||||
strExp xs = appE [| concat |] $ listE $ map strSegmentExp xs
|
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 :: String -> Q Exp
|
||||||
expandVars ln =
|
expandVars input =
|
||||||
case runIdentity $ Stream.parse strParser (Stream.fromList ln) of
|
case parseStr input of
|
||||||
Left e ->
|
Left e ->
|
||||||
fail $ "str QuasiQuoter parse error: " ++ displayException e
|
fail $ "str QuasiQuoter parse error: " ++ displayException e
|
||||||
Right x ->
|
Right x ->
|
||||||
|
Loading…
Reference in New Issue
Block a user