Commit ff9d5915 authored by POTTIER Francois's avatar POTTIER Francois

Printers: use [print_element_as_symbol] as a default implementation

for [print_element].
parent 6fc6ad8d
* Generate default printers for terminal and nonterminal.
* [Printers] could use [print_element_as_symbol] as the default
value of [print_element].
* IncrementalEngine: document [lr1state], [element], [view].
Document the Inspection interface.
......
......@@ -5,6 +5,7 @@ module Make
val dot: string
val space: string
val print_symbol: I.xsymbol -> string
val print_element: (I.element -> string) option
end)
= struct
......@@ -71,24 +72,36 @@ module Make
let buffer_element_as_symbol =
into_buffer print_element_as_symbol
(* Printing a stack or an environment. These functions are parameterized
over an element printer. [print_element_as_symbol] can be used for
this purpose; but the user can define other printers if desired. *)
(* Some of the functions that follow need an element printer. They use
[print_element] if provided by the user; otherwise they use
[print_element_as_symbol]. *)
let buffer_stack buffer_element b stack =
let print_element =
match print_element with
| Some print_element ->
print_element
| None ->
print_element_as_symbol
let buffer_element =
into_buffer print_element
(* Printing a stack or an environment. *)
let buffer_stack b stack =
I.foldr (fun element () ->
buffer_element b element;
out b space
) stack ()
let buffer_env buffer_element b env =
buffer_stack buffer_element b (I.view env)
let buffer_env b env =
buffer_stack b (I.view env)
let print_stack print_element stack =
with_buffer (buffer_stack (into_buffer print_element)) stack
let print_stack stack =
with_buffer buffer_stack stack
let print_env print_element env =
with_buffer (buffer_env (into_buffer print_element)) env
let print_env env =
with_buffer buffer_env env
end
......@@ -5,6 +5,7 @@ module Make
val dot: string
val space: string
val print_symbol: I.xsymbol -> string
val print_element: (I.element -> string) option
end)
: sig
......@@ -14,15 +15,15 @@ module Make
val buffer_element_as_symbol: Buffer.t -> I.element -> unit
val print_element_as_symbol: I.element -> string
(* Printing a stack or an environment. These functions are parameterized
over an element printer. [print_element_as_symbol] can be used for
this purpose; but the user can define other printers if desired. *)
(* Printing a stack or an environment. These functions need an element
printer. They use [print_element] if provided by the user; otherwise
they use [print_element_as_symbol]. *)
val buffer_stack: (Buffer.t -> I.element -> unit) -> Buffer.t -> I.element I.stream -> unit
val print_stack: (I.element -> string) -> I.element I.stream -> string
val buffer_stack: Buffer.t -> I.element I.stream -> unit
val print_stack: I.element I.stream -> string
val buffer_env: (Buffer.t -> I.element -> unit) -> Buffer.t -> I.env -> unit
val print_env: (I.element -> string) -> I.env -> string
val buffer_env: Buffer.t -> I.env -> unit
val print_env: I.env -> string
(* Printing an item. *)
......
......@@ -31,14 +31,6 @@ let print_symbol symbol =
| X (T T_error) ->
"error"
module P =
Printers.Make(I) (struct
let arrow = " -> "
let dot = "."
let space = " "
let print_symbol = print_symbol
end)
(* A custom element printer. *)
let print_element e : string =
......@@ -69,18 +61,27 @@ let print_element e : string =
| T T_error ->
"error"
(* TEMPORARY comment *)
module P =
Printers.Make(I) (struct
let arrow = " -> "
let dot = "."
let space = " "
let print_symbol = print_symbol
let print_element = Some print_element
end)
(* Debugging. *)
let dump env =
Printf.fprintf stderr "Stack height: %d\n%!" (I.length (I.view env));
Printf.fprintf stderr "Stack view:\n%s\n%!" (P.print_env print_element env);
Printf.fprintf stderr "Stack view:\n%s\n%!" (P.print_env env);
begin match Lazy.force (I.view env) with
| I.Nil ->
()
| I.Cons (I.Element (current, _, _, _), _) ->
Printf.fprintf stderr "Current state: %d\n%!" (Obj.magic current);
let items = I.items current in
Printf.fprintf stderr "#Items: %d\n%!" (List.length items);
List.iter (fun item ->
Printf.fprintf stderr "%s\n%!" (P.print_item item)
) items
......
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