From 69749d7686f7a7272e51db1680e8563a51bc635d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pottier?= Date: Wed, 29 Mar 2017 10:53:26 +0200 Subject: [PATCH] In [IncrementalEngine] and in the documentation, use [position] as a synonym for [Lexing.position]. --- doc/main.tex | 13 ++++++++----- src/IncrementalEngine.ml | 14 ++++++++------ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/doc/main.tex b/doc/main.tex index 67dda36f..40cf53e9 100644 --- a/doc/main.tex +++ b/doc/main.tex @@ -2125,11 +2125,14 @@ the name of the start symbol.) The generated file \texttt{parser.mli} contains the following declaration: \begin{verbatim} module Incremental : sig - val main: Lexing.position -> thing MenhirInterpreter.checkpoint + val main: position -> thing MenhirInterpreter.checkpoint end \end{verbatim} The argument is the initial position. If the lexer is based on an OCaml lexing buffer, this argument should be \verb+lexbuf.lex_curr_p+. +In \sref{sec:incremental} and \sref{sec:inspection}, +the type \verb+position+ is a synonym for \verb+Lexing.position+. + We emphasize that the function \verb+Incremental.main+ does not parse anything. It constructs a checkpoint which serves as a \emph{starting} point. The functions \verb+offer+ and \verb+resume+, described below, are used @@ -2217,7 +2220,7 @@ transitions and possibly handle errors in a different manner, if desired. \begin{verbatim} val offer: 'a checkpoint -> - token * Lexing.position * Lexing.position -> + token * position * position -> 'a checkpoint \end{verbatim} @@ -2256,7 +2259,7 @@ give a few more type definitions. \begin{verbatim} type supplier = - unit -> token * Lexing.position * Lexing.position + unit -> token * position * position \end{verbatim} A token supplier is a function of no arguments which delivers a new token @@ -2347,7 +2350,7 @@ The states of the LR(1) automaton are numbered (from 0 and up). \begin{verbatim} type element = - | Element: 'a lr1state * 'a * Lexing.position * Lexing.position -> element + | Element: 'a lr1state * 'a * position * position -> element \end{verbatim} The type \verb+element+ describes one entry in the stack of the LR(1) @@ -2396,7 +2399,7 @@ constant time. %% val positions \begin{verbatim} - val positions: env -> Lexing.position * Lexing.position + val positions: env -> position * position \end{verbatim} The function \verb+positions+ returns the start and end positions of the diff --git a/src/IncrementalEngine.ml b/src/IncrementalEngine.ml index 4b8c44b1..27c79f97 100644 --- a/src/IncrementalEngine.ml +++ b/src/IncrementalEngine.ml @@ -11,6 +11,8 @@ (* *) (******************************************************************************) +type position = Lexing.position + open General (* This signature describes the incremental LR engine. *) @@ -78,7 +80,7 @@ module type INCREMENTAL_ENGINE = sig val offer: 'a checkpoint -> - token * Lexing.position * Lexing.position -> + token * position * position -> 'a checkpoint (* [resume] allows the user to resume the parser after it has suspended @@ -94,7 +96,7 @@ module type INCREMENTAL_ENGINE = sig (together with its start and end positions) every time it is called. *) type supplier = - unit -> token * Lexing.position * Lexing.position + unit -> token * position * position (* A pair of a lexer and a lexing buffer can be easily turned into a supplier. *) @@ -180,7 +182,7 @@ module type INCREMENTAL_ENGINE = sig hypothetical token, and may be picked up by the semantic actions. We suggest using the position where the error was detected. *) - val acceptable: 'a checkpoint -> token -> Lexing.position -> bool + val acceptable: 'a checkpoint -> token -> position -> bool (* [pop env] returns a new environment, where the parser's top stack cell has been popped off. (If the stack is empty, [None] is returned.) This @@ -236,7 +238,7 @@ module type INCREMENTAL_ENGINE = sig has type ['a]. In other words, the type [element] is an existential type. *) type element = - | Element: 'a lr1state * 'a * Lexing.position * Lexing.position -> element + | Element: 'a lr1state * 'a * position * position -> element (* 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]. *) @@ -255,7 +257,7 @@ module type INCREMENTAL_ENGINE = sig invoked in an initial state, this function returns a pair of twice the initial position. *) - val positions: 'a env -> Lexing.position * Lexing.position + val positions: 'a env -> position * position (* This tells whether the parser is about to perform a default reduction. In particular, when applied to an environment taken from a result of @@ -391,7 +393,7 @@ module type INSPECTION = sig determined by [env]) has an outgoing transition labeled with [symbol]. Otherwise, [Invalid_argument _] is raised. *) - val feed: 'a symbol -> Lexing.position -> 'a -> Lexing.position -> 'b env -> 'b env + val feed: 'a symbol -> position -> 'a -> position -> 'b env -> 'b env end -- 2.22.0