Module Visitor.Fold

Visitor that accumulates over the nodes of the tree.

type 'a action = 'a folding_action
type ('x, 'a) fold = 'x -> 'a -> 'a folding_action

Some combinators to write more readable folding visitors

val skip_children : 'a -> 'a folding_action
val skip : 'a -> 'a folding_action
val do_children : 'a -> 'a folding_action
val proceed : 'a -> 'a folding_action
val do_children_and_then : 'a -> ('a -> 'a) -> 'a folding_action
val proceed_and_then : 'a -> ('a -> 'a) -> 'a folding_action
val default : 'a -> 'b -> 'b folding_action

Action handling

val handle : ('a -> 'b -> 'b action) -> continue:('a -> 'b -> 'b) -> 'a -> 'b -> 'b

handle fold continue node acc first calls fold node acc, and then behaves according to the action returned.

val leaf : ('x -> 'a -> 'a action) -> 'x -> 'a -> 'a

leaf fold node acc calls fold node acc and returns immediately (after executing the post action, if fold returns DoChildrenAndThen).

class 'a folder : object ... end

Base folding visitor.

Entry points for folding over some basic types.

val fold_bool : 'a folder -> bool -> 'a -> 'a
val fold_char : 'a folder -> char -> 'a -> 'a
val fold_int : 'a folder -> int -> 'a -> 'a
val fold_string : 'a folder -> string -> 'a -> 'a

Generic entry points.

val fold_option : fold:('b folder as 'a -> 'c -> 'b -> 'b) -> 'd -> 'c option -> 'b -> 'b
val fold_list : fold:('b folder as 'a -> 'c -> 'b -> 'b) -> 'd -> 'c list -> 'b -> 'b
val fold_nel : fold:('b folder as 'a -> 'c -> 'b -> 'b) -> 'd -> 'c Basics.NEL.t -> 'b -> 'b
val fold' : fold:('b folder as 'a -> 'c -> 'b -> 'b) -> 'd -> 'c Srcloc.TYPES.with_loc -> 'b -> 'b
val fold_int' : 'a folder -> int Srcloc.TYPES.with_loc -> 'a -> 'a
val fold_int'_opt : 'a folder -> int Srcloc.TYPES.with_loc option -> 'a -> 'a
val fold_string' : 'a folder -> string Srcloc.TYPES.with_loc -> 'a -> 'a
val fold_string'_opt : 'a folder -> string Srcloc.TYPES.with_loc option -> 'a -> 'a
val fold_with_loc_list : fold:('b folder as 'a -> 'c -> 'b -> 'b) -> 'd -> 'c Srcloc.TYPES.with_loc list -> 'b -> 'b
val handle' : ('a Srcloc.TYPES.with_loc -> 'x -> 'x action) -> fold:('x folder as 'b -> 'a -> 'x -> 'x) -> 'b -> 'a Srcloc.TYPES.with_loc -> 'x -> 'x

Helper to shorten definitions for traversal of nodes with source locations

val leaf' : ('a Srcloc.TYPES.with_loc -> 'b -> 'b action) -> 'b folder -> 'a Srcloc.TYPES.with_loc -> 'b -> 'b
val todo : (string * int * int * int) -> string -> 'b -> 'a -> 'a

Reports a missing folding visitor implementation once. Use __POS__ as first argument

val partial : (string * int * int * int) -> string -> 'a -> 'a

Reports a partial folding visitor implementation once. Use __POS__ as first argument