3 | import public FS.Posix
4 | import public Text.ILex
6 | import Text.ILex.Char.UTF8
8 | %hide Data.Linear.(.)
20 | {auto has : Has ex es}
21 | -> {auto lft : ELift1 q f}
24 | -> Pull f ByteString es x
26 | streamParseErr err prs pl = Prelude.do
27 | st <- lift1 (init 0 empty prs)
31 | onErr : HSum [e] -> HSum es
32 | onErr (Here x) = inject (err x)
34 | go : LexState prs -> Pull f ByteString es x -> Pull f a es x
36 | assert_total $
P.uncons p >>= \case
37 | Left res => Prelude.do
38 | v <- mapErrors onErr $
eliftEither {s = q} (lastStep prs st)
40 | Right (BS n bv,p2) => Prelude.do
41 | st2 <- mapErrors onErr $
eliftEither (stepState (toIBuffer bv) prs st)
42 | m <- lift1 (prs.chunk st2.stack)
43 | consMaybe m (go st2 p2)
49 | {auto has : Has (ByteError e) es}
50 | -> {auto lft : ELift1 q f}
52 | -> (prs : P1 q (ByteBounded e) a)
53 | -> Pull f ByteString es x
55 | streamParseFrom o = streamParseErr (byteError o)
66 | {auto has : Has e es}
67 | -> {auto lft : ELift1 q f}
69 | -> Pull f ByteString es x
71 | streamParse = streamParseErr id
77 | {auto has : Has ex es}
78 | -> {auto lft : ELift1 q f}
82 | -> Stream f es ByteString
84 | streamValErr err dflt prs = P.lastOr dflt . streamParseErr err prs
88 | {auto has : Has (ByteError e) es}
89 | -> {auto lft : ELift1 q f}
92 | -> (prs : P1 q (ByteBounded e) a)
93 | -> Stream f es ByteString
95 | streamValFrom o = streamValErr (byteError o)
99 | {auto has : Has e es}
100 | -> {auto lft : ELift1 q f}
101 | -> (dflts : Lazy a)
102 | -> (prs : P1 q e a)
103 | -> Stream f es ByteString
105 | streamVal = streamValErr id
108 | adjBE : ByteError e -> (SnocList ByteString, x) -> ByteError e
109 | adjBE be z = {content := Just (fastConcat $
fst z <>> [])} be
111 | parameters {auto ph : PollH e}
112 | {auto he : Has Errno es}
123 | locError : Has (ByteError x) es => AsyncPull e o es a -> AsyncPull e o es a
125 | handleError (ByteError x) $
\x => case x.origin of
126 | FileSrc p => readBytes p |> P.foldPair (:<) [<] |> (>>= throw . adjBE x)