From 2135285b05d90239bd30a5094f8413fddb48df60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pottier?= Date: Thu, 1 Jan 2015 18:06:33 +0100 Subject: [PATCH] Renamed main_incremental to Incremental.main. This guarantees the absence of name clashes. --- CHANGES | 4 ++++ TODO | 8 -------- demos/calc-incremental/calc.ml | 2 +- doc/main.tex | 21 +++++++++++++-------- src/interface.ml | 21 ++++++++++----------- src/interface.mli | 4 ++-- src/tableBackend.ml | 25 ++++++++++++++++++++----- 7 files changed, 50 insertions(+), 35 deletions(-) diff --git a/CHANGES b/CHANGES index 70d5e411..97aa27cb 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +2015/01/01: +Incompatible change of the incremental API. +The entry point main_incremental is now named Incremental.main. + 2014/12/29: Incompatible change of the incremental API. The API now exposes reduction events. diff --git a/TODO b/TODO index 58b9e28e..75436999 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,3 @@ -* Introduce a submodule Incremental for the incremental entry - points. Move also the types terminal, nonterminal, symbol - to a sub-module, to avoid any name clashes. - -* Clean up Interface and tableBackend. Decide whether we need - a new switch (--inspect) for the inspection API. Condition - [terminal], [nonterminal], etc. to this new switch. - * IncrementalEngine: document [lr1state], [element], [view]. * Define MenhirLib.Stream? diff --git a/demos/calc-incremental/calc.ml b/demos/calc-incremental/calc.ml index 480174a8..af9f0b63 100644 --- a/demos/calc-incremental/calc.ml +++ b/demos/calc-incremental/calc.ml @@ -107,7 +107,7 @@ let rec loop linebuf (result : int I.result) = let process (line : string) = let linebuf = Lexing.from_string line in try - loop linebuf (Parser.main_incremental()) + loop linebuf (Parser.Incremental.main()) with | Lexer.Error msg -> Printf.fprintf stderr "%s%!" msg diff --git a/doc/main.tex b/doc/main.tex index aecae517..da0487b0 100644 --- a/doc/main.tex +++ b/doc/main.tex @@ -1797,7 +1797,8 @@ We assume that the grammar specification has just one start symbol \label{sec:monolithic} The monolithic API consists in just one parsing function, named after the -start symbol: +start symbol. The generated file \texttt{parser.mli} contains the following +declaration: \begin{verbatim} val main: (Lexing.lexbuf -> token) -> Lexing.lexbuf -> thing \end{verbatim} @@ -1839,10 +1840,14 @@ $O(n)$ space in memory. % TEMPORARY actually, live parsing also requires a way of performing % error recovery, up to a complete parse... as in Merlin. -In this API, the parser is started by invoking \verb+main_incremental+, -where \mystartsymbol is the name of the start symbol: +In this API, the parser is started by invoking +\texttt{Incremental.\mystartsymbol}. (Recall that we assume \mystartsymbol is +the name of the start symbol.) The generated file \texttt{parser.mli} contains +the following declaration: \begin{verbatim} - val main_incremental: unit -> thing MenhirInterpreter.result + module Incremental : sig + val main: unit -> thing MenhirInterpreter.result + end \end{verbatim} The sub-module \menhirinterpreter is also part of the incremental API. @@ -1932,10 +1937,10 @@ parser has suspended itself with a result of the form This function expects just the previous result \verb+result+. It produces a new result. It does not raise any exception. -The incremental API subsumes the monolithic API. Indeed, \verb+main+ can -be (and is in fact) implemented by first using \verb+main_incremental+, then -calling \verb+offer+ and \verb+resume+ in a loop, until a final result is -obtained. +The incremental API subsumes the monolithic API. Indeed, \mystartsymbol can be +(and is in fact) implemented by first using +\texttt{Incremental.\mystartsymbol}, then calling \verb+offer+ and +\verb+resume+ in a loop, until a final result is obtained. At this time, because the type \verb+env+ is opaque, the state of the parser cannot be inspected by the user. We plan to offer an inspection API in the diff --git a/src/interface.ml b/src/interface.ml index c231d773..2d821ea4 100644 --- a/src/interface.ml +++ b/src/interface.ml @@ -40,13 +40,10 @@ let result t = (* -------------------------------------------------------------------------- *) -(* The name of the incremental entry point for the start symbol [symbol]. *) +(* The name of the sub-module that contains the incremental entry points. *) -let incremental symbol = - (* This convention is not great. A name clash with a non-incremental - entry point is possible if there exists a nonterminal symbol whose name - ends with [_incremental]. It would be preferable to introduce a sub-module. *) - Misc.normalize symbol ^ "_incremental" +let incremental = + "Incremental" (* The type of the incremental entry point for the start symbol [symbol]. *) @@ -93,11 +90,13 @@ let incremental_api grammar () = ) :: IIComment "The entry point(s) to the incremental API." :: - IIValDecls ( - StringSet.fold (fun symbol decls -> - (incremental symbol, entrytypescheme_incremental grammar symbol) :: decls - ) grammar.start_symbols [] - ) :: + IIModule (incremental, MTSigEnd [ + IIValDecls ( + StringSet.fold (fun symbol decls -> + (symbol, entrytypescheme_incremental grammar symbol) :: decls + ) grammar.start_symbols [] + ) + ]) :: [] diff --git a/src/interface.mli b/src/interface.mli index feba24b9..00e506aa 100644 --- a/src/interface.mli +++ b/src/interface.mli @@ -19,9 +19,9 @@ val interpreter: string val result: IL.typ -> IL.typ -(* The name of the incremental entry point for the start symbol [symbol]. *) +(* The name of the sub-module that contains the incremental entry points. *) -val incremental: string -> string +val incremental: string (* This writes the interface of the generated parser to the [.mli] file. *) diff --git a/src/tableBackend.ml b/src/tableBackend.ml index 47dec5a0..0fc2e431 100644 --- a/src/tableBackend.ml +++ b/src/tableBackend.ml @@ -687,7 +687,9 @@ let application = (* ------------------------------------------------------------------------ *) -(* The client API invokes the interpreter with an appropriate start state. *) +(* The client APIs invoke the interpreter with an appropriate start state. + The monolithic API calls [entry] (see [Engine]), while the incremental + API calls [start]. *) (* An entry point to the monolithic API. *) @@ -713,11 +715,19 @@ let monolithic_entry_point state nt t = ) ) +(* The whole monolithic API. *) + +let monolithic_api : IL.valdef list = + Lr1.fold_entry (fun _prod state nt t api -> + monolithic_entry_point state nt t :: + api + ) [] + (* An entry point to the incremental API. *) let incremental_entry_point state nt t = define ( - incremental (Nonterminal.print true nt), + Nonterminal.print true 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 @@ -737,9 +747,10 @@ let incremental_entry_point state nt t = ) ) -let api : IL.valdef list = +(* The whole incremental API. *) + +let incremental_api : IL.valdef list = Lr1.fold_entry (fun _prod state nt t api -> - monolithic_entry_point state nt t :: incremental_entry_point state nt t :: api ) [] @@ -859,7 +870,11 @@ let program = SIModuleDef (interpreter, application) :: - SIValDefs (false, api) :: + SIValDefs (false, monolithic_api) :: + + SIModuleDef (incremental, MStruct [ + SIValDefs (false, incremental_api) + ]) :: listiflazy Settings.inspection (fun () -> -- GitLab