@@ -127,6 +127,7 @@ module Streamly.Internal.Data.Parser
127 -- , takeFramedBy
127 -- , takeFramedBy
128 , takeFramedBy_
128 , takeFramedBy_
129 , takeFramedByEsc_
129 , takeFramedByEsc_
130+ , takeFramedByGeneric
130 -- , wordByQuoted
131 -- , wordByQuoted
131 -- , wordByQuotedEsc
132 -- , wordByQuotedEsc
@@ -660,7 +661,17 @@ dropWhile p = takeWhile p FL.drain
660-- Separators
661-- Separators
661-------------------------------------------------------------------------------
662-------------------------------------------------------------------------------
664+{-# INLINE takeFramedByGeneric #-}
665+takeFramedByGeneric :: MonadCatch m =>
667+ -> Maybe (a -> Bool)
668+ -> Maybe (a -> Bool)
671+takeFramedByGeneric esc begin end f =
672+ D.toParserK $ D.takeFramedByGeneric esc begin end f
663−-- | @takeEndBy_ cond parser@ parses a token that ends by a separator chosen by
674+-- | @takeEndBy cond parser@ parses a token that ends by a separator chosen by
664-- the supplied predicate. The separator is also taken with the token.
675-- the supplied predicate. The separator is also taken with the token.
666-- This can be combined with other parsers to implement other interesting
677-- This can be combined with other parsers to implement other interesting
@@ -669,6 +680,8 @@ dropWhile p = takeWhile p FL.drain
669-- >>> takeEndByLE cond n p = Parser.takeEndBy cond (Parser.fromFold $ Fold.take n p)
680-- >>> takeEndByLE cond n p = Parser.takeEndBy cond (Parser.fromFold $ Fold.take n p)
670-- >>> takeEndByBetween cond m n p = Parser.takeEndBy cond (Parser.takeBetween m n p)
681-- >>> takeEndByBetween cond m n p = Parser.takeEndBy cond (Parser.takeBetween m n p)
683+-- >>> takeEndBy = Parser.takeEndByEsc (const False)
672-- See also "Streamly.Data.Fold.takeEndBy".
685-- See also "Streamly.Data.Fold.takeEndBy".
674-- /Pre-release/
687-- /Pre-release/
@@ -676,6 +689,7 @@ dropWhile p = takeWhile p FL.drain
676{-# INLINE takeEndBy #-}
689{-# INLINE takeEndBy #-}
677takeEndBy :: MonadCatch m => (a -> Bool) -> Parser m a b -> Parser m a b
690takeEndBy :: MonadCatch m => (a -> Bool) -> Parser m a b -> Parser m a b
678takeEndBy cond = D.toParserK . D.takeEndBy cond . D.fromParserK
691takeEndBy cond = D.toParserK . D.takeEndBy cond . D.fromParserK
692+-- takeEndBy = takeEndByEsc (const False)
680-- | Like 'takeEndBy' but the separator is dropped.
694-- | Like 'takeEndBy' but the separator is dropped.
@@ -686,6 +700,10 @@ takeEndBy cond = D.toParserK . D.takeEndBy cond . D.fromParserK
686{-# INLINE takeEndBy_ #-}
700{-# INLINE takeEndBy_ #-}
687takeEndBy_ :: MonadCatch m => (a -> Bool) -> Parser m a b -> Parser m a b
701takeEndBy_ :: MonadCatch m => (a -> Bool) -> Parser m a b -> Parser m a b
688takeEndBy_ cond = D.toParserK . D.takeEndBy_ cond . D.fromParserK
702takeEndBy_ cond = D.toParserK . D.takeEndBy_ cond . D.fromParserK
705+ takeFramedByGeneric Nothing Nothing (Just isEnd) (toFold p)
690-- | Take either the separator or the token. Separator is a Left value and
708-- | Take either the separator or the token. Separator is a Left value and
691-- token is Right value.
709-- token is Right value.
@@ -724,6 +742,12 @@ takeEitherSepBy _cond = undefined -- D.toParserK . D.takeEitherSepBy cond
724takeStartBy :: MonadCatch m => (a -> Bool) -> Fold m a b -> Parser m a b
742takeStartBy :: MonadCatch m => (a -> Bool) -> Fold m a b -> Parser m a b
725takeStartBy cond = D.toParserK . D.takeStartBy cond
743takeStartBy cond = D.toParserK . D.takeStartBy cond
746+{-# INLINE takeStartBy_ #-}
747+takeStartBy_ :: MonadCatch m => (a -> Bool) -> Fold m a b -> Parser m a b
748+takeStartBy_ isBegin = takeFramedByGeneric Nothing (Just isBegin) Nothing
727-------------------------------------------------------------------------------
751-------------------------------------------------------------------------------
728-- Quoting and Escaping
752-- Quoting and Escaping
729-------------------------------------------------------------------------------
753-------------------------------------------------------------------------------
@@ -732,14 +756,12 @@ takeStartBy cond = D.toParserK . D.takeStartBy cond
732-- escape char determined by the first predicate. The escape characters are
756-- escape char determined by the first predicate. The escape characters are
733-- removed.
757-- removed.
735−-- >>> takeEndBy = Parser.takeEndByEsc (const False)
737-- /pre-release/
759-- /pre-release/
738{-# INLINE takeEndByEsc #-}
760{-# INLINE takeEndByEsc #-}
739takeEndByEsc :: MonadCatch m =>
761takeEndByEsc :: MonadCatch m =>
740 (a -> Bool) -> (a -> Bool) -> Parser m a b -> Parser m a b
762 (a -> Bool) -> (a -> Bool) -> Parser m a b -> Parser m a b
741−takeEndByEsc isEsc isSep p =
763+takeEndByEsc isEsc isEnd p =
742− D.toParserK $ D.takeEndByEsc isEsc isSep (D.fromParserK p)
764+ D.toParserK $ D.takeEndByEsc isEsc isEnd (D.fromParserK p)
744-- | @takeFramedByEsc_ isEsc isBegin isEnd fold@ parses a token framed using a
766-- | @takeFramedByEsc_ isEsc isBegin isEnd fold@ parses a token framed using a
745-- begin and end predicate, and an escape character. The frame begin and end
767-- begin and end predicate, and an escape character. The frame begin and end
@@ -767,6 +789,8 @@ takeFramedByEsc_ :: MonadCatch m =>
767 (a -> Bool) -> (a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser m a b
789 (a -> Bool) -> (a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser m a b
768takeFramedByEsc_ isEsc isBegin isEnd f =
790takeFramedByEsc_ isEsc isBegin isEnd f =
769 D.toParserK $ D.takeFramedByEsc_ isEsc isBegin isEnd f
791 D.toParserK $ D.takeFramedByEsc_ isEsc isBegin isEnd f
792+-- takeEndByEsc_ isEsc isEnd p =
793+-- takeFramedByGeneric (Just isEsc) Nothing (Just isEnd) (toFold p)
771-- | @takeFramedBy_ isBegin isEnd fold@ parses a token framed by a begin and an
795-- | @takeFramedBy_ isBegin isEnd fold@ parses a token framed by a begin and an
772-- end predicate.
796-- end predicate.
@@ -777,7 +801,8 @@ takeFramedByEsc_ isEsc isBegin isEnd f =
777takeFramedBy_ :: MonadCatch m =>
801takeFramedBy_ :: MonadCatch m =>
778 (a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser m a b
802 (a -> Bool) -> (a -> Bool) -> Fold m a b -> Parser m a b
779takeFramedBy_ isBegin isEnd f = D.toParserK $ D.takeFramedBy_ isBegin isEnd f
803takeFramedBy_ isBegin isEnd f = D.toParserK $ D.takeFramedBy_ isBegin isEnd f
780−-- takeFramedBy_ = takeFramedByEsc_ (const False)
804+-- takeFramedBy_ isBegin isEnd =
805+-- takeFramedByGeneric (Just (const False)) (Just isBegin) (Just isEnd)
782-------------------------------------------------------------------------------
807-------------------------------------------------------------------------------
783-- Grouping and words
808-- Grouping and words