File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,6 +21,57 @@ def many1 (p : Get α) : Get (Array α) := do
2121 let rest ← many p
2222 return rest.insertIdx 0 first
2323
24+ -- TODO: refactor following definitions for performance
25+
26+ @ [inline, specialize]
27+ def takeAtLeast (n : Nat) (p : Get α) : Get (Array α) := do
28+ let mut r := #[]
29+ repeat
30+ if r.size == n then break
31+ let x ← p
32+ r := r.push x
33+ repeat
34+ let some x ← optional p | break
35+ r := r.push x
36+ return r
37+
38+ /-- inclusive -/
39+ @ [inline, specialize]
40+ def takeUpTo (n : Nat) (p : Get α) : Get (Array α) := do
41+ let mut r := #[]
42+ repeat
43+ if r.size == n then break
44+ let some x ← optional p | break
45+ r := r.push x
46+ return r
47+
48+ @ [inline, specialize]
49+ def takeN (n : Nat) (p : Get α) : Get (Array α) := do
50+ let mut r := #[]
51+ repeat
52+ if r.size == n then break
53+ let x ← p
54+ r := r.push x
55+ return r
56+
57+ /--inclusive on both sides -/
58+ @ [inline, specialize]
59+ def takeRange (min max : Nat) (p : Get α) : Get (Array α) := do
60+ let mut r := #[]
61+ repeat
62+ if r.size == min then break
63+ let x ← p
64+ r := r.push x
65+ repeat
66+ if r.size == max then break
67+ let some x ← optional p | break
68+ r := r.push x
69+ return r
70+
71+ end
72+
73+ public section
74+
2475@[always_inline]
2576instance : Decode UInt8 where
2677 get d :=
You can’t perform that action at this time.
0 commit comments