5 | import Text.ByteRange
6 | import Text.ILex.Char.UTF8
7 | import public FS.Posix
8 | import public Text.ILex
10 | %hide Data.Linear.(.)
22 | {auto has : Has ex es}
23 | -> {auto lft : ELift1 q f}
26 | -> Pull f ByteString es x
28 | streamParseErr err prs pl = Prelude.do
29 | st <- lift1 (init 0 empty prs)
33 | onErr : HSum [e] -> HSum es
34 | onErr (Here x) = inject (err x)
36 | go : LexState prs -> Pull f ByteString es x -> Pull f a es x
38 | assert_total $
P.uncons p >>= \case
39 | Left res => Prelude.do
40 | v <- mapErrors onErr $
eliftEither {s = q} (lastStep prs st)
42 | Right (BS n bv,p2) => Prelude.do
43 | st2 <- mapErrors onErr $
eliftEither (stepState (toIBuffer bv) prs st)
44 | m <- lift1 (prs.chunk st2.stack)
45 | consMaybe m (go st2 p2)
51 | {auto has : Has (ByteError e) es}
52 | -> {auto lft : ELift1 q f}
54 | -> (prs : P1 q (ByteBounded e) a)
55 | -> Pull f ByteString es x
57 | streamParseFrom o = streamParseErr (byteError o)
68 | {auto has : Has e es}
69 | -> {auto lft : ELift1 q f}
71 | -> Pull f ByteString es x
73 | streamParse = streamParseErr id
79 | {auto has : Has ex es}
80 | -> {auto lft : ELift1 q f}
84 | -> Stream f es ByteString
86 | streamValErr err dflt prs = P.lastOr dflt . streamParseErr err prs
90 | {auto has : Has (ByteError e) es}
91 | -> {auto lft : ELift1 q f}
94 | -> (prs : P1 q (ByteBounded e) a)
95 | -> Stream f es ByteString
97 | streamValFrom o = streamValErr (byteError o)
101 | {auto has : Has e es}
102 | -> {auto lft : ELift1 q f}
103 | -> (dflts : Lazy a)
104 | -> (prs : P1 q e a)
105 | -> Stream f es ByteString
107 | streamVal = streamValErr id
118 | {auto h : HasIO (f es)}
120 | -> Stream f es ByteString
121 | -> Pull f o es (Maybe TextBounds)
122 | locateBounds NoBB bs = pure Nothing
123 | locateBounds (BB start end) bs =
124 | P.scans1 None (appendChunk start end) bs
125 | |> P.takeThrough (not . isDone)
127 | |> map (textBounds start end)
129 | parameters {auto ph : PollH e}
130 | {auto he : Has Errno es}
132 | {auto hb : Has (ByteError x) es}
133 | {auto hf : Has (FCErr x) es}
144 | locError : AsyncPull e o es a -> AsyncPull e o es a
146 | handleError (ByteError x) $
\x => case x.origin of
147 | FileSrc p => Prelude.do
148 | m <- locateBounds x.bounds (readBytes p)
149 | maybe (throw x) (throw . toFCErr x) m