Skip to content

Commit

Permalink
made max_steps a positional arg
Browse files Browse the repository at this point in the history
  • Loading branch information
kencole committed Sep 21, 2021
1 parent 75c2c91 commit a6b2d5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/angstrom.ml
Expand Up @@ -461,7 +461,7 @@ let fix_direct f =
in
r

let fix_lazy ?(max_steps=20) f =
let fix_lazy max_steps f =
let steps = ref max_steps in
let rec p = lazy (f r)
and r = { run = fun buf pos more fail succ ->
Expand All @@ -479,7 +479,7 @@ let fix_lazy ?(max_steps=20) f =
let fix = match Sys.backend_type with
| Native -> fix_direct
| Bytecode -> fix_direct
| Other _ -> fun f -> fix_lazy f
| Other _ -> fun f -> fix_lazy 20 f

let option x p =
p <|> return x
Expand Down
11 changes: 5 additions & 6 deletions lib/angstrom.mli
Expand Up @@ -348,16 +348,15 @@ val fix : ('a t -> 'a t) -> 'a t
let obj = char '{' *> ... json ... <* char '}' in
choice [str; num; arr json, ...])]} *)

(** [fix_lazy] is like [fix], but after the function is
[max_steps] deep, it wraps up the remaining computation and yields
(** [fix_lazy] is like [fix], but after the function reaches the max
depth, it wraps up the remaining computation and yields
back to the root of the parsing loop where it continues from there.
This is an effective way to break up the stack trace into more managable
chunks, which is important for Js_of_ocaml due to the lack of tailrec
optimizations for CPS-style tail calls. [max_steps] defaults to
[20], and when compiling for Js_of_ocaml, [fix] itself is defined as
[fix_lazy] set to [20]. *)
val fix_lazy : ?max_steps:int-> ('a t -> 'a t) -> 'a t
optimizations for CPS-style tail calls. When compiling for Js_of_ocaml,
[fix] itself is defined as [fix_lazy 20]. *)
val fix_lazy : int -> ('a t -> 'a t) -> 'a t

(** {2 Alternatives} *)

Expand Down

0 comments on commit a6b2d5e

Please sign in to comment.