ErrorReporting.mli 2.93 KB
Newer Older
1 2
(* This module is part of MenhirLib. *)

3
module Make
4
  (I : IncrementalEngine.EVERYTHING)
5 6 7 8 9 10 11 12 13 14 15 16 17 18
  (User : sig

    (* In order to submit artificial tokens to the parser, we need a function
       that converts a terminal symbol to a token. Unfortunately, we cannot
       (in general) auto-generate this code, because it requires making up
       semantic values of arbitrary OCaml types. *)

    val terminal2token: _ I.terminal -> I.token

  end)
: sig

  open I

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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
  (* An explanation is a description of what the parser has recognized in the
     recent past and what it expects next. More precisely, an explanation is
     an LR(0) item, enriched with positions. Indeed, the past (the first half
     of the item's right-hand side, up to the bullet) corresponds to a part of
     the input that has been read already, so it can be annotated with
     positions. *)

  type explanation

  (* The LR(0) item. *)

  val item: explanation -> item

  (* The past. This is a non-empty sequence of (terminal and non-terminal)
     symbols, each of which corresponds to a range of the input file. These
     symbols correspond to the first half (up to the bullet) of the item's
     right-hand side. In short, they represent what (we think) we have
     recognized in the recent past. *)

  (* It is worth noting that, when an error occurs, we produce multiple
     explanations, which may have different pasts. Indeed, not only may
     these pasts have different lengths (one may be a suffix of another),
     but two pasts can in fact be incomparable. Indeed, different choices
     of the lookahead token may cause different reductions, hence different
     interpretations of what has been read in the past. *)

  val past: explanation -> (xsymbol * Lexing.position * Lexing.position) list

  (* The future. This is a non-empty sequence of (terminal and non-terminal)
     symbols. These symbols correspond to the second half (after the bullet)
     of the item's right-hand side. In short, they represent what we expect
     to recognize in the future, if this item is a good prediction. *)

  (* This information can be computed from [item]. This function is provided
     only for convenience. *)

  val future: explanation -> xsymbol list

  (* A goal. This is a non-terminal symbol. It is the item's left-hand side.
     In short, it represents the reduction that we will be able to perform if
     we successfully recognize this future. *)

  (* This information can be computed from [item]. This function is provided
     only for convenience. *)

  val goal: explanation -> xsymbol
65 66 67

  (* TEMPORARY *)

68 69 70 71
  (* We build lists of explanations. These explanations may originate in
     distinct LR(1) states. They may have different pasts, because  *)

  exception Error of (Lexing.position * Lexing.position) * explanation list
72 73 74

  (* TEMPORARY *)

75 76
  type reader =
    unit -> token * Lexing.position * Lexing.position
77 78 79 80

  val entry: 'a I.result -> (Lexing.lexbuf -> token) -> Lexing.lexbuf -> 'a

end