File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -56,16 +56,26 @@ def skipByte (b : UInt8) : Parser Unit :=
5656/--
5757Skip a sequence of bytes equal to the given `ByteArray`.
5858-/
59- def skipBytes (arr : ByteArray) : Parser Unit := do
60- for b in arr do
61- skipByte b
59+ def skipBytes (arr : ByteArray) : Parser Unit := fun it =>
60+ if it.remainingBytes < arr.size then
61+ .error it .eof
62+ else
63+ let rec go (idx : Nat) (it : ByteArray.Iterator) : ParseResult Unit ByteArray.Iterator :=
64+ if h : idx < arr.size then
65+ match skipByte arr[idx] it with
66+ | .success it' _ => go (idx + 1 ) it'
67+ | .error it' err => .error it' err
68+ else
69+ .success it ()
70+ go 0 it
6271
6372/--
6473Parse a string by matching its UTF-8 bytes, returns the string on success.
6574-/
6675@[inline]
6776def pstring (s : String) : Parser String := do
68- skipBytes s.toUTF8
77+ let utf8 := s.toUTF8
78+ skipBytes utf8
6979 return s
7080
7181/--
You can’t perform that action at this time.
0 commit comments