on master help sign in
Add/update comments in parser modules
d3b4e36Harendra Kumar
core/src/Streamly/Internal/Data/Parser.hs+23−1
@@ -85,9 +85,9 @@ module Streamly.Internal.Data.Parser
85 -- , take -- takeBetween 0 n
85 -- , take -- takeBetween 0 n
86 , takeEQ -- takeBetween n n
86 , takeEQ -- takeBetween n n
87 , takeGE -- takeBetween n maxBound
87 , takeGE -- takeBetween n maxBound
88+ , takeP
88
89
89 -- Grab a sequence of input elements by inspecting them
90 -- Grab a sequence of input elements by inspecting them
90− , takeP
91 , lookAhead
91 , lookAhead
92 , takeWhileP
92 , takeWhileP
93 , takeWhile
93 , takeWhile
@@ -95,16 +95,22 @@ module Streamly.Internal.Data.Parser
95 , takeWhile1
95 , takeWhile1
96 , drainWhile
96 , drainWhile
97
97
98+ -- Separators
98 , sliceSepByP
99 , sliceSepByP
99 , sliceBeginWith
100 , sliceBeginWith
100 , sliceSepWith
101 , sliceSepWith
102+
103+ -- Quoting and Escaping
101 , escapedSliceSepBy
104 , escapedSliceSepBy
102 , escapedFrameBy
105 , escapedFrameBy
106+
107+ -- Words and grouping
103 , wordBy
108 , wordBy
104 , groupBy
109 , groupBy
105 , groupByRolling
110 , groupByRolling
106 , groupByRollingEither
111 , groupByRollingEither
107 , eqBy
112 , eqBy
113+
108 -- | Unimplemented
114 -- | Unimplemented
109 --
115 --
110 -- @
116 -- @
@@ -498,6 +504,10 @@ takeEQ n = D.toParserK . D.takeEQ n
498takeGE :: MonadCatch m => Int -> Fold m a b -> Parser m a b
504takeGE :: MonadCatch m => Int -> Fold m a b -> Parser m a b
499takeGE n = D.toParserK . D.takeGE n
505takeGE n = D.toParserK . D.takeGE n
500
506
507+-------------------------------------------------------------------------------
508+-- Take until a condition
509+-------------------------------------------------------------------------------
510+
501-- $takeWhile
511-- $takeWhile
502-- Note: This is called @takeWhileP@ and @munch@ in some parser libraries.
512-- Note: This is called @takeWhileP@ and @munch@ in some parser libraries.
503
513
@@ -562,6 +572,10 @@ takeWhile1 cond = D.toParserK . D.takeWhile1 cond
562drainWhile :: MonadCatch m => (a -> Bool) -> Parser m a ()
572drainWhile :: MonadCatch m => (a -> Bool) -> Parser m a ()
563drainWhile p = takeWhile p FL.drain
573drainWhile p = takeWhile p FL.drain
564
574
575+-------------------------------------------------------------------------------
576+-- Separators
577+-------------------------------------------------------------------------------
578+
565-- | @sliceSepByP cond parser@ parses a slice of the input using @parser@ until
579-- | @sliceSepByP cond parser@ parses a slice of the input using @parser@ until
566-- @cond@ succeeds or the parser stops.
580-- @cond@ succeeds or the parser stops.
567--
581--
@@ -630,6 +644,10 @@ sliceBeginWith ::
630 (a -> Bool) -> Fold m a b -> Parser m a b
644 (a -> Bool) -> Fold m a b -> Parser m a b
631sliceBeginWith cond = D.toParserK . D.sliceBeginWith cond
645sliceBeginWith cond = D.toParserK . D.sliceBeginWith cond
632
646
647+-------------------------------------------------------------------------------
648+-- Quoting and Escaping
649+-------------------------------------------------------------------------------
650+
633-- | Like 'sliceSepBy' but the separator elements can be escaped using an
651-- | Like 'sliceSepBy' but the separator elements can be escaped using an
634-- escape char determined by the second predicate.
652-- escape char determined by the second predicate.
635--
653--
@@ -669,6 +687,10 @@ escapedFrameBy :: -- MonadCatch m =>
669escapedFrameBy _begin _end _escape _p = undefined
687escapedFrameBy _begin _end _escape _p = undefined
670 -- D.toParserK . D.frameBy begin end escape p
688 -- D.toParserK . D.frameBy begin end escape p
671
689
690+-------------------------------------------------------------------------------
691+-- Grouping and words
692+-------------------------------------------------------------------------------
693+
672-- | Like 'splitOn' but strips leading, trailing, and repeated separators.
694-- | Like 'splitOn' but strips leading, trailing, and repeated separators.
673-- Therefore, @".a..b."@ having '.' as the separator would be parsed as
695-- Therefore, @".a..b."@ having '.' as the separator would be parsed as
674-- @["a","b"]@. In other words, its like parsing words from whitespace
696-- @["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
56 -- sliceSepByMax cond n p = sliceBy cond (take n p)
56 -- sliceSepByMax cond n p = sliceBy cond (take n p)
57 -- sliceSepByBetween cond m n p = sliceBy cond (takeBetween m n p)
57 -- sliceSepByBetween cond m n p = sliceBy cond (takeBetween m n p)
58 -- takeWhileBetween cond m n p = takeWhile cond (takeBetween m n p)
58 -- takeWhileBetween cond m n p = takeWhile cond (takeBetween m n p)
59− --
59+
60 -- Grab a sequence of input elements without inspecting them
60 -- Grab a sequence of input elements without inspecting them
61 , takeBetween
61 , takeBetween
62 -- , take -- take -- takeBetween 0 n
62 -- , take -- take -- takeBetween 0 n
63 -- , takeLE1 -- take1 -- takeBetween 1 n
63 -- , takeLE1 -- take1 -- takeBetween 1 n
64 , takeEQ -- takeBetween n n
64 , takeEQ -- takeBetween n n
65 , takeGE -- takeBetween n maxBound
65 , takeGE -- takeBetween n maxBound
66+ , takeP
66
67
67 -- Grab a sequence of input elements by inspecting them
68 -- Grab a sequence of input elements by inspecting them
68− , takeP
69 , lookAhead
69 , lookAhead
70 , takeWhile
70 , takeWhile
71 , takeWhile1
71 , takeWhile1
72+
73+ -- Separators
72 , sliceSepByP
74 , sliceSepByP
73 -- , sliceSepByBetween
75 -- , sliceSepByBetween
74 , sliceBeginWith
76 , sliceBeginWith
75 -- , sliceSepWith
77 -- , sliceSepWith
76− --
78+
77− -- , frameSepBy -- parse frames escaped by an escape char/sequence
79+ -- Words and grouping
78− -- , frameEndWith
79− --
80 , wordBy
80 , wordBy
81 , groupBy
81 , groupBy
82 , groupByRolling
82 , groupByRolling
83 , groupByRollingEither
83 , groupByRollingEither
84+
85+ -- Matching strings
84 , eqBy
86 , eqBy
85 , matchBy
87 , matchBy
86 -- , prefixOf -- match any prefix of a given string
88 -- , prefixOf -- match any prefix of a given string
@@ -573,6 +575,10 @@ takeGE n (Fold fstep finitial fextract) = Parser step initial extract
573 $ "takeGE: Expecting at least " ++ show cnt
575 $ "takeGE: Expecting at least " ++ show cnt
574 ++ " elements, input terminated on " ++ show i
576 ++ " elements, input terminated on " ++ show i
575
577
578+-------------------------------------------------------------------------------
579+-- Conditional splitting
580+-------------------------------------------------------------------------------
581+
576-- | See 'Streamly.Internal.Data.Parser.takeWhile'.
582-- | See 'Streamly.Internal.Data.Parser.takeWhile'.
577--
583--
578-- /Pre-release/
584-- /Pre-release/
@@ -642,6 +648,10 @@ takeWhile1 predicate (Fold fstep finitial fextract) =
642 extract (Left _) = throwM $ ParseError "takeWhile1: end of input"
648 extract (Left _) = throwM $ ParseError "takeWhile1: end of input"
643 extract (Right s) = fextract s
649 extract (Right s) = fextract s
644
650
651+-------------------------------------------------------------------------------
652+-- Separators
653+-------------------------------------------------------------------------------
654+
645-- | See 'Streamly.Internal.Data.Parser.sliceSepByP'.
655-- | See 'Streamly.Internal.Data.Parser.sliceSepByP'.
646--
656--
647-- /Pre-release/
657-- /Pre-release/
@@ -705,6 +715,10 @@ sliceBeginWith cond (Fold fstep finitial fextract) =
705 extract (Left' s) = fextract s
715 extract (Left' s) = fextract s
706 extract (Right' s) = fextract s
716 extract (Right' s) = fextract s
707
717
718+-------------------------------------------------------------------------------
719+-- Grouping and words
720+-------------------------------------------------------------------------------
721+
708data WordByState s b = WBLeft !s | WBWord !s | WBRight !b
722data WordByState s b = WBLeft !s | WBWord !s | WBRight !b
709
723
710-- | See 'Streamly.Internal.Data.Parser.wordBy'.
724-- | See 'Streamly.Internal.Data.Parser.wordBy'.