Skip to content

Commit

Permalink
mid work
Browse files Browse the repository at this point in the history
  • Loading branch information
adithyaov committed Oct 4, 2024
1 parent 89ea37c commit a6299c2
Showing 1 changed file with 14 additions and 32 deletions.
46 changes: 14 additions & 32 deletions core/src/Streamly/Internal/Data/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1714,13 +1714,14 @@ data WordQuotedState s b a =
{-# INLINE wordWithQuotes #-}
wordWithQuotes :: (Monad m, Eq a) =>
Bool -- ^ Retain the quotes and escape chars in the output
-> (a -> Maybe a -> Maybe a) -- ^ quote char -> escaped char -> translated char
-> (a -> a -> Maybe a) -- ^ quote char -> escaped char -> translated char
-> (a -> Either String (Maybe a)) -- ^ ending quote char -> translated char or err
-> a -- ^ Matches an escape elem?
-> (a -> Maybe a) -- ^ If left quote, return right quote, else Nothing.
-> (a -> Bool) -- ^ Matches a word separator?
-> Fold m a b
-> Parser a m b
wordWithQuotes keepQuotes tr escChar toRight isSep
wordWithQuotes keepQuotes tr trEnd escChar toRight isSep
(Fold fstep finitial _ ffinal) =
Parser step initial extract

Expand Down Expand Up @@ -1805,7 +1806,7 @@ wordWithQuotes keepQuotes tr escChar toRight isSep
else processQuoted s a n ql qr
step (WordUnquotedEsc s) a = processUnquoted s a
step (WordQuotedEsc s n ql qr) a =
case tr ql (Just a) of
case tr ql a of
Nothing -> do
res <- fstep s escChar
case res of
Expand All @@ -1826,10 +1827,11 @@ wordWithQuotes keepQuotes tr escChar toRight isSep
if n == 0
then fmap (Done 0) $ ffinal s
else err "wordWithQuotes: missing frame end"
extract (WordQuotedEsc s 0 ql _) =
case tr ql Nothing of
Nothing -> fmap (Done 0) $ ffinal s
Just x -> do
extract (WordQuotedEsc s _ ql _) =
case trEnd ql of
Left errTxt -> err errTxt
(Right Nothing) -> fmap (Done 0) $ ffinal s
(Right (Just x)) -> do
res <- fstep s x
case res of
FL.Partial s1 -> fmap (Done 0) $ ffinal s1
Expand All @@ -1855,18 +1857,10 @@ wordKeepQuotes :: (Monad m, Eq a) =>
-> Parser a m b
wordKeepQuotes =
-- Escape the quote char itself
wordWithQuotes True escTransation

where

escTransation q mx =
case mx of
Just x ->
if q == x
then Just x
else Nothing
-- We are skipping the final quote here.
Nothing -> Nothing
wordWithQuotes
True
(\q x -> if q == x then Just x else Nothing)
(\_ -> if q == x then Just x else Nothing)

-- See the "Quoting Rules" section in the "bash" manual page for a primer on
-- how quotes are used by shells.
Expand All @@ -1886,19 +1880,7 @@ wordProcessQuotes :: (Monad m, Eq a) =>
-> Parser a m b
wordProcessQuotes =
-- Escape the quote char itself
wordWithQuotes False escTransation

where

escTransation q mx =
case mx of
Just x ->
if q == x
then Just x
else Nothing
-- We are skipping the final quote here.
Nothing -> Nothing

wordWithQuotes False (\q x -> if q == x then Just x else Nothing)

{-# ANN type GroupByState Fuse #-}
data GroupByState a s
Expand Down

0 comments on commit a6299c2

Please sign in to comment.