on master help sign in
Change blockWithQuotes API
9662569Harendra Kumar
core/src/Streamly/Internal/Data/Parser/ParserD.hs+8−8
@@ -1802,19 +1802,19 @@ data BlockParseState s =
1802-- not overlap. Block start and end brackets must be different for nesting
1802-- not overlap. Block start and end brackets must be different for nesting
1803-- blocks within blocks.
1803-- blocks within blocks.
1804--
1804--
1805−-- >>> p = Parser.blockWithQuotes '{' '}' '"' '\\' Fold.toList
1805+-- >>> p = Parser.blockWithQuotes (== '\\') (== '"') '{' '}' Fold.toList
1806-- >>> Stream.parse p $ Stream.fromList "{msg: \"hello world\"}"
1806-- >>> Stream.parse p $ Stream.fromList "{msg: \"hello world\"}"
1807-- Right "msg: \"hello world\""
1807-- Right "msg: \"hello world\""
1808--
1808--
1809{-# INLINE blockWithQuotes #-}
1809{-# INLINE blockWithQuotes #-}
1810blockWithQuotes :: (Monad m, Eq a) =>
1810blockWithQuotes :: (Monad m, Eq a) =>
1811+ (a -> Bool) -- ^ escape char
1812+ -> (a -> Bool) -- ^ quote char, to quote inside brackets
1811− a -- ^ Block opening bracket
1813+ -> a -- ^ Block opening bracket
1812 -> a -- ^ Block closing bracket
1814 -> a -- ^ Block closing bracket
1813− -> a -- ^ quote char
1814− -> a -- ^ escape char
1815 -> Fold m a b
1815 -> Fold m a b
1816 -> Parser a m b
1816 -> Parser a m b
1817−blockWithQuotes bopen bclose quote esc
1817+blockWithQuotes isEsc isQuote bopen bclose
1818 (Fold fstep finitial fextract) =
1818 (Fold fstep finitial fextract) =
1819 Parser step initial extract
1819 Parser step initial extract
1820
1820
@@ -1851,13 +1851,13 @@ blockWithQuotes bopen bclose quote esc
1851 then fmap (Done 0) (fextract s)
1851 then fmap (Done 0) (fextract s)
1852 else process s a (BlockUnquoted (level - 1))
1852 else process s a (BlockUnquoted (level - 1))
1853 else
1853 else
1854− if a == quote
1854+ if isQuote a
1855 then process s a (BlockQuoted level)
1855 then process s a (BlockQuoted level)
1856 else process s a (BlockUnquoted level)
1856 else process s a (BlockUnquoted level)
1857 step (BlockQuoted level s) a
1857 step (BlockQuoted level s) a
1858− | a == esc = process s a (BlockQuotedEsc level)
1858+ | isEsc a = process s a (BlockQuotedEsc level)
1859 | otherwise =
1859 | otherwise =
1860− if a == quote
1860+ if isQuote a
1861 then process s a (BlockUnquoted level)
1861 then process s a (BlockUnquoted level)
1862 else process s a (BlockQuoted level)
1862 else process s a (BlockQuoted level)
1863 step (BlockQuotedEsc level s) a = process s a (BlockQuoted level)
1863 step (BlockQuotedEsc level s) a = process s a (BlockQuoted level)