on master help sign in
Expose Parser module (#1831)

Co-authored-by: Harendra Kumar <harendra@composewell.com>

commita060b799973b88b6e0912fd422befeac13d5f40a authorRanjeet Ranjan <ranjeetr@composewell.com> dateTue 20 Sep 2022, 14:44 (4 years ago) parentb1eb9c4
4 files changed+109−2
core/src/Streamly/Data/Parser.hs+105 core/src/Streamly/Internal/Data/Parser.hs+2−2 core/streamly-core.cabal+1 streamly.cabal+1
core/src/Streamly/Data/Parser.hsnew file+105
@@ -0,0 +1,105 @@
1+-- |
2+-- Module : Streamly.Data.Parser
3+-- Copyright : (c) 2020 Composewell Technologies
4+-- License : BSD-3-Clause
5+-- Maintainer : streamly@composewell.com
6+-- Stability : pre-release
7+-- Portability : GHC
8+--
9+-- Fast backtracking parsers with stream fusion and native streaming
10+-- capability. Parsers are just more powerful folds, folds and parsers can be
11+-- interconverted.
12+--
13+-- Note that these parsers do not report the error context (e.g. line number or
14+-- column). Though this can be supported in future.
15+--
16+module Streamly.Data.Parser
17+ (
18+ -- * Parser Type
19+ Parser
20+
21+ -- XXX Should we use Fold.fromParser instead?
22+ -- -- * Downgrade to Fold
23+ -- , toFold
24+
25+ -- * Parsers
26+ -- ** From Folds
27+ , fromFold
28+
29+ -- ** Without Input
30+ -- , fromFoldMaybe
31+ , fromPure
32+ , fromEffect
33+ , die
34+ -- , dieM
35+
36+ -- ** Element parsers
37+ , peek
38+
39+ -- All of these can be expressed in terms of either
40+ , one
41+ , element
42+ , except
43+ , oneOf
44+ , noneOf
45+ , satisfy
46+ -- , maybe
47+ -- , either
48+ , eof
49+
50+ -- ** Sequences
51+ , eqBy
52+ , list
53+
54+ -- * Combinators
55+ -- Mapping on output
56+ -- , rmapM
57+
58+ -- ** Mapping on input
59+ , lmap
60+ , lmapM
61+
62+ -- ** Filtering
63+ , filter
64+
65+ -- ** Look Ahead
66+ , lookAhead
67+
68+ -- ** Tokenize by length
69+ -- , takeBetween
70+ , takeEQ
71+ -- , takeGE
72+ -- , takeP
73+
74+ -- ** Tokenize by predicate
75+ -- , takeWhileP
76+ , takeWhile
77+ , takeWhile1
78+ , dropWhile
79+ -- , takeEndBy
80+ -- , takeEndByEsc
81+ -- , takeStartBy
82+ , wordBy
83+
84+ -- ** Grouping
85+ , groupBy
86+ -- , groupByRolling
87+ -- , groupByRollingEither
88+
89+ -- ** Framing
90+ , wordFramedBy
91+ , wordQuotedBy
92+
93+ -- ** Splitting
94+ , many
95+ , some
96+ , manyTill
97+
98+ -- ** De-interleaving
99+ , deintercalate
100+ )
101+
102+where
103+
104+import Streamly.Internal.Data.Parser
105+import Prelude hiding (dropWhile, takeWhile, filter)
core/src/Streamly/Internal/Data/Parser.hs+2−2
@@ -1008,7 +1008,7 @@ groupByRolling eq = D.toParserK . D.groupByRolling eq
10081008-- ascending and descending cases we can use 'groupByRollingEither (<=)
10091009-- Fold.toList Fold.toList'.
10101010--
1011−-- /Unimplemented/
1011+-- /Pre-release/
10121012{-# INLINE groupByRollingEither #-}
10131013groupByRollingEither :: Monad m =>
10141014 (a -> a -> Bool) -> Fold m a b -> Fold m a c -> Parser m a (Either b c)
@@ -1370,7 +1370,7 @@ manyTillP :: -- Monad m =>
13701370manyTillP _p1 _p2 _f = undefined
13711371 -- D.toParserK $ D.manyTillP (D.fromParserK p1) (D.fromParserK p2) f
13721372
1373−-- | @manyTill f collect test@ tries the parser @test@ on the input, if @test@
1373+-- | @manyTill f test collect@ tries the parser @test@ on the input, if @test@
13741374-- fails it backtracks and tries @collect@, after @collect@ succeeds @test@ is
13751375-- tried again and so on. The parser stops when @test@ succeeds. The output of
13761376-- @test@ is discarded and the output of @collect@ is accumulated by the
core/streamly-core.cabal+1
@@ -339,6 +339,7 @@ library
339339 , Streamly.Data.Unbox
340340 , Streamly.Data.Fold
341341 , Streamly.Data.Fold.Tee
342+ , Streamly.Data.Parser
342343 , Streamly.Data.Unfold
343344 , Streamly.Data.Array.Unboxed
344345 , Streamly.Data.Array.Unboxed.Mut
streamly.cabal+1
@@ -212,6 +212,7 @@ extra-source-files:
212212 core/src/Streamly/Data/Stream.hs
213213 core/src/Streamly/Data/Fold.hs
214214 core/src/Streamly/Data/Fold/Tee.hs
215+ core/src/Streamly/Data/Parser.hs
215216 core/src/Streamly/Data/Unfold.hs
216217 core/src/Streamly/Internal/Data/Fold/Window.hs
217218 core/src/Streamly/Data/Unbox.hs