Commit 129fc0f9 authored by POTTIER Francois's avatar POTTIER Francois

New function [top] in the incremental API.

Mark the type [stack] and the function [stack] as deprecated.
parent 6ac6cac4
......@@ -652,6 +652,10 @@ module Make (T : TABLE) = struct
value associated with (the incoming symbol of) this state. Note that the
type [element] is an existential type. *)
(* As of 2017/03/31, the type [stack] and the function [stack] are DEPRECATED.
If desired, they could now be implemented outside Menhir, by relying on
the functions [top] and [pop]. *)
type element =
| Element: 'a lr1state * 'a * position * position -> element
......@@ -694,6 +698,18 @@ module Make (T : TABLE) = struct
let stack env : element stream =
stack env.stack env.current
(* As explained above, the function [top] allows access to the top stack
element only if the stack is nonempty, i.e., only if the current state
is not an initial state. *)
let top env : element option =
let cell = env.stack in
let next = cell.next in
if next == cell then
None
else
Some (Element (env.current, cell.semv, cell.startp, cell.endp))
(* ------------------------------------------------------------------------ *)
(* Access to the position of the lookahead token. *)
......
......@@ -248,7 +248,11 @@ module type INCREMENTAL_ENGINE = sig
(* The parser's stack is (or, more precisely, can be viewed as) a stream of
elements. The type [stream] is defined by the module [General]. *)
type stack =
(* As of 2017/03/31, the type [stack] and the function [stack] are DEPRECATED.
They might be removed in the future. An alternative way of inspecting the
stack is via the functions [top] and [pop]. *)
type stack = (* DEPRECATED *)
element stream
(* This is the parser's stack, a stream of elements. This stream is empty if
......@@ -256,7 +260,12 @@ module type INCREMENTAL_ENGINE = sig
automaton's current state is the one found in the top element of the
stack. *)
val stack: 'a env -> stack
val stack: 'a env -> stack (* DEPRECATED *)
(* [top env] returns the parser's top stack cell. If the stack is empty,
[None] is returned. *)
val top: 'a env -> element option
(* These are the start and end positions of the current lookahead token. If
invoked in an initial state, this function returns a pair of twice the
......
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