aboutsummaryrefslogtreecommitdiff
path: root/gramlib/plexing.mli
diff options
context:
space:
mode:
authorEmilio Jesus Gallego Arias2018-10-07 07:01:05 +0200
committerEmilio Jesus Gallego Arias2018-10-29 01:25:34 +0100
commit503fa442869978a9e19e738be990ea8c7534962e (patch)
tree16e1a42ff9955a80ac6bd1b2302992516b6840ee /gramlib/plexing.mli
parent06979f87959866e6ed1214e745893dcd2e8ddbb3 (diff)
[camlp5] Automatic conversion from revised syntax + parsers
`for i in *; do camlp5r pr_o.cmo $i > ../gramlib.auto/$i; done`
Diffstat (limited to 'gramlib/plexing.mli')
-rw-r--r--gramlib/plexing.mli85
1 files changed, 25 insertions, 60 deletions
diff --git a/gramlib/plexing.mli b/gramlib/plexing.mli
index f0a03da583..6b5f718bc3 100644
--- a/gramlib/plexing.mli
+++ b/gramlib/plexing.mli
@@ -8,7 +8,7 @@
grammars (see module [Grammar]). It also provides some useful functions
to create lexers. *)
-type pattern = (string * string);
+type pattern = string * string
(* Type for values used by the generated code of the EXTEND
statement to represent terminals in entry rules.
- The first string is the constructor name (must start with
@@ -19,61 +19,27 @@ type pattern = (string * string);
- The way tokens patterns are interpreted to parse tokens is done
by the lexer, function [tok_match] below. *)
-exception Error of string;
+exception Error of string
(** A lexing error exception to be used by lexers. *)
(** Lexer type *)
-type lexer 'te =
- { tok_func : lexer_func 'te;
+type 'te lexer =
+ { tok_func : 'te lexer_func;
tok_using : pattern -> unit;
tok_removing : pattern -> unit;
- tok_match : mutable pattern -> 'te -> string;
+ mutable tok_match : pattern -> 'te -> string;
tok_text : pattern -> string;
- tok_comm : mutable option (list Ploc.t) }
- (** The type for lexers compatible with camlp5 grammars. The parameter
- type ['te] is the type of the tokens.
-- The field [tok_func] is the main lexer function. See [lexer_func]
- type below.
-- The field [tok_using] is a function called by the [EXTEND]
- statement to warn the lexer that a rule uses this pattern
- (given as parameter). This allow the lexer 1/ to check that
- the pattern constructor is really among its possible constructors
- 2/ to enter the keywords in its tables.
-- The field [tok_removing] is a function possibly called by the
- [DELETE_RULE] statement to warn the lexer that this pattern
- (given as parameter) is no more used in the grammar (the grammar
- system maintains a number of usages of all patterns and calls this
- function when this number falls to zero). If it is a keyword, this
- allow the lexer to remove it in its tables.
-- The field [tok_match] is a function called by the camlp5
- grammar system to ask the lexer how the input tokens have to
- be matched against the patterns. Warning: for efficiency, this
- function has to be written as a function taking patterns as
- parameters and, for each pattern value, returning a function
- matching a token, *not* as a function with two parameters.
-- The field [tok_text] is a function called by the grammar
- system to get the name of the tokens for the error messages,
- in case of syntax error, or for the displaying of the rules
- of an entry.
-- The field [tok_comm] is a mutable place where the lexer can
- put the locations of the comments, if its initial value is not
- [None]. If it is [None], nothing has to be done by the lexer. *)
-
-and lexer_func 'te = Stream.t char -> (Stream.t 'te * location_function)
- (** The type of a lexer function (field [tok_func] of the type
- [glexer]). The character stream is the input stream to be
- lexed. The result is a pair of a token stream and a location
- function (see below) for this tokens stream. *)
-
-and location_function = int -> Ploc.t;
+ mutable tok_comm : Ploc.t list option }
+and 'te lexer_func = char Stream.t -> 'te Stream.t * location_function
+and location_function = int -> Ploc.t
(** The type of a function giving the location of a token in the
source from the token number in the stream (starting from zero). *)
-value lexer_text : pattern -> string;
+val lexer_text : pattern -> string
(** A simple [tok_text] function. *)
-value default_match : pattern -> (string * string) -> string;
+val default_match : pattern -> string * string -> string
(** A simple [tok_match] function, appling to the token type
[(string * string)] *)
@@ -95,35 +61,35 @@ value default_match : pattern -> (string * string) -> string;
[tok_removing], [tok_match] and [tok_text] may have other implementations
as well. *)
-value lexer_func_of_parser :
- ((Stream.t char * ref int * ref int) -> ('te * Ploc.t)) -> lexer_func 'te;
+val lexer_func_of_parser :
+ (char Stream.t * int ref * int ref -> 'te * Ploc.t) -> 'te lexer_func
(** A lexer function from a lexer written as a char stream parser
returning the next token and its location. The two references
with the char stream contain the current line number and the
position of the beginning of the current line. *)
-value lexer_func_of_ocamllex : (Lexing.lexbuf -> 'te) -> lexer_func 'te;
+val lexer_func_of_ocamllex : (Lexing.lexbuf -> 'te) -> 'te lexer_func
(** A lexer function from a lexer created by [ocamllex] *)
(** Function to build a stream and a location function *)
-value make_stream_and_location :
- (unit -> ('te * Ploc.t)) -> (Stream.t 'te * location_function);
+val make_stream_and_location :
+ (unit -> 'te * Ploc.t) -> 'te Stream.t * location_function
(** General function *)
(** Useful functions and values *)
-value eval_char : string -> char;
-value eval_string : Ploc.t -> string -> string;
+val eval_char : string -> char
+val eval_string : Ploc.t -> string -> string
(** Convert a char or a string token, where the backslashes had not
been interpreted into a real char or string; raise [Failure] if
bad backslash sequence found; [Plexing.eval_char (Char.escaped c)]
would return [c] and [Plexing.eval_string (String.escaped s)] would
return [s] *)
-value restore_lexing_info : ref (option (int * int));
-value input_file : ref string;
-value line_nb : ref (ref int);
-value bol_pos : ref (ref int);
+val restore_lexing_info : (int * int) option ref
+val input_file : string ref
+val line_nb : int ref ref
+val bol_pos : int ref ref
(** Special variables used to reinitialize line numbers and position
of beginning of line with their correct current values when a parser
is called several times with the same character stream. Necessary
@@ -135,9 +101,8 @@ value bol_pos : ref (ref int);
module Lexbuf :
sig
- type t = 'a;
- value empty : t;
- value add : char -> t -> t;
- value get : t -> string;
+ type t
+ val empty : t
+ val add : char -> t -> t
+ val get : t -> string
end
-;