Commit d1df6b87 authored by POTTIER Francois's avatar POTTIER Francois

Replaced [error_state] with [current_state_number],

which is more general, as it takes an [env].
parent b70e708d
......@@ -718,12 +718,8 @@ module Make (T : TABLE) = struct
env1.stack == env2.stack &&
number env1.current = number env2.current
let error_state checkpoint =
match checkpoint with
| HandlingError env ->
number env.current
| _ ->
invalid_arg "error_state expects HandlingError"
let current_state_number env =
number env.current
(* ------------------------------------------------------------------------ *)
......
......@@ -281,14 +281,13 @@ module type INCREMENTAL_ENGINE = sig
val get: int -> 'a env -> element option
(* [error_state checkpoint] requires [checkpoint] to be of the form
[HandlingError env]. Out of [env], it extracts the automaton's current
state, and returns this state, as an integer number. (This works even if
the automaton's stack is empty, in which case the current state is an
initial state.) This number can then be used as an argument to a
[message] function that was generated by [menhir --compile-errors]. *)
val error_state: 'a checkpoint -> int
(* [current_state_number env] returns (the integer number of) the automaton's
current state. This works even if the automaton's stack is empty, in which
case the current state is an initial state. This number can be used as an
argument to a [message] function that was generated by [menhir
--compile-errors]. *)
val current_state_number: 'a env -> int
(* [equal env1 env2] tells whether the parser configurations [env1] and
[env2] are equal in the sense that the automaton's current state is
......
......@@ -22,10 +22,10 @@ open Parser.MenhirInterpreter (* incremental API to our parser *)
(* [fail] is invoked if a syntax error is encountered. *)
let fail lexbuf checkpoint =
let fail lexbuf env =
(* The parser has suspended itself because of a syntax error. Stop.
Find out which state the parser is currently in. *)
let s : int = error_state checkpoint in
let s : int = current_state_number env in
(* Display a nice error message. In principle, the table found in
[ParserMessages] should be complete, so we should obtain
a nice message. If [Not_found] is raised, we produce a generic
......@@ -43,6 +43,13 @@ let fail lexbuf checkpoint =
(* Display our message and die. *)
Error.error (Positions.lexbuf lexbuf) "syntax error.\n%s" message
let fail lexbuf checkpoint =
match checkpoint with
| HandlingError env ->
fail lexbuf env
| _ ->
assert false (* this cannot happen *)
(* The entry point. *)
let grammar lexer lexbuf =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment