Source file automaton_stack_intf.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
open! Import

(** Automaton stack represents a prefix of a sexp (or of a sexp sequence) while it's being
    parsed.  We have three different types of the stack depending on how much detail about
    the sexp structure is being recorded (just the sexp, sexp with comments and positions
    (CST), or just positions. *)

module type Automaton_stack = sig
  module For_cst : sig
    type t =
      | Empty (** at top-level *)
      | T_or_comment of Cst.t_or_comment * t (** after the given sexp or comment *)
      | Open of Positions.pos * t (** after the opening paren *)
      | In_sexp_comment of
          { hash_semi_pos : Positions.pos
          ; rev_comments : Cst.comment list
          ; stack : t
          }
          (** [In_sexp_comment] only indicates if the next s-expression is to be commented
          out, but if we are nested below parens below an sexp comment, the stack would
          look like [Open (.., In_sexp_comment ..)]. *)

    val empty : t

    (** Raises if [t] contains a partial sexp. *)
    val get_many : t -> Cst.t_or_comment list
  end

  (** The recorded positions are stored elsewhere *)
  module Just_positions : sig
    type t = unit

    val empty : t
  end

  type t =
    | Empty
    | Open of t
    | Sexp of Sexp.t * t

  val empty : t

  (** Raises if [t] is not exactly one complete sexp. *)
  val get_single : t -> Sexp.t

  (** Raises if [t] contains a partial sexp. *)
  val get_many : t -> Sexp.t list
end