]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/ocaml/contrib/camlp4/Camlp4/Sig.ml
Update
[l4.git] / l4 / pkg / ocaml / ocaml / contrib / camlp4 / Camlp4 / Sig.ml
1 (* camlp4r *)
2 (****************************************************************************)
3 (*                                                                          *)
4 (*                              Objective Caml                              *)
5 (*                                                                          *)
6 (*                            INRIA Rocquencourt                            *)
7 (*                                                                          *)
8 (*  Copyright  2006   Institut National de Recherche  en  Informatique et   *)
9 (*  en Automatique.  All rights reserved.  This file is distributed under   *)
10 (*  the terms of the GNU Library General Public License, with the special   *)
11 (*  exception on linking described in LICENSE at the top of the Objective   *)
12 (*  Caml source tree.                                                       *)
13 (*                                                                          *)
14 (****************************************************************************)
15
16 (* Authors:
17  * - Daniel de Rauglaudre: initial version
18  * - Nicolas Pouillard: refactoring
19  *)
20
21
22
23 (** Camlp4 signature repository *)
24
25 (** {6 Basic signatures} *)
26
27 (** Signature with just a type. *)
28 module type Type = sig
29   type t;
30 end;
31
32 (** Signature for errors modules, an Error modules can be registred with
33     the {!ErrorHandler.Register} functor in order to be well printed. *)
34 module type Error = sig
35   type t;
36   exception E of t;
37   value to_string : t -> string;
38   value print : Format.formatter -> t -> unit;
39 end;
40
41 (** A signature for extensions identifiers. *)
42 module type Id = sig
43
44   (** The name of the extension, typically the module name. *)
45   value name    : string;
46
47   (** The version of the extension, typically $ Id$ with a versionning system. *)
48   value version : string;
49
50 end;
51
52 (** A signature for warnings abstract from locations. *)
53 module Warning (Loc : Type) = struct
54   module type S = sig
55     type warning = Loc.t -> string -> unit;
56     value default_warning : warning;
57     value current_warning : ref warning;
58     value print_warning   : warning;
59   end;
60 end;
61
62 (** {6 Advanced signatures} *)
63
64 (** A signature for locations. *)
65 module type Loc = sig
66
67   type t;
68
69   (** Return a start location for the given file name.
70       This location starts at the begining of the file. *)
71   value mk : string -> t;
72
73   (** The [ghost] location can be used when no location
74       information is available. *)
75   value ghost : t;
76
77   (** {6 Conversion functions} *)
78
79   (** Return a location where both positions are set the given position. *)
80   value of_lexing_position : Lexing.position -> t;
81
82   (** Return an OCaml location. *)
83   value to_ocaml_location : t -> Camlp4_import.Location.t;
84
85   (** Return a location from an OCaml location. *)
86   value of_ocaml_location : Camlp4_import.Location.t -> t;
87
88   (** Return a location from ocamllex buffer. *)
89   value of_lexbuf : Lexing.lexbuf -> t;
90
91   (** Return a location from [(file_name, start_line, start_bol, start_off,
92       stop_line,  stop_bol,  stop_off, ghost)]. *)
93   value of_tuple : (string * int * int * int * int * int * int * bool) -> t;
94
95   (** Return [(file_name, start_line, start_bol, start_off,
96       stop_line,  stop_bol,  stop_off, ghost)]. *)
97   value to_tuple : t -> (string * int * int * int * int * int * int * bool);
98
99   (** [merge loc1 loc2] Return a location that starts at [loc1] and end at [loc2]. *)
100   value merge : t -> t -> t;
101
102   (** The stop pos becomes equal to the start pos. *)
103   value join : t -> t;
104
105   (** [move selector n loc]
106       Return the location where positions are moved.
107       Affected positions are chosen with [selector].
108       Returned positions have their character offset plus [n]. *)
109   value move : [= `start | `stop | `both ] -> int -> t -> t;
110
111   (** [shift n loc] Return the location where the new start position is the old
112       stop position, and where the new stop position character offset is the
113       old one plus [n]. *)
114   value shift : int -> t -> t;
115
116   (** [move_line n loc] Return the location with the old line count plus [n].
117       The "begin of line" of both positions become the current offset. *)
118   value move_line : int -> t -> t;
119
120   (** {6 Accessors} *)
121
122   (** Return the file name *)
123   value file_name  : t -> string;
124
125   (** Return the line number of the begining of this location. *)
126   value start_line : t -> int;
127
128   (** Return the line number of the ending of this location. *)
129   value stop_line  : t -> int;
130
131   (** Returns the number of characters from the begining of the file
132       to the begining of the line of location's begining. *)
133   value start_bol  : t -> int;
134
135   (** Returns the number of characters from the begining of the file
136       to the begining of the line of location's ending. *)
137   value stop_bol   : t -> int;
138
139   (** Returns the number of characters from the begining of the file
140       of the begining of this location. *)
141   value start_off  : t -> int;
142
143   (** Return the number of characters from the begining of the file
144       of the ending of this location. *)
145   value stop_off   : t -> int;
146
147   (** Return the start position as a Lexing.position. *)
148   value start_pos  : t -> Lexing.position;
149
150   (** Return the stop position as a Lexing.position. *)
151   value stop_pos   : t -> Lexing.position;
152
153   (** Generally, return true if this location does not come
154       from an input stream. *)
155   value is_ghost   : t -> bool;
156
157   (** Return the associated ghost location. *)
158   value ghostify   : t -> t;
159
160   (** Return the location with the give file name *)
161   value set_file_name : string -> t -> t;
162
163   (** [strictly_before loc1 loc2] True if the stop position of [loc1] is
164       strictly_before the start position of [loc2]. *)
165   value strictly_before : t -> t -> bool;
166
167   (** Return the location with an absolute file name. *)
168   value make_absolute : t -> t;
169
170   (** Print the location into the formatter in a format suitable for error
171       reporting. *)
172   value print : Format.formatter -> t -> unit;
173
174   (** Print the location in a short format useful for debugging. *)
175   value dump  : Format.formatter -> t -> unit;
176
177   (** Same as {!print} but return a string instead of printting it. *)
178   value to_string : t -> string;
179
180   (** [Exc_located loc e] is an encapsulation of the exception [e] with
181       the input location [loc]. To be used in quotation expanders
182       and in grammars to specify some input location for an error.
183       Do not raise this exception directly: rather use the following
184       function [Loc.raise]. *)
185   exception Exc_located of t and exn;
186
187   (** [raise loc e], if [e] is already an [Exc_located] exception,
188       re-raise it, else raise the exception [Exc_located loc e]. *)
189   value raise : t -> exn -> 'a;
190
191   (** The name of the location variable used in grammars and in
192       the predefined quotations for OCaml syntax trees. Default: [_loc]. *)
193   value name : ref string;
194
195 end;
196
197 (** Abstract syntax tree minimal signature.
198     Types of this signature are abstract.
199     See the {!Camlp4Ast} signature for a concrete definition. *)
200 module type Ast = sig
201
202   (** {6 Syntactic categories as abstract types} *)
203
204   type loc;
205   type meta_bool;
206   type meta_option 'a;
207   type meta_list 'a;
208   type ctyp;
209   type patt;
210   type expr;
211   type module_type;
212   type sig_item;
213   type with_constr;
214   type module_expr;
215   type str_item;
216   type class_type;
217   type class_sig_item;
218   type class_expr;
219   type class_str_item;
220   type match_case;
221   type ident;
222   type binding;
223   type rec_binding;
224   type module_binding;
225
226   (** {6 Location accessors} *)
227
228   value loc_of_ctyp : ctyp -> loc;
229   value loc_of_patt : patt -> loc;
230   value loc_of_expr : expr -> loc;
231   value loc_of_module_type : module_type -> loc;
232   value loc_of_module_expr : module_expr -> loc;
233   value loc_of_sig_item : sig_item -> loc;
234   value loc_of_str_item : str_item -> loc;
235   value loc_of_class_type : class_type -> loc;
236   value loc_of_class_sig_item : class_sig_item -> loc;
237   value loc_of_class_expr : class_expr -> loc;
238   value loc_of_class_str_item : class_str_item -> loc;
239   value loc_of_with_constr : with_constr -> loc;
240   value loc_of_binding : binding -> loc;
241   value loc_of_rec_binding : rec_binding -> loc;
242   value loc_of_module_binding : module_binding -> loc;
243   value loc_of_match_case : match_case -> loc;
244   value loc_of_ident : ident -> loc;
245
246   (** {6 Traversals} *)
247
248   (** This class is the base class for map traversal on the Ast.
249       To make a custom traversal class one just extend it like that:
250       
251       This example swap pairs expression contents:
252       open Camlp4.PreCast;
253       [class swap = object
254         inherit Ast.map as super;
255         method expr e =
256           match super#expr e with
257           \[ <:expr\@_loc< ($e1$, $e2$) >> -> <:expr< ($e2$, $e1$) >>
258           | e -> e \];
259       end;
260       value _loc = Loc.ghost;
261       value map = (new swap)#expr;
262       assert (map <:expr< fun x -> (x, 42) >> = <:expr< fun x -> (42, x) >>);]
263   *)
264   class map : object ('self_type)
265     method string : string -> string;
266     method list : ! 'a 'b . ('self_type -> 'a -> 'b) -> list 'a -> list 'b;
267     method meta_bool : meta_bool -> meta_bool;
268     method meta_option : ! 'a 'b . ('self_type -> 'a -> 'b) -> meta_option 'a -> meta_option 'b;
269     method meta_list : ! 'a 'b . ('self_type -> 'a -> 'b) -> meta_list 'a -> meta_list 'b;
270     method loc : loc -> loc;
271     method expr : expr -> expr;
272     method patt : patt -> patt;
273     method ctyp : ctyp -> ctyp;
274     method str_item : str_item -> str_item;
275     method sig_item : sig_item -> sig_item;
276
277     method module_expr : module_expr -> module_expr;
278     method module_type : module_type -> module_type;
279     method class_expr : class_expr -> class_expr;
280     method class_type : class_type -> class_type;
281     method class_sig_item : class_sig_item -> class_sig_item;
282     method class_str_item : class_str_item -> class_str_item;
283     method with_constr : with_constr -> with_constr;
284     method binding : binding -> binding;
285     method rec_binding : rec_binding -> rec_binding;
286     method module_binding : module_binding -> module_binding;
287     method match_case : match_case -> match_case;
288     method ident : ident -> ident;
289
290     method unknown : ! 'a. 'a -> 'a;
291   end;
292
293   (** Fold style traversal *)
294   class fold : object ('self_type)
295     method string : string -> 'self_type;
296     method list : ! 'a . ('self_type -> 'a -> 'self_type) -> list 'a -> 'self_type;
297     method meta_bool : meta_bool -> 'self_type;
298     method meta_option : ! 'a . ('self_type -> 'a -> 'self_type) -> meta_option 'a -> 'self_type;
299     method meta_list : ! 'a . ('self_type -> 'a -> 'self_type) -> meta_list 'a -> 'self_type;
300     method loc : loc -> 'self_type;
301     method expr : expr -> 'self_type;
302     method patt : patt -> 'self_type;
303     method ctyp : ctyp -> 'self_type;
304     method str_item : str_item -> 'self_type;
305     method sig_item : sig_item -> 'self_type;
306     method module_expr : module_expr -> 'self_type;
307     method module_type : module_type -> 'self_type;
308     method class_expr : class_expr -> 'self_type;
309     method class_type : class_type -> 'self_type;
310     method class_sig_item : class_sig_item -> 'self_type;
311     method class_str_item : class_str_item -> 'self_type;
312     method with_constr : with_constr -> 'self_type;
313     method binding : binding -> 'self_type;
314     method rec_binding : rec_binding -> 'self_type;
315     method module_binding : module_binding -> 'self_type;
316     method match_case : match_case -> 'self_type;
317     method ident : ident -> 'self_type;
318
319     method unknown : ! 'a. 'a -> 'self_type;
320   end;
321
322 end;
323
324
325 (** Signature for OCaml syntax trees. *) (*
326     This signature is an extension of {!Ast}
327     It provides:
328       - Types for all kinds of structure.
329       - Map: A base class for map traversals.
330       - Map classes and functions for common kinds.
331
332     == Core language ==
333     ctyp               :: Representaion of types
334     patt               :: The type of patterns
335     expr               :: The type of expressions
336     match_case         :: The type of cases for match/function/try constructions
337     ident              :: The type of identifiers (including path like Foo(X).Bar.y)
338     binding            :: The type of let bindings
339     rec_binding        :: The type of record definitions
340
341     == Modules ==
342     module_type        :: The type of module types
343     sig_item           :: The type of signature items
344     str_item           :: The type of structure items
345     module_expr        :: The type of module expressions
346     module_binding     :: The type of recursive module definitions
347     with_constr        :: The type of `with' constraints
348
349     == Classes ==
350     class_type         :: The type of class types
351     class_sig_item     :: The type of class signature items
352     class_expr         :: The type of class expressions
353     class_str_item     :: The type of class structure items
354  *)
355 module type Camlp4Ast = sig
356
357   (** The inner module for locations *)
358   module Loc : Loc;
359
360   INCLUDE "camlp4/Camlp4/Camlp4Ast.partial.ml";
361
362   value loc_of_ctyp : ctyp -> loc;
363   value loc_of_patt : patt -> loc;
364   value loc_of_expr : expr -> loc;
365   value loc_of_module_type : module_type -> loc;
366   value loc_of_module_expr : module_expr -> loc;
367   value loc_of_sig_item : sig_item -> loc;
368   value loc_of_str_item : str_item -> loc;
369   value loc_of_class_type : class_type -> loc;
370   value loc_of_class_sig_item : class_sig_item -> loc;
371   value loc_of_class_expr : class_expr -> loc;
372   value loc_of_class_str_item : class_str_item -> loc;
373   value loc_of_with_constr : with_constr -> loc;
374   value loc_of_binding : binding -> loc;
375   value loc_of_rec_binding : rec_binding -> loc;
376   value loc_of_module_binding : module_binding -> loc;
377   value loc_of_match_case : match_case -> loc;
378   value loc_of_ident : ident -> loc;
379
380   module Meta : sig
381     module type META_LOC = sig
382       (* The first location is where to put the returned pattern.
383           Generally it's _loc to match with <:patt< ... >> quotations.
384           The second location is the one to treat. *)
385       value meta_loc_patt : loc -> loc -> patt;
386       (* The first location is where to put the returned expression.
387           Generally it's _loc to match with <:expr< ... >> quotations.
388           The second location is the one to treat. *)
389       value meta_loc_expr : loc -> loc -> expr;
390     end;
391     module MetaLoc : sig
392       value meta_loc_patt : loc -> loc -> patt;
393       value meta_loc_expr : loc -> loc -> expr;
394     end;
395     module MetaGhostLoc : sig
396       value meta_loc_patt : loc -> 'a -> patt;
397       value meta_loc_expr : loc -> 'a -> expr;
398     end;
399     module MetaLocVar : sig
400       value meta_loc_patt : loc -> 'a -> patt;
401       value meta_loc_expr : loc -> 'a -> expr;
402     end;
403     module Make (MetaLoc : META_LOC) : sig
404       module Expr : sig
405         value meta_string : loc -> string -> expr;
406         value meta_int : loc -> string -> expr;
407         value meta_float : loc -> string -> expr;
408         value meta_char : loc -> string -> expr;
409         value meta_bool : loc -> bool -> expr;
410         value meta_list : (loc -> 'a -> expr) -> loc -> list 'a -> expr;
411         value meta_binding : loc -> binding -> expr;
412         value meta_rec_binding : loc -> rec_binding -> expr;
413         value meta_class_expr : loc -> class_expr -> expr;
414         value meta_class_sig_item : loc -> class_sig_item -> expr;
415         value meta_class_str_item : loc -> class_str_item -> expr;
416         value meta_class_type : loc -> class_type -> expr;
417         value meta_ctyp : loc -> ctyp -> expr;
418         value meta_expr : loc -> expr -> expr;
419         value meta_ident : loc -> ident -> expr;
420         value meta_match_case : loc -> match_case -> expr;
421         value meta_module_binding : loc -> module_binding -> expr;
422         value meta_module_expr : loc -> module_expr -> expr;
423         value meta_module_type : loc -> module_type -> expr;
424         value meta_patt : loc -> patt -> expr;
425         value meta_sig_item : loc -> sig_item -> expr;
426         value meta_str_item : loc -> str_item -> expr;
427         value meta_with_constr : loc -> with_constr -> expr;
428       end;
429       module Patt : sig
430         value meta_string : loc -> string -> patt;
431         value meta_int : loc -> string -> patt;
432         value meta_float : loc -> string -> patt;
433         value meta_char : loc -> string -> patt;
434         value meta_bool : loc -> bool -> patt;
435         value meta_list : (loc -> 'a -> patt) -> loc -> list 'a -> patt;
436         value meta_binding : loc -> binding -> patt;
437         value meta_rec_binding : loc -> rec_binding -> patt;
438         value meta_class_expr : loc -> class_expr -> patt;
439         value meta_class_sig_item : loc -> class_sig_item -> patt;
440         value meta_class_str_item : loc -> class_str_item -> patt;
441         value meta_class_type : loc -> class_type -> patt;
442         value meta_ctyp : loc -> ctyp -> patt;
443         value meta_expr : loc -> expr -> patt;
444         value meta_ident : loc -> ident -> patt;
445         value meta_match_case : loc -> match_case -> patt;
446         value meta_module_binding : loc -> module_binding -> patt;
447         value meta_module_expr : loc -> module_expr -> patt;
448         value meta_module_type : loc -> module_type -> patt;
449         value meta_patt : loc -> patt -> patt;
450         value meta_sig_item : loc -> sig_item -> patt;
451         value meta_str_item : loc -> str_item -> patt;
452         value meta_with_constr : loc -> with_constr -> patt;
453       end;
454     end;
455   end;
456
457   (** See {!Ast.map}. *)
458   class map : object ('self_type)
459     method string : string -> string;
460     method list : ! 'a 'b . ('self_type -> 'a -> 'b) -> list 'a -> list 'b;
461     method meta_bool : meta_bool -> meta_bool;
462     method meta_option : ! 'a 'b . ('self_type -> 'a -> 'b) -> meta_option 'a -> meta_option 'b;
463     method meta_list : ! 'a 'b . ('self_type -> 'a -> 'b) -> meta_list 'a -> meta_list 'b;
464     method loc : loc -> loc;
465     method expr : expr -> expr;
466     method patt : patt -> patt;
467     method ctyp : ctyp -> ctyp;
468     method str_item : str_item -> str_item;
469     method sig_item : sig_item -> sig_item;
470
471     method module_expr : module_expr -> module_expr;
472     method module_type : module_type -> module_type;
473     method class_expr : class_expr -> class_expr;
474     method class_type : class_type -> class_type;
475     method class_sig_item : class_sig_item -> class_sig_item;
476     method class_str_item : class_str_item -> class_str_item;
477     method with_constr : with_constr -> with_constr;
478     method binding : binding -> binding;
479     method rec_binding : rec_binding -> rec_binding;
480     method module_binding : module_binding -> module_binding;
481     method match_case : match_case -> match_case;
482     method ident : ident -> ident;
483
484     method unknown : ! 'a. 'a -> 'a;
485   end;
486
487   (** See {!Ast.fold}. *)
488   class fold : object ('self_type)
489     method string : string -> 'self_type;
490     method list : ! 'a . ('self_type -> 'a -> 'self_type) -> list 'a -> 'self_type;
491     method meta_bool : meta_bool -> 'self_type;
492     method meta_option : ! 'a . ('self_type -> 'a -> 'self_type) -> meta_option 'a -> 'self_type;
493     method meta_list : ! 'a . ('self_type -> 'a -> 'self_type) -> meta_list 'a -> 'self_type;
494     method loc : loc -> 'self_type;
495     method expr : expr -> 'self_type;
496     method patt : patt -> 'self_type;
497     method ctyp : ctyp -> 'self_type;
498     method str_item : str_item -> 'self_type;
499     method sig_item : sig_item -> 'self_type;
500     method module_expr : module_expr -> 'self_type;
501     method module_type : module_type -> 'self_type;
502     method class_expr : class_expr -> 'self_type;
503     method class_type : class_type -> 'self_type;
504     method class_sig_item : class_sig_item -> 'self_type;
505     method class_str_item : class_str_item -> 'self_type;
506     method with_constr : with_constr -> 'self_type;
507     method binding : binding -> 'self_type;
508     method rec_binding : rec_binding -> 'self_type;
509     method module_binding : module_binding -> 'self_type;
510     method match_case : match_case -> 'self_type;
511     method ident : ident -> 'self_type;
512
513     method unknown : ! 'a. 'a -> 'self_type;
514   end;
515
516   value map_expr : (expr -> expr) -> map;
517   value map_patt : (patt -> patt) -> map;
518   value map_ctyp : (ctyp -> ctyp) -> map;
519   value map_str_item : (str_item -> str_item) -> map;
520   value map_sig_item : (sig_item -> sig_item) -> map;
521   value map_loc : (loc -> loc) -> map;
522
523   value ident_of_expr : expr -> ident;
524   value ident_of_patt : patt -> ident;
525   value ident_of_ctyp : ctyp -> ident;
526
527   value biAnd_of_list : list binding -> binding;
528   value rbSem_of_list : list rec_binding -> rec_binding;
529   value paSem_of_list : list patt -> patt;
530   value paCom_of_list : list patt -> patt;
531   value tyOr_of_list : list ctyp -> ctyp;
532   value tyAnd_of_list : list ctyp -> ctyp;
533   value tyAmp_of_list : list ctyp -> ctyp;
534   value tySem_of_list : list ctyp -> ctyp;
535   value tyCom_of_list : list ctyp -> ctyp;
536   value tySta_of_list : list ctyp -> ctyp;
537   value stSem_of_list : list str_item -> str_item;
538   value sgSem_of_list : list sig_item -> sig_item;
539   value crSem_of_list : list class_str_item -> class_str_item;
540   value cgSem_of_list : list class_sig_item -> class_sig_item;
541   value ctAnd_of_list : list class_type -> class_type;
542   value ceAnd_of_list : list class_expr -> class_expr;
543   value wcAnd_of_list : list with_constr -> with_constr;
544   value meApp_of_list : list module_expr -> module_expr;
545   value mbAnd_of_list : list module_binding -> module_binding;
546   value mcOr_of_list : list match_case -> match_case;
547   value idAcc_of_list : list ident -> ident;
548   value idApp_of_list : list ident -> ident;
549   value exSem_of_list : list expr -> expr;
550   value exCom_of_list : list expr -> expr;
551
552   value list_of_ctyp : ctyp -> list ctyp -> list ctyp;
553   value list_of_binding : binding -> list binding -> list binding;
554   value list_of_rec_binding : rec_binding -> list rec_binding -> list rec_binding;
555   value list_of_with_constr : with_constr -> list with_constr -> list with_constr;
556   value list_of_patt : patt -> list patt -> list patt;
557   value list_of_expr : expr -> list expr -> list expr;
558   value list_of_str_item : str_item -> list str_item -> list str_item;
559   value list_of_sig_item : sig_item -> list sig_item -> list sig_item;
560   value list_of_class_sig_item : class_sig_item -> list class_sig_item -> list class_sig_item;
561   value list_of_class_str_item : class_str_item -> list class_str_item -> list class_str_item;
562   value list_of_class_type : class_type -> list class_type -> list class_type;
563   value list_of_class_expr : class_expr -> list class_expr -> list class_expr;
564   value list_of_module_expr : module_expr -> list module_expr -> list module_expr;
565   value list_of_module_binding : module_binding -> list module_binding -> list module_binding;
566   value list_of_match_case : match_case -> list match_case -> list match_case;
567   value list_of_ident : ident -> list ident -> list ident;
568
569   (** Like [String.escape] but takes care to not
570       escape antiquotations strings. *)
571   value safe_string_escaped : string -> string;
572
573   (** Returns True if the given pattern is irrefutable. *)
574   value is_irrefut_patt : patt -> bool;
575
576   value is_constructor : ident -> bool;
577   value is_patt_constructor : patt -> bool;
578   value is_expr_constructor : expr -> bool;
579
580   value ty_of_stl : (Loc.t * string * list ctyp) -> ctyp;
581   value ty_of_sbt : (Loc.t * string * bool * ctyp) -> ctyp;
582   value bi_of_pe : (patt * expr) -> binding;
583   value pel_of_binding : binding -> list (patt * expr);
584   value binding_of_pel : list (patt * expr) -> binding;
585   value sum_type_of_list : list (Loc.t * string * list ctyp) -> ctyp;
586   value record_type_of_list : list (Loc.t * string * bool * ctyp) -> ctyp;
587 end;
588
589 (** This functor is a restriction functor.
590     It takes a Camlp4Ast module and gives the Ast one.
591     Typical use is for [with] constraints.
592     Example: ... with module Ast = Camlp4.Sig.Camlp4AstToAst Camlp4Ast *)
593 module Camlp4AstToAst (M : Camlp4Ast) : Ast
594   with type loc = M.loc
595    and type meta_bool = M.meta_bool
596    and type meta_option 'a = M.meta_option 'a
597    and type meta_list 'a = M.meta_list 'a
598    and type ctyp = M.ctyp
599    and type patt = M.patt
600    and type expr = M.expr
601    and type module_type = M.module_type
602    and type sig_item = M.sig_item
603    and type with_constr = M.with_constr
604    and type module_expr = M.module_expr
605    and type str_item = M.str_item
606    and type class_type = M.class_type
607    and type class_sig_item = M.class_sig_item
608    and type class_expr = M.class_expr
609    and type class_str_item = M.class_str_item
610    and type binding = M.binding
611    and type rec_binding = M.rec_binding
612    and type module_binding = M.module_binding
613    and type match_case = M.match_case
614    and type ident = M.ident
615 = M;
616
617 (** Concrete definition of Camlp4 ASTs abstracted from locations.
618     Since the Ast contains locations, this functor produces Ast types
619     for a given location type. *)
620 module MakeCamlp4Ast (Loc : Type) = struct
621
622   INCLUDE "camlp4/Camlp4/Camlp4Ast.partial.ml";
623
624 end;
625
626 (** {6 Filters} *)
627
628 (** A type for stream filters. *)
629 type stream_filter 'a 'loc = Stream.t ('a * 'loc) -> Stream.t ('a * 'loc);
630
631 (** Registerinng and folding of Ast filters.
632     Two kinds of filters must be handled:
633       - Implementation filters: str_item -> str_item.
634       - Interface filters: sig_item -> sig_item. *)
635 module type AstFilters = sig
636
637   module Ast : Camlp4Ast;
638
639   type filter 'a = 'a -> 'a;
640
641   value register_sig_item_filter : (filter Ast.sig_item) -> unit;
642   value register_str_item_filter : (filter Ast.str_item) -> unit;
643   value register_topphrase_filter : (filter Ast.str_item) -> unit;
644
645   value fold_interf_filters : ('a -> filter Ast.sig_item -> 'a) -> 'a -> 'a;
646   value fold_implem_filters : ('a -> filter Ast.str_item -> 'a) -> 'a -> 'a;
647   value fold_topphrase_filters : ('a -> filter Ast.str_item -> 'a) -> 'a -> 'a;
648
649 end;
650
651 (** ASTs as one single dynamic type *)
652 module type DynAst = sig
653   module Ast : Ast;
654   type tag 'a;
655
656   value ctyp_tag : tag Ast.ctyp;
657   value patt_tag : tag Ast.patt;
658   value expr_tag : tag Ast.expr;
659   value module_type_tag : tag Ast.module_type;
660   value sig_item_tag : tag Ast.sig_item;
661   value with_constr_tag : tag Ast.with_constr;
662   value module_expr_tag : tag Ast.module_expr;
663   value str_item_tag : tag Ast.str_item;
664   value class_type_tag : tag Ast.class_type;
665   value class_sig_item_tag : tag Ast.class_sig_item;
666   value class_expr_tag : tag Ast.class_expr;
667   value class_str_item_tag : tag Ast.class_str_item;
668   value match_case_tag : tag Ast.match_case;
669   value ident_tag : tag Ast.ident;
670   value binding_tag : tag Ast.binding;
671   value rec_binding_tag : tag Ast.rec_binding;
672   value module_binding_tag : tag Ast.module_binding;
673
674   value string_of_tag : tag 'a -> string;
675
676   module Pack (X : sig type t 'a; end) : sig
677     type pack;
678     value pack : tag 'a -> X.t 'a -> pack;
679     value unpack : tag 'a -> pack -> X.t 'a;
680     value print_tag : Format.formatter -> pack -> unit;
681   end;
682 end;
683
684
685 (** {6 Quotation operations} *)
686
687 (** The generic quotation type.
688     To see how fields are used here is an example:
689        <:q_name@q_loc<q_contents>>
690     The last one, q_shift is equal to the length of "<:q_name@q_loc<". *)
691 type quotation =
692   { q_name     : string ;
693     q_loc      : string ;
694     q_shift    : int    ;
695     q_contents : string };
696
697 (** The signature for a quotation expander registery. *)
698 module type Quotation = sig
699   module Ast : Ast;
700   module DynAst : DynAst with module Ast = Ast;
701   open Ast;
702
703   (** The [loc] is the initial location. The option string is the optional name
704       for the location variable. The string is the quotation contents. *)
705   type expand_fun 'a = loc -> option string -> string -> 'a;
706
707   (** [add name exp] adds the quotation [name] associated with the
708       expander [exp]. *)
709   value add : string -> DynAst.tag 'a -> expand_fun 'a -> unit;
710
711   (** [find name] returns the expander of the given quotation name. *)
712   value find : string -> DynAst.tag 'a -> expand_fun 'a;
713
714   (** [default] holds the default quotation name. *)
715   value default : ref string;
716
717   (** [parse_quotation_result parse_function loc position_tag quotation quotation_result]
718       It's a parser wrapper, this function handles the error reporting for you. *)
719   value parse_quotation_result :
720     (loc -> string -> 'a) -> loc -> quotation -> string -> string -> 'a;
721
722   (** function translating quotation names; default = identity *)
723   value translate : ref (string -> string);
724
725   value expand : loc -> quotation -> DynAst.tag 'a -> 'a;
726
727   (** [dump_file] optionally tells Camlp4 to dump the
728       result of an expander if this result is syntactically incorrect.
729       If [None] (default), this result is not dumped. If [Some fname], the
730       result is dumped in the file [fname]. *)
731   value dump_file : ref (option string);
732
733   module Error : Error;
734
735 end;
736
737 (** {6 Tokens} *)
738
739 (** A signature for tokens. *)
740 module type Token = sig
741
742   module Loc : Loc;
743
744   type t;
745
746   value to_string : t -> string;
747   
748   value print : Format.formatter -> t -> unit;
749
750   value match_keyword : string -> t -> bool;
751
752   value extract_string : t -> string;
753
754   module Filter : sig
755
756     type token_filter = stream_filter t Loc.t;
757
758     (** The type for this filter chain.
759         A basic implementation just store the [is_keyword] function given
760         by [mk] and use it in the [filter] function. *)
761     type t;
762
763     (** The given predicate function returns true if the given string
764         is a keyword. This function can be used in filters to translate
765         identifier tokens to keyword tokens. *)
766     value mk : (string -> bool) -> t;
767
768     (** This function allows to register a new filter to the token filter chain.
769         You can choose to not support these and raise an exception. *)
770     value define_filter : t -> (token_filter -> token_filter) -> unit;
771
772     (** This function filter the given stream and return a filtered stream.
773         A basic implementation just match identifiers against the [is_keyword]
774         function to produce token keywords instead. *)
775     value filter : t -> token_filter;
776
777     (** Called by the grammar system when a keyword is used. 
778         The boolean argument is True when it's the first time that keyword
779         is used. If you do not care about this information just return [()]. *)
780     value keyword_added : t -> string -> bool -> unit;
781
782     (** Called by the grammar system when a keyword is no longer used.
783         If you do not care about this information just return [()]. *)
784     value keyword_removed : t -> string -> unit;
785   end;
786
787   module Error : Error;
788 end;
789
790 (** This signature describes tokens for the Objective Caml and the Revised
791     syntax lexing rules. For some tokens the data constructor holds two
792     representations with the evaluated one and the source one. For example
793     the INT data constructor holds an integer and a string, this string can
794     contains more information that's needed for a good pretty-printing
795     ("42", "4_2", "0000042", "0b0101010"...).
796
797     The meaning of the tokens are:
798 -      [KEYWORD s] is the keyword [s].
799 -      [LIDENT s] is the ident [s] starting with a lowercase letter.
800 -      [UIDENT s] is the ident [s] starting with an uppercase letter.
801 -      [INT i s] (resp. [INT32 i s], [INT64 i s] and [NATIVEINT i s])
802         the integer constant [i] whose string source is [s].
803 -      [FLOAT f s] is the float constant [f] whose string source is [s].
804 -      [STRING s s'] is the string constant [s] whose string source is [s'].
805 -      [CHAR c s] is the character constant [c] whose string source is [s].
806 -      [QUOTATION q] is a quotation [q], see {!Quotation.t} for more information.
807 -      [ANTIQUOT n s] is an antiquotation [n] holding the string [s].
808 -      [EOI] is the end of input.
809
810      Warning: the second string associated with the constructor [STRING] is
811      the string found in the source without any interpretation. In particular,
812      the backslashes are not interpreted. For example, if the input is ["\n"]
813      the string is *not* a string with one element containing the character
814      "return", but a string of two elements: the backslash and the character
815      ["n"]. To interpret a string use the first string of the [STRING]
816      constructor (or if you need to compute it use the module
817      {!Camlp4.Struct.Token.Eval}. Same thing for the constructor [CHAR]. *)
818 type camlp4_token =
819   [ KEYWORD       of string
820   | SYMBOL        of string
821   | LIDENT        of string
822   | UIDENT        of string
823   | ESCAPED_IDENT of string
824   | INT           of int and string
825   | INT32         of int32 and string
826   | INT64         of int64 and string
827   | NATIVEINT     of nativeint and string
828   | FLOAT         of float and string
829   | CHAR          of char and string
830   | STRING        of string and string
831   | LABEL         of string
832   | OPTLABEL      of string
833   | QUOTATION     of quotation
834   | ANTIQUOT      of string and string
835   | COMMENT       of string
836   | BLANKS        of string
837   | NEWLINE
838   | LINE_DIRECTIVE of int and option string
839   | EOI ];
840
841 (** A signature for specialized tokens. *)
842 module type Camlp4Token = Token with type t = camlp4_token;
843
844 (** {6 Dynamic loaders} *)
845
846 (** A signature for dynamic loaders. *)
847 module type DynLoader = sig
848   type t;
849   exception Error of string and string;
850
851   (** [mk ?ocaml_stdlib ?camlp4_stdlib]
852       The stdlib flag is true by default.
853       To disable it use: [mk ~ocaml_stdlib:False] *)
854   value mk : ?ocaml_stdlib: bool -> ?camlp4_stdlib: bool -> unit -> t;
855
856   (** Fold over the current load path list. *)
857   value fold_load_path : t -> (string -> 'a -> 'a) -> 'a -> 'a;
858
859   (** [load f] Load the file [f]. If [f] is not an absolute path name,
860       the load path list used to find the directory of [f]. *)
861   value load : t -> string -> unit;
862
863   (** [include_dir d] Add the directory [d] in the current load path
864       list (like the common -I option). *)
865   value include_dir : t -> string -> unit;
866
867   (** [find_in_path f] Returns the full path of the file [f] if
868       [f] is in the current load path, raises [Not_found] otherwise. *)
869   value find_in_path : t -> string -> string;
870
871   (** [is_native] [True] if we are in native code, [False] for bytecode. *)
872   value is_native : bool;
873 end;
874
875 (** A signature for grammars. *)
876 module Grammar = struct
877
878   (** Internal signature for sematantic actions of grammars,
879       not for the casual user. These functions are unsafe. *)
880   module type Action = sig
881     type  t    ;
882
883     value mk    : 'a ->  t;
884     value get   :  t -> 'a;
885     value getf  :  t -> ('a -> 'b);
886     value getf2 :  t -> ('a -> 'b -> 'c);
887   end;
888
889   type assoc =
890     [ NonA
891     | RightA
892     | LeftA ];
893
894   type position =
895     [ First
896     | Last
897     | Before of string
898     | After of string
899     | Level of string ];
900
901   (** Common signature for {!Sig.Grammar.Static} and {!Sig.Grammar.Dynamic}. *)
902   module type Structure = sig
903     module Loc    : Loc;
904     module Action : Action;
905     module Token  : Token with module Loc = Loc;
906
907     type gram;
908     type internal_entry;
909     type tree;
910
911     type token_pattern = ((Token.t -> bool) * string);
912
913     type symbol =
914       [ Smeta of string and list symbol and Action.t
915       | Snterm of internal_entry
916       | Snterml of internal_entry and string
917       | Slist0 of symbol
918       | Slist0sep of symbol and symbol
919       | Slist1 of symbol
920       | Slist1sep of symbol and symbol
921       | Sopt of symbol
922       | Sself
923       | Snext
924       | Stoken of token_pattern
925       | Skeyword of string
926       | Stree of tree ];
927
928     type production_rule = (list symbol * Action.t);
929     type single_extend_statment =
930       (option string * option assoc * list production_rule);
931     type extend_statment =
932       (option position * list single_extend_statment);
933     type delete_statment = list symbol;
934
935     type fold 'a 'b 'c =
936       internal_entry -> list symbol ->
937         (Stream.t 'a -> 'b) -> Stream.t 'a -> 'c;
938
939     type foldsep 'a 'b 'c =
940       internal_entry -> list symbol ->
941         (Stream.t 'a -> 'b) -> (Stream.t 'a -> unit) -> Stream.t 'a -> 'c;
942
943   end;
944
945   (** Signature for Camlp4 grammars. Here the dynamic means that you can produce as
946       many grammar values as needed with a single grammar module.
947       If you do not need many grammar values it's preferable to use a static one. *)
948   module type Dynamic = sig
949     include Structure;
950
951     (** Make a new grammar. *)
952     value mk : unit -> gram;
953
954     module Entry : sig
955       (** The abstract type of grammar entries. The type parameter is the type
956           of the semantic actions that are associated with this entry. *)
957       type t 'a;
958   
959       (** Make a new entry from the given name. *)
960       value mk : gram -> string -> t 'a;
961   
962       (** Make a new entry from a name and an hand made token parser. *)
963       value of_parser :
964         gram -> string -> (Stream.t (Token.t * Loc.t) -> 'a) -> t 'a;
965
966       (** Clear the entry and setup this parser instead. *)
967       value setup_parser :
968         t 'a -> (Stream.t (Token.t * Loc.t) -> 'a) -> unit;
969
970       (** Get the entry name. *)
971       value name : t 'a -> string;
972
973       (** Print the given entry into the given formatter. *)
974       value print : Format.formatter -> t 'a -> unit;
975
976       (** Same as {!print} but show the left-factorization. *)
977       value dump : Format.formatter -> t 'a -> unit;
978
979       (**/**)
980       value obj : t 'a -> internal_entry;
981       value clear : t 'a -> unit;
982       (**/**)
983     end;
984
985     (** [get_filter g] Get the {!Token.Filter} associated to the [g]. *)
986     value get_filter : gram -> Token.Filter.t;
987
988     type not_filtered 'a;
989
990     (** This function is called by the EXTEND ... END syntax. *)
991     value extend      : Entry.t 'a -> extend_statment -> unit;
992
993     (** The delete rule. *)
994     value delete_rule : Entry.t 'a -> delete_statment -> unit;
995
996     value srules      : Entry.t 'a -> list (list symbol * Action.t) -> symbol;
997     value sfold0      : ('a -> 'b -> 'b) -> 'b -> fold _ 'a 'b;
998     value sfold1      : ('a -> 'b -> 'b) -> 'b -> fold _ 'a 'b;
999     value sfold0sep   : ('a -> 'b -> 'b) -> 'b -> foldsep _ 'a 'b;
1000     (* value sfold1sep : ('a -> 'b -> 'b) -> 'b -> foldsep _ 'a 'b; *)
1001
1002     (** Use the lexer to produce a non filtered token stream from a char stream. *)
1003     value lex : gram -> Loc.t -> Stream.t char
1004                     -> not_filtered (Stream.t (Token.t * Loc.t));
1005
1006     (** Token stream from string. *)
1007     value lex_string : gram -> Loc.t -> string
1008                             -> not_filtered (Stream.t (Token.t * Loc.t));
1009
1010     (** Filter a token stream using the {!Token.Filter} module *)
1011     value filter : gram -> not_filtered (Stream.t (Token.t * Loc.t))
1012                                       -> Stream.t (Token.t * Loc.t);
1013
1014     (** Lex, filter and parse a stream of character. *)
1015     value parse : Entry.t 'a -> Loc.t -> Stream.t char -> 'a;
1016
1017     (** Same as {!parse} but from a string. *)
1018     value parse_string : Entry.t 'a -> Loc.t -> string -> 'a;
1019
1020     (** Parse a token stream that is not filtered yet. *)
1021     value parse_tokens_before_filter :
1022       Entry.t 'a -> not_filtered (Stream.t (Token.t * Loc.t)) -> 'a;
1023
1024     (** Parse a token stream that is already filtered. *)
1025     value parse_tokens_after_filter :
1026       Entry.t 'a -> Stream.t (Token.t * Loc.t) -> 'a;
1027
1028   end;
1029
1030   (** Signature for Camlp4 grammars. Here the static means that there is only
1031       one grammar value by grammar module. If you do not need to store the grammar
1032       value it's preferable to use a static one. *)
1033   module type Static = sig
1034     include Structure;
1035
1036     module Entry : sig
1037       (** The abstract type of grammar entries. The type parameter is the type
1038           of the semantic actions that are associated with this entry. *)
1039       type t 'a;
1040
1041       (** Make a new entry from the given name. *)
1042       value mk : string -> t 'a;
1043
1044       (** Make a new entry from a name and an hand made token parser. *)
1045       value of_parser :
1046         string -> (Stream.t (Token.t * Loc.t) -> 'a) -> t 'a;
1047
1048       (** Clear the entry and setup this parser instead. *)
1049       value setup_parser :
1050         t 'a -> (Stream.t (Token.t * Loc.t) -> 'a) -> unit;
1051
1052       (** Get the entry name. *)
1053       value name : t 'a -> string;
1054
1055       (** Print the given entry into the given formatter. *)
1056       value print : Format.formatter -> t 'a -> unit;
1057
1058       (** Same as {!print} but show the left-factorization. *)
1059       value dump : Format.formatter -> t 'a -> unit;
1060
1061       (**/**)
1062       value obj : t 'a -> internal_entry;
1063       value clear : t 'a -> unit;
1064       (**/**)
1065     end;
1066
1067     (** Get the {!Token.Filter} associated to the grammar module. *)
1068     value get_filter : unit -> Token.Filter.t;
1069
1070     type not_filtered 'a;
1071
1072     (** This function is called by the EXTEND ... END syntax. *)
1073     value extend      : Entry.t 'a -> extend_statment -> unit;
1074
1075     (** The delete rule. *)
1076     value delete_rule : Entry.t 'a -> delete_statment -> unit;
1077     value srules      : Entry.t 'a -> list (list symbol * Action.t) -> symbol;
1078     value sfold0      : ('a -> 'b -> 'b) -> 'b -> fold _ 'a 'b;
1079     value sfold1      : ('a -> 'b -> 'b) -> 'b -> fold _ 'a 'b;
1080     value sfold0sep   : ('a -> 'b -> 'b) -> 'b -> foldsep _ 'a 'b;
1081     (* value sfold1sep : ('a -> 'b -> 'b) -> 'b -> foldsep _ 'a 'b; *)
1082
1083     (** Use the lexer to produce a non filtered token stream from a char stream. *)
1084     value lex : Loc.t -> Stream.t char
1085                       -> not_filtered (Stream.t (Token.t * Loc.t));
1086     (** Token stream from string. *)
1087     value lex_string : Loc.t -> string
1088                             -> not_filtered (Stream.t (Token.t * Loc.t));
1089
1090     (** Filter a token stream using the {!Token.Filter} module *)
1091     value filter : not_filtered (Stream.t (Token.t * Loc.t))
1092                               -> Stream.t (Token.t * Loc.t);
1093
1094     (** Lex, filter and parse a stream of character. *)
1095     value parse : Entry.t 'a -> Loc.t -> Stream.t char -> 'a;
1096
1097     (** Same as {!parse} but from a string. *)
1098     value parse_string : Entry.t 'a -> Loc.t -> string -> 'a;
1099
1100     (** Parse a token stream that is not filtered yet. *)
1101     value parse_tokens_before_filter :
1102       Entry.t 'a -> not_filtered (Stream.t (Token.t * Loc.t)) -> 'a;
1103
1104     (** Parse a token stream that is already filtered. *)
1105     value parse_tokens_after_filter :
1106       Entry.t 'a -> Stream.t (Token.t * Loc.t) -> 'a;
1107
1108   end;
1109
1110 end;
1111
1112 (** A signature for lexers. *)
1113 module type Lexer = sig
1114   module Loc : Loc;
1115   module Token : Token with module Loc = Loc;
1116   module Error : Error;
1117
1118   (** The constructor for a lexing function. The character stream is the input
1119       stream to be lexed. The result is a stream of pairs of a token and
1120       a location.
1121       The lexer do not use global (mutable) variables: instantiations
1122       of [Lexer.mk ()] do not perturb each other. *)
1123   value mk : unit -> (Loc.t -> Stream.t char -> Stream.t (Token.t * Loc.t));
1124 end;
1125
1126
1127 (** A signature for parsers abstract from ASTs. *)
1128 module Parser (Ast : Ast) = struct
1129   module type SIMPLE = sig
1130     (** The parse function for expressions.
1131         The underlying expression grammar entry is generally "expr; EOI". *)
1132     value parse_expr : Ast.loc -> string -> Ast.expr;
1133
1134     (** The parse function for patterns.
1135         The underlying pattern grammar entry is generally "patt; EOI". *)
1136     value parse_patt : Ast.loc -> string -> Ast.patt;
1137   end;
1138
1139   module type S = sig
1140
1141     (** Called when parsing an implementation (ml file) to build the syntax
1142         tree; the returned list contains the phrases (structure items) as a
1143         single "declare" node (a list of structure items);   if  the parser
1144         encounter a directive it stops (since the directive may change  the
1145         syntax), the given [directive_handler] function  evaluates  it  and
1146         the parsing starts again. *)
1147     value parse_implem : ?directive_handler:(Ast.str_item -> option Ast.str_item) ->
1148                         Ast.loc -> Stream.t char -> Ast.str_item;
1149
1150     (** Same as {!parse_implem} but for interface (mli file). *)
1151     value parse_interf : ?directive_handler:(Ast.sig_item -> option Ast.sig_item) ->
1152                         Ast.loc -> Stream.t char -> Ast.sig_item;
1153   end;
1154 end;
1155
1156 (** A signature for printers abstract from ASTs. *)
1157 module Printer (Ast : Ast) = struct
1158   module type S = sig
1159
1160     value print_interf : ?input_file:string -> ?output_file:string ->
1161                         Ast.sig_item -> unit;
1162     value print_implem : ?input_file:string -> ?output_file:string ->
1163                         Ast.str_item -> unit;
1164
1165   end;
1166 end;
1167
1168 (** A syntax module is a sort of constistent bunch of modules and values.
1169    In such a module you have a parser, a printer, and also modules for
1170    locations, syntax trees, tokens, grammars, quotations, anti-quotations.
1171    There is also the main grammar entries. *)
1172 module type Syntax = sig
1173   module Loc            : Loc;
1174   module Ast            : Ast with type loc = Loc.t;
1175   module Token          : Token with module Loc = Loc;
1176   module Gram           : Grammar.Static with module Loc = Loc and module Token = Token;
1177   module Quotation      : Quotation with module Ast = Ast;
1178
1179   module AntiquotSyntax : (Parser Ast).SIMPLE;
1180
1181   include (Warning Loc).S;
1182   include (Parser  Ast).S;
1183   include (Printer Ast).S;
1184 end;
1185
1186 (** A syntax module is a sort of constistent bunch of modules and values.
1187     In such a module you have a parser, a printer, and also modules for
1188     locations, syntax trees, tokens, grammars, quotations, anti-quotations.
1189     There is also the main grammar entries. *)
1190 module type Camlp4Syntax = sig
1191   module Loc            : Loc;
1192
1193   module Ast            : Camlp4Ast with module Loc = Loc;
1194   module Token          : Camlp4Token with module Loc = Loc;
1195
1196   module Gram           : Grammar.Static with module Loc = Loc and module Token = Token;
1197   module Quotation      : Quotation with module Ast = Camlp4AstToAst Ast;
1198
1199   module AntiquotSyntax : (Parser Ast).SIMPLE;
1200
1201   include (Warning Loc).S;
1202   include (Parser  Ast).S;
1203   include (Printer Ast).S;
1204
1205   value interf : Gram.Entry.t (list Ast.sig_item * option Loc.t);
1206   value implem : Gram.Entry.t (list Ast.str_item * option Loc.t);
1207   value top_phrase : Gram.Entry.t (option Ast.str_item);
1208   value use_file : Gram.Entry.t (list Ast.str_item * option Loc.t);
1209   value a_CHAR : Gram.Entry.t string;
1210   value a_FLOAT : Gram.Entry.t string;
1211   value a_INT : Gram.Entry.t string;
1212   value a_INT32 : Gram.Entry.t string;
1213   value a_INT64 : Gram.Entry.t string;
1214   value a_LABEL : Gram.Entry.t string;
1215   value a_LIDENT : Gram.Entry.t string;
1216   value a_NATIVEINT : Gram.Entry.t string;
1217   value a_OPTLABEL : Gram.Entry.t string;
1218   value a_STRING : Gram.Entry.t string;
1219   value a_UIDENT : Gram.Entry.t string;
1220   value a_ident : Gram.Entry.t string;
1221   value amp_ctyp : Gram.Entry.t Ast.ctyp;
1222   value and_ctyp : Gram.Entry.t Ast.ctyp;
1223   value match_case : Gram.Entry.t Ast.match_case;
1224   value match_case0 : Gram.Entry.t Ast.match_case;
1225   value match_case_quot : Gram.Entry.t Ast.match_case;
1226   value binding : Gram.Entry.t Ast.binding;
1227   value binding_quot : Gram.Entry.t Ast.binding;
1228   value rec_binding_quot : Gram.Entry.t Ast.rec_binding;
1229   value class_declaration : Gram.Entry.t Ast.class_expr;
1230   value class_description : Gram.Entry.t Ast.class_type;
1231   value class_expr : Gram.Entry.t Ast.class_expr;
1232   value class_expr_quot : Gram.Entry.t Ast.class_expr;
1233   value class_fun_binding : Gram.Entry.t Ast.class_expr;
1234   value class_fun_def : Gram.Entry.t Ast.class_expr;
1235   value class_info_for_class_expr : Gram.Entry.t Ast.class_expr;
1236   value class_info_for_class_type : Gram.Entry.t Ast.class_type;
1237   value class_longident : Gram.Entry.t Ast.ident;
1238   value class_longident_and_param : Gram.Entry.t Ast.class_expr;
1239   value class_name_and_param : Gram.Entry.t (string * Ast.ctyp);
1240   value class_sig_item : Gram.Entry.t Ast.class_sig_item;
1241   value class_sig_item_quot : Gram.Entry.t Ast.class_sig_item;
1242   value class_signature : Gram.Entry.t Ast.class_sig_item;
1243   value class_str_item : Gram.Entry.t Ast.class_str_item;
1244   value class_str_item_quot : Gram.Entry.t Ast.class_str_item;
1245   value class_structure : Gram.Entry.t Ast.class_str_item;
1246   value class_type : Gram.Entry.t Ast.class_type;
1247   value class_type_declaration : Gram.Entry.t Ast.class_type;
1248   value class_type_longident : Gram.Entry.t Ast.ident;
1249   value class_type_longident_and_param : Gram.Entry.t Ast.class_type;
1250   value class_type_plus : Gram.Entry.t Ast.class_type;
1251   value class_type_quot : Gram.Entry.t Ast.class_type;
1252   value comma_ctyp : Gram.Entry.t Ast.ctyp;
1253   value comma_expr : Gram.Entry.t Ast.expr;
1254   value comma_ipatt : Gram.Entry.t Ast.patt;
1255   value comma_patt : Gram.Entry.t Ast.patt;
1256   value comma_type_parameter : Gram.Entry.t Ast.ctyp;
1257   value constrain : Gram.Entry.t (Ast.ctyp * Ast.ctyp);
1258   value constructor_arg_list : Gram.Entry.t Ast.ctyp;
1259   value constructor_declaration : Gram.Entry.t Ast.ctyp;
1260   value constructor_declarations : Gram.Entry.t Ast.ctyp;
1261   value ctyp : Gram.Entry.t Ast.ctyp;
1262   value ctyp_quot : Gram.Entry.t Ast.ctyp;
1263   value cvalue_binding : Gram.Entry.t Ast.expr;
1264   value direction_flag : Gram.Entry.t Ast.meta_bool;
1265   value dummy : Gram.Entry.t unit;
1266   value eq_expr : Gram.Entry.t (string -> Ast.patt -> Ast.patt);
1267   value expr : Gram.Entry.t Ast.expr;
1268   value expr_eoi : Gram.Entry.t Ast.expr;
1269   value expr_quot : Gram.Entry.t Ast.expr;
1270   value field_expr : Gram.Entry.t Ast.rec_binding;
1271   value field_expr_list : Gram.Entry.t Ast.rec_binding;
1272   value fun_binding : Gram.Entry.t Ast.expr;
1273   value fun_def : Gram.Entry.t Ast.expr;
1274   value ident : Gram.Entry.t Ast.ident;
1275   value ident_quot : Gram.Entry.t Ast.ident;
1276   value ipatt : Gram.Entry.t Ast.patt;
1277   value ipatt_tcon : Gram.Entry.t Ast.patt;
1278   value label : Gram.Entry.t string;
1279   value label_declaration : Gram.Entry.t Ast.ctyp;
1280   value label_declaration_list : Gram.Entry.t Ast.ctyp;
1281   value label_expr : Gram.Entry.t Ast.rec_binding;
1282   value label_expr_list : Gram.Entry.t Ast.rec_binding;
1283   value label_ipatt : Gram.Entry.t Ast.patt;
1284   value label_ipatt_list : Gram.Entry.t Ast.patt;
1285   value label_longident : Gram.Entry.t Ast.ident;
1286   value label_patt : Gram.Entry.t Ast.patt;
1287   value label_patt_list : Gram.Entry.t Ast.patt;
1288   value labeled_ipatt : Gram.Entry.t Ast.patt;
1289   value let_binding : Gram.Entry.t Ast.binding;
1290   value meth_list : Gram.Entry.t (Ast.ctyp * Ast.meta_bool);
1291   value meth_decl : Gram.Entry.t Ast.ctyp;
1292   value module_binding : Gram.Entry.t Ast.module_binding;
1293   value module_binding0 : Gram.Entry.t Ast.module_expr;
1294   value module_binding_quot : Gram.Entry.t Ast.module_binding;
1295   value module_declaration : Gram.Entry.t Ast.module_type;
1296   value module_expr : Gram.Entry.t Ast.module_expr;
1297   value module_expr_quot : Gram.Entry.t Ast.module_expr;
1298   value module_longident : Gram.Entry.t Ast.ident;
1299   value module_longident_with_app : Gram.Entry.t Ast.ident;
1300   value module_rec_declaration : Gram.Entry.t Ast.module_binding;
1301   value module_type : Gram.Entry.t Ast.module_type;
1302   value module_type_quot : Gram.Entry.t Ast.module_type;
1303   value more_ctyp : Gram.Entry.t Ast.ctyp;
1304   value name_tags : Gram.Entry.t Ast.ctyp;
1305   value opt_as_lident : Gram.Entry.t string;
1306   value opt_class_self_patt : Gram.Entry.t Ast.patt;
1307   value opt_class_self_type : Gram.Entry.t Ast.ctyp;
1308   value opt_comma_ctyp : Gram.Entry.t Ast.ctyp;
1309   value opt_dot_dot : Gram.Entry.t Ast.meta_bool;
1310   value opt_eq_ctyp : Gram.Entry.t Ast.ctyp;
1311   value opt_expr : Gram.Entry.t Ast.expr;
1312   value opt_meth_list : Gram.Entry.t Ast.ctyp;
1313   value opt_mutable : Gram.Entry.t Ast.meta_bool;
1314   value opt_polyt : Gram.Entry.t Ast.ctyp;
1315   value opt_private : Gram.Entry.t Ast.meta_bool;
1316   value opt_rec : Gram.Entry.t Ast.meta_bool;
1317   value opt_virtual : Gram.Entry.t Ast.meta_bool;
1318   value opt_when_expr : Gram.Entry.t Ast.expr;
1319   value patt : Gram.Entry.t Ast.patt;
1320   value patt_as_patt_opt : Gram.Entry.t Ast.patt;
1321   value patt_eoi : Gram.Entry.t Ast.patt;
1322   value patt_quot : Gram.Entry.t Ast.patt;
1323   value patt_tcon : Gram.Entry.t Ast.patt;
1324   value phrase : Gram.Entry.t Ast.str_item;
1325   value poly_type : Gram.Entry.t Ast.ctyp;
1326   value row_field : Gram.Entry.t Ast.ctyp;
1327   value sem_expr : Gram.Entry.t Ast.expr;
1328   value sem_expr_for_list : Gram.Entry.t (Ast.expr -> Ast.expr);
1329   value sem_patt : Gram.Entry.t Ast.patt;
1330   value sem_patt_for_list : Gram.Entry.t (Ast.patt -> Ast.patt);
1331   value semi : Gram.Entry.t unit;
1332   value sequence : Gram.Entry.t Ast.expr;
1333   value do_sequence : Gram.Entry.t Ast.expr;
1334   value sig_item : Gram.Entry.t Ast.sig_item;
1335   value sig_item_quot : Gram.Entry.t Ast.sig_item;
1336   value sig_items : Gram.Entry.t Ast.sig_item;
1337   value star_ctyp : Gram.Entry.t Ast.ctyp;
1338   value str_item : Gram.Entry.t Ast.str_item;
1339   value str_item_quot : Gram.Entry.t Ast.str_item;
1340   value str_items : Gram.Entry.t Ast.str_item;
1341   value type_constraint : Gram.Entry.t unit;
1342   value type_declaration : Gram.Entry.t Ast.ctyp;
1343   value type_ident_and_parameters : Gram.Entry.t (string * list Ast.ctyp);
1344   value type_kind : Gram.Entry.t Ast.ctyp;
1345   value type_longident : Gram.Entry.t Ast.ident;
1346   value type_longident_and_parameters : Gram.Entry.t Ast.ctyp;
1347   value type_parameter : Gram.Entry.t Ast.ctyp;
1348   value type_parameters : Gram.Entry.t (Ast.ctyp -> Ast.ctyp);
1349   value typevars : Gram.Entry.t Ast.ctyp;
1350   value val_longident : Gram.Entry.t Ast.ident;
1351   value value_let : Gram.Entry.t unit;
1352   value value_val : Gram.Entry.t unit;
1353   value with_constr : Gram.Entry.t Ast.with_constr;
1354   value with_constr_quot : Gram.Entry.t Ast.with_constr;
1355   value prefixop : Gram.Entry.t Ast.expr;
1356   value infixop0 : Gram.Entry.t Ast.expr;
1357   value infixop1 : Gram.Entry.t Ast.expr;
1358   value infixop2 : Gram.Entry.t Ast.expr;
1359   value infixop3 : Gram.Entry.t Ast.expr;
1360   value infixop4 : Gram.Entry.t Ast.expr;
1361 end;
1362
1363 (** A signature for syntax extension (syntax -> syntax functors). *)
1364 module type SyntaxExtension = functor (Syn : Syntax)
1365                     -> (Syntax with module Loc            = Syn.Loc
1366                                 and module Ast            = Syn.Ast
1367                                 and module Token          = Syn.Token
1368                                 and module Gram           = Syn.Gram
1369                                 and module Quotation      = Syn.Quotation);
1370