on master help sign in
Add/update comments in parser modules
commitd3b4e36ac736a58e1179fc6d89978f02d18c515d authorHarendra Kumar <harendra@composewell.com> dateTue 3 May 2022, 13:37 (4 years ago) parent7f38a19
2 files changed+43−7
core/src/Streamly/Internal/Data/Parser.hs+23−1 core/src/Streamly/Internal/Data/Parser/ParserD.hs+20−6
core/src/Streamly/Internal/Data/Parser.hs+23−1
@@ -85,9 +85,9 @@ module Streamly.Internal.Data.Parser
8585 -- , take -- takeBetween 0 n
8686 , takeEQ -- takeBetween n n
8787 , takeGE -- takeBetween n maxBound
88+ , takeP
8889
8990 -- Grab a sequence of input elements by inspecting them
90− , takeP
9191 , lookAhead
9292 , takeWhileP
9393 , takeWhile
@@ -95,16 +95,22 @@ module Streamly.Internal.Data.Parser
9595 , takeWhile1
9696 , drainWhile
9797
98+ -- Separators
9899 , sliceSepByP
99100 , sliceBeginWith
100101 , sliceSepWith
102+
103+ -- Quoting and Escaping
101104 , escapedSliceSepBy
102105 , escapedFrameBy
106+
107+ -- Words and grouping
103108 , wordBy
104109 , groupBy
105110 , groupByRolling
106111 , groupByRollingEither
107112 , eqBy
113+
108114 -- | Unimplemented
109115 --
110116 -- @
@@ -498,6 +504,10 @@ takeEQ n = D.toParserK . D.takeEQ n
498504takeGE :: MonadCatch m => Int -> Fold m a b -> Parser m a b
499505takeGE n = D.toParserK . D.takeGE n
500506
507+-------------------------------------------------------------------------------
508+-- Take until a condition
509+-------------------------------------------------------------------------------
510+
501511-- $takeWhile
502512-- Note: This is called @takeWhileP@ and @munch@ in some parser libraries.
503513
@@ -562,6 +572,10 @@ takeWhile1 cond = D.toParserK . D.takeWhile1 cond
562572drainWhile :: MonadCatch m => (a -> Bool) -> Parser m a ()
563573drainWhile p = takeWhile p FL.drain
564574
575+-------------------------------------------------------------------------------
576+-- Separators
577+-------------------------------------------------------------------------------
578+
565579-- | @sliceSepByP cond parser@ parses a slice of the input using @parser@ until
566580-- @cond@ succeeds or the parser stops.
567581--
@@ -630,6 +644,10 @@ sliceBeginWith ::
630644 (a -> Bool) -> Fold m a b -> Parser m a b
631645sliceBeginWith cond = D.toParserK . D.sliceBeginWith cond
632646
647+-------------------------------------------------------------------------------
648+-- Quoting and Escaping
649+-------------------------------------------------------------------------------
650+
633651-- | Like 'sliceSepBy' but the separator elements can be escaped using an
634652-- escape char determined by the second predicate.
635653--
@@ -669,6 +687,10 @@ escapedFrameBy :: -- MonadCatch m =>
669687escapedFrameBy _begin _end _escape _p = undefined
670688 -- D.toParserK . D.frameBy begin end escape p
671689
690+-------------------------------------------------------------------------------
691+-- Grouping and words
692+-------------------------------------------------------------------------------
693+
672694-- | Like 'splitOn' but strips leading, trailing, and repeated separators.
673695-- Therefore, @".a..b."@ having '.' as the separator would be parsed as
674696-- @["a","b"]@. In other words, its like parsing words from whitespace
core/src/Streamly/Internal/Data/Parser/ParserD.hs+20−6
@@ -56,31 +56,33 @@ module Streamly.Internal.Data.Parser.ParserD
5656 -- sliceSepByMax cond n p = sliceBy cond (take n p)
5757 -- sliceSepByBetween cond m n p = sliceBy cond (takeBetween m n p)
5858 -- takeWhileBetween cond m n p = takeWhile cond (takeBetween m n p)
59− --
59+
6060 -- Grab a sequence of input elements without inspecting them
6161 , takeBetween
6262 -- , take -- take -- takeBetween 0 n
6363 -- , takeLE1 -- take1 -- takeBetween 1 n
6464 , takeEQ -- takeBetween n n
6565 , takeGE -- takeBetween n maxBound
66+ , takeP
6667
6768 -- Grab a sequence of input elements by inspecting them
68− , takeP
6969 , lookAhead
7070 , takeWhile
7171 , takeWhile1
72+
73+ -- Separators
7274 , sliceSepByP
7375 -- , sliceSepByBetween
7476 , sliceBeginWith
7577 -- , sliceSepWith
76− --
77− -- , frameSepBy -- parse frames escaped by an escape char/sequence
78− -- , frameEndWith
79− --
78+
79+ -- Words and grouping
8080 , wordBy
8181 , groupBy
8282 , groupByRolling
8383 , groupByRollingEither
84+
85+ -- Matching strings
8486 , eqBy
8587 , matchBy
8688 -- , prefixOf -- match any prefix of a given string
@@ -573,6 +575,10 @@ takeGE n (Fold fstep finitial fextract) = Parser step initial extract
573575 $ "takeGE: Expecting at least " ++ show cnt
574576 ++ " elements, input terminated on " ++ show i
575577
578+-------------------------------------------------------------------------------
579+-- Conditional splitting
580+-------------------------------------------------------------------------------
581+
576582-- | See 'Streamly.Internal.Data.Parser.takeWhile'.
577583--
578584-- /Pre-release/
@@ -642,6 +648,10 @@ takeWhile1 predicate (Fold fstep finitial fextract) =
642648 extract (Left _) = throwM $ ParseError "takeWhile1: end of input"
643649 extract (Right s) = fextract s
644650
651+-------------------------------------------------------------------------------
652+-- Separators
653+-------------------------------------------------------------------------------
654+
645655-- | See 'Streamly.Internal.Data.Parser.sliceSepByP'.
646656--
647657-- /Pre-release/
@@ -705,6 +715,10 @@ sliceBeginWith cond (Fold fstep finitial fextract) =
705715 extract (Left' s) = fextract s
706716 extract (Right' s) = fextract s
707717
718+-------------------------------------------------------------------------------
719+-- Grouping and words
720+-------------------------------------------------------------------------------
721+
708722data WordByState s b = WBLeft !s | WBWord !s | WBRight !b
709723
710724-- | See 'Streamly.Internal.Data.Parser.wordBy'.