forked from haskell/attoparsec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattoparsec-isotropic.cabal
More file actions
237 lines (216 loc) · 7.05 KB
/
Copy pathattoparsec-isotropic.cabal
File metadata and controls
237 lines (216 loc) · 7.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
cabal-version: 3.0
name: attoparsec-isotropic
version: 0.14.5
license: BSD-3-Clause
license-file: LICENSE
category: Text, Parsing
author: Daniil Iaitskov <dyaitskov@gmail.com>
maintainer: Daniil Iaitskov <dyaitskov@gmail.com>
stability: experimental
synopsis: right-to-left parser backward compatible with attoparsec
homepage: https://github.com/yaitskov/attoparsec-isotropic
bug-reports: https://github.com/yaitskov/attoparsec-isotropic/issues
build-type: Simple
description:
A fork of <https://github.com/haskell/attoparsec attoparsec> library
allows to define omnidirected parsers or parsers consuming input from
right-to-left. The library is highly backward compabitle with original
interface. Idea to do the fork is inspired by the need to parse a CSV
file in <https://github.com/yaitskov/RobinHood-pr0fit robin-hood-profit>
in one go with “constant” memory footprint and rows in reverse
chronological order.
== Example
#example#
> {-# LANGUAGE OverloadedStrings #-}
> {-# LANGUAGE TupleSections #-}
> import Data.Attoparsec.ByteString
>
> test = parseOnly ab "ab" == parseBackOnly ba "ab"
> where
> ab = (,) <$> string "a" <*> string "b"
> ba = (,) <$> string "b" <*> string "a"
>
> test2 = parseOnly ab "ab" == parseBackOnly ab "ba"
> where
> ab = string "a" >*< string "b"
== Running parser in reverse incrementally
#running-parser-in-reverse-incrementally#
Snippet from the CSV parser app:
> consumeFile :: Handle -> (RobinRow -> ProfitM ()) -> ProfitM ()
> consumeFile h handleRow = do
> input <- readBlock h
> go Nothing input
> where
> go !loopDetector input = do
> iBlock <- gets (^. #currentBlock)
> if iBlock < 0 && input == mempty
> then pure ()
> else do
> parseBackWith (readBlock h) parseRow input >>= \case
> Fail _unconsumed ctx er -> do
> erpos <- liftIO $ hTell h
> fail $ "Failed to parse CSV file around " <> show erpos <> " byte; due: "
> <> show er <> "; context: " <> show ctx
> Partial _ -> fail "CSV file is partial"
> Done (unconsumed :: ByteString) (rawRow :: [ByteString]) -> do
> iBlock' <- gets (^. #currentBlock)
> if loopDetector == Just (unconsumed, iBlock')
> then
> fail $ "Loop detected. Unconsumed input: " <> show unconsumed
> else do
> trashCodes <- asks (^. #codesToSkip)
> case parseRobinRow trashCodes rawRow of
> Left e -> fail e
> Right row -> do
> forM_ row handleRow
> go (Just (unconsumed, iBlock')) unconsumed
tested-with:
GHC == 9.10.1, GHC == 9.12.2
extra-source-files:
benchmarks/*.txt
benchmarks/json-data/*.json
benchmarks/Makefile
benchmarks/med.txt.bz2
examples/*.c
examples/*.hs
examples/Makefile
extra-doc-files:
README.md
changelog.md
Flag developer
Description: Whether to build the library in development mode
Default: False
Manual: True
common base
default-language: GHC2024
ghc-options: -Wall
default-extensions:
CPP
DefaultSignatures
OverloadedStrings
TemplateHaskell
TypeFamilies
build-depends:
array < 1
, base < 5
, bytestring < 1
, containers < 1
, deepseq < 2
, fail < 5
, haddock-use-refs < 2
, scientific < 1
, semigroups < 0.21
, tagged < 1
, text < 3
, trace-embrace >= 1.2 && < 3
, transformers < 1
-- We need to test and benchmark these modules,
-- but do not want to expose them to end users
library attoparsec-isotropic-internal
import: base
hs-source-dirs: internal
exposed-modules: Data.Attoparsec.ByteString.Buffer
Data.Attoparsec.ByteString.FastSet
Data.Attoparsec.Internal.Compat
Data.Attoparsec.Internal.Fhthagn
Data.Attoparsec.Text.Buffer
Data.Attoparsec.Text.FastSet
ghc-options: -O2 -Wall
library
import: base
build-depends:
attoparsec-isotropic-internal
, ghc-prim < 0.14
exposed-modules: Data.Attoparsec
Data.Attoparsec.ByteString
Data.Attoparsec.ByteString.Char8
Data.Attoparsec.ByteString.Lazy
Data.Attoparsec.Char8
Data.Attoparsec.Combinator
Data.Attoparsec.Internal
Data.Attoparsec.Internal.Types
Data.Attoparsec.Lazy
Data.Attoparsec.Number
Data.Attoparsec.Text
Data.Attoparsec.Text.Lazy
Data.Attoparsec.Types
Data.Attoparsec.Zepto
other-modules: Data.Attoparsec.ByteString.Internal
Data.Attoparsec.Text.Internal
ghc-options: -O2 -Wall
if flag(developer)
ghc-prof-options: -auto-all
ghc-options: -Werror
test-suite attoparsec-isotropic-tests
import: base
type: exitcode-stdio-1.0
hs-source-dirs: tests
main-is: QC.hs
other-modules: QC.Buffer
QC.ByteString
QC.ByteStringRightToLeft
QC.Combinator
QC.CombinatorRight
QC.Common
QC.IPv6.Internal
QC.IPv6.Types
QC.MonoidalScientific
QC.Rechunked
QC.Simple
QC.Text
QC.Text.FastSet
QC.Text.Regressions
ghc-options:
-Wall -threaded -rtsopts
if flag(developer)
ghc-options: -Werror
build-depends:
QuickCheck >= 2.13.2 && < 2.16
, attoparsec-isotropic
, attoparsec-isotropic-internal
, quickcheck-unicode
, tasty >= 1 && < 2
, tasty-bench >= 0.3 && < 1
, tasty-quickcheck >= 0.8 && < 1
, vector
-- benchmark dependencies
-- cabal2nix skips dependencies from benchmark
, http-types
benchmark attoparsec-isotropic-benchmarks
import: base
type: exitcode-stdio-1.0
hs-source-dirs: benchmarks benchmarks/warp-3.0.1.1
ghc-options: -O2 -Wall -rtsopts
main-is: Benchmarks.hs
other-modules:
Aeson
Common
Genome
HeadersByteString
HeadersByteString.Atto
HeadersText
Links
Network.Wai.Handler.Warp.ReadInt
Network.Wai.Handler.Warp.RequestHeader
Numbers
Sets
TextFastSet
Warp
ghc-options: -O2 -Wall
if flag(developer)
ghc-options: -Werror
build-depends:
attoparsec-isotropic
, attoparsec-isotropic-internal
, case-insensitive
, directory
, filepath
, ghc-prim
, http-types
, parsec >= 3.1.2
, tasty-bench >= 0.3 && < 1
, unordered-containers
, vector
source-repository head
type: git
location: https://github.com/yaitskov/attoparsec-isotropic.git