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
9-- Fast backtracking parsers with stream fusion and native streaming
10-- capability. Parsers are just more powerful folds, folds and parsers can be
13-- Note that these parsers do not report the error context (e.g. line number or
14-- column). This may be supported in future.
16-- mtl instances are not provided. If the 'Parser' type is the top most layer
17-- (which should be the case almost always) you can just use 'fromEffect' to
18-- execute the lower layer monad effects.
20-- == Performance Notes
22-- This module is designed for fusion, inline the operations in this module for
23-- fusion to occur, avoid using these operations in recursive calls, avoid
24-- operations like 'sequence', 'asum' on these parsers. If you need these then
25-- use the 'ParserK' module instead.
27-- The 'Parser' type represents a stream consumer by composing state as data
28-- which enables stream fusion. Stream fusion generates a tight loop without
29-- any constructor allocations between the stages, providing C like performance
30-- for the loop. Stream fusion works when multiple functions are combined in a
31-- pipeline statically. Therefore, the operations in this module must be
32-- inlined and must not be used recursively to allow for stream fusion.
34-- Using the 'Parser' type parsing operations like 'one', 'splitWith' etc.
35-- degrade quadratically (O(n^2)) when combined many times. If you need to
36-- combine these operations, say more than 50 times in a single loop, then you
37-- should use the continuation style parser type 'ParserK' instead. Also, if
38-- you need to use these operations in a recursive loop you should use
41-- The 'ParserK' type represents a stream consumer by composing function calls,
42-- therefore, a function call overhead is incurred at each composition. It is
43-- quite fast in general but may be a few times slower than a fused parser.
44-- However, it allows for scalable dynamic composition especially parsers can
45-- be used in recursive calls. Using the 'ParserK' type operations like
46-- 'splitWith' provide linear (O(n)) performance with respect to the number of
49-- 'Parser' and 'ParserK' types can be interconverted.
51module Streamly.Data.Parser
56 -- -- * Downgrade to Fold
74 -- All of these can be expressed in terms of either
93 -- ** Mapping on input
106 -- ** Tokenize by length
112 -- ** Tokenize by predicate
125 -- , groupByRollingEither
140 -- ** De-interleaving
146import Streamly.Internal.Data.Parser
147import Prelude hiding (dropWhile, takeWhile, filter)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list