Commit f3825381 authored by POTTIER Francois's avatar POTTIER Francois

Published the existence of the sub-module [MenhirInterpreter] and of

the incremental entry points in the generated [.mli] file.
parent 63ea185c
......@@ -21,17 +21,60 @@ let excredef = {
excdef with exceq = Some excname
}
(* The type of the entry point for the start symbol [symbol]. *)
(* Finding the type of a start symbol. *)
let ocamltype_of_start_symbol symbol =
try
TypTextual (StringMap.find symbol PreFront.grammar.types)
with Not_found ->
(* Every start symbol should have a type. *)
assert false
(* The type of the monolithic entry point for the start symbol [symbol]. *)
let entrytypescheme symbol =
let ocamltype =
try
StringMap.find symbol PreFront.grammar.types
with Not_found ->
(* Every start symbol should have a type. *)
assert false
in
type2scheme (marrow [ arrow tlexbuf ttoken; tlexbuf ] (TypTextual ocamltype))
let typ = ocamltype_of_start_symbol symbol in
type2scheme (marrow [ arrow tlexbuf ttoken; tlexbuf ] typ)
(* When the table back-end is active, the generated parser contains,
as a sub-module, an application of [Engine.Make]. This sub-module
is named as follows. *)
let interpreter =
"MenhirInterpreter"
let result t =
TypApp (interpreter ^ ".result", [ t ])
(* The name of the incremental entry point for the start symbol [symbol]. *)
let incremental symbol =
Misc.normalize symbol ^ "_incremental" (* TEMPORARY better idea? *)
(* The type of the incremental entry point for the start symbol [symbol]. *)
let entrytypescheme_incremental symbol =
let t = ocamltype_of_start_symbol symbol in
type2scheme (marrow [ tunit ] (result t))
(* This is the interface of the generated parser -- only the part
that is specific of the table back-end. *)
let table_interface =
if Settings.table then [
IIModule (
interpreter,
MTWithType (
MTNamedModuleType "MenhirLib.EngineTypes.INCREMENTAL_ENGINE",
tctoken, WKDestructive, ttoken
)
);
IIValDecls (
StringSet.fold (fun symbol decls ->
(incremental symbol, entrytypescheme_incremental symbol) :: decls
) PreFront.grammar.start_symbols []
)
] else []
(* This is the interface of the generated parser. *)
......@@ -44,7 +87,7 @@ let interface = [
(Misc.normalize symbol, entrytypescheme symbol) :: decls
) PreFront.grammar.start_symbols []
)
])
] @ table_interface)
]
(* Writing the interface to a file. *)
......
......@@ -6,11 +6,27 @@ val excname: string
val excdef: IL.excdef
val excredef: IL.excdef
(* The type of the entry point for the nonterminal start symbol
[symbol]. *)
(* The type of the entry point for the start symbol [nt]. *)
val entrytypescheme: string -> IL.typescheme
(* The name of the interpreter sub-module, when the table back-end
is used. *)
val interpreter: string
(* The type ['a result], defined in the interpreter sub-module. *)
val result: IL.typ -> IL.typ
(* The name of the incremental entry point for the start symbol [symbol]. *)
val incremental: string -> string
(* The type of the incremental entry point for the start symbol [symbol]. *)
val entrytypescheme_incremental: string -> IL.typescheme
(* This writes the interface of the generated parser to the [.mli]
file. *)
......
......@@ -55,18 +55,12 @@ let fcurrent =
let ftriple =
field "triple"
let interpreter =
"MenhirInterpreter"
let entry =
interpreter ^ ".entry"
let start =
interpreter ^ ".start"
let result t =
TypApp (interpreter ^ ".result", [ t ])
(* ------------------------------------------------------------------------ *)
(* Code generation for semantic actions. *)
......@@ -726,7 +720,8 @@ let api : IL.valdef list =
) ::
(* The entry point to the incremental API. *)
define (
Nonterminal.print true nt ^ "_incremental", (* TEMPORARY *)
(* [false] is intentional; [incremental] performs normalization *)
incremental (Nonterminal.print false nt),
(* In principle the abstraction [fun () -> ...] should not be
necessary, since [start] is a pure function. However, when
[--trace] is enabled, [start] will log messages to 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