1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
2013-04-16 06:31:35 -07:00
|
|
|
(** Abstract syntax tree produced by parsing *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
open Asttypes
|
|
|
|
|
2013-04-16 00:58:04 -07:00
|
|
|
(** {2 Extension points} *)
|
2013-02-28 08:51:59 -08:00
|
|
|
|
2013-07-22 07:58:15 -07:00
|
|
|
type attribute = string loc * payload
|
2014-04-11 23:56:51 -07:00
|
|
|
(* [@id ARG]
|
|
|
|
[@@id ARG]
|
|
|
|
|
|
|
|
Metadata containers passed around within the AST.
|
|
|
|
The compiler ignores unknown attributes.
|
2013-04-12 09:08:52 -07:00
|
|
|
*)
|
2013-02-28 08:51:59 -08:00
|
|
|
|
2013-07-22 07:58:15 -07:00
|
|
|
and extension = string loc * payload
|
2013-09-03 01:59:23 -07:00
|
|
|
(* [%id ARG]
|
|
|
|
[%%id ARG]
|
2014-04-11 23:56:51 -07:00
|
|
|
|
|
|
|
Sub-language placeholder -- rejected by the typechecker.
|
|
|
|
*)
|
2013-02-28 08:51:59 -08:00
|
|
|
|
2013-04-10 11:00:11 -07:00
|
|
|
and attributes = attribute list
|
|
|
|
|
2013-07-22 07:58:15 -07:00
|
|
|
and payload =
|
|
|
|
| PStr of structure
|
2013-07-22 08:15:07 -07:00
|
|
|
| PTyp of core_type (* : T *)
|
|
|
|
| PPat of pattern * expression option (* : P or : P when E *)
|
2013-07-22 07:58:15 -07:00
|
|
|
|
2013-04-16 00:58:04 -07:00
|
|
|
(** {2 Core language} *)
|
|
|
|
|
|
|
|
(* Type expressions *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2013-02-28 08:51:59 -08:00
|
|
|
and core_type =
|
2013-04-12 09:08:52 -07:00
|
|
|
{
|
|
|
|
ptyp_desc: core_type_desc;
|
|
|
|
ptyp_loc: Location.t;
|
2013-04-19 00:40:57 -07:00
|
|
|
ptyp_attributes: attributes; (* ... [@id1] [@id2] *)
|
2013-04-12 09:08:52 -07:00
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2010-01-22 04:48:24 -08:00
|
|
|
and core_type_desc =
|
2013-04-12 09:08:52 -07:00
|
|
|
| Ptyp_any
|
|
|
|
(* _ *)
|
1997-02-11 10:24:47 -08:00
|
|
|
| Ptyp_var of string
|
2013-04-12 09:08:52 -07:00
|
|
|
(* 'a *)
|
2014-12-22 00:45:55 -08:00
|
|
|
| Ptyp_arrow of arg_label * core_type * core_type
|
|
|
|
(* T1 -> T2 Simple
|
|
|
|
~l:T1 -> T2 Labelled
|
|
|
|
?l:T1 -> T2 Otional
|
2013-04-12 09:08:52 -07:00
|
|
|
*)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Ptyp_tuple of core_type list
|
2014-08-22 06:45:02 -07:00
|
|
|
(* T1 * ... * Tn
|
|
|
|
|
|
|
|
Invariant: n >= 2
|
|
|
|
*)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Ptyp_constr of Longident.t loc * core_type list
|
2013-04-12 09:08:52 -07:00
|
|
|
(* tconstr
|
|
|
|
T tconstr
|
|
|
|
(T1, ..., Tn) tconstr
|
|
|
|
*)
|
2014-05-05 04:21:45 -07:00
|
|
|
| Ptyp_object of (string * attributes * core_type) list * closed_flag
|
2013-04-12 09:08:52 -07:00
|
|
|
(* < l1:T1; ...; ln:Tn > (flag = Closed)
|
|
|
|
< l1:T1; ...; ln:Tn; .. > (flag = Open)
|
|
|
|
*)
|
2013-04-16 05:17:17 -07:00
|
|
|
| Ptyp_class of Longident.t loc * core_type list
|
2013-04-12 09:08:52 -07:00
|
|
|
(* #tconstr
|
|
|
|
T #tconstr
|
2013-04-16 05:17:17 -07:00
|
|
|
(T1, ..., Tn) #tconstr
|
2013-04-12 09:08:52 -07:00
|
|
|
*)
|
1997-03-07 14:26:29 -08:00
|
|
|
| Ptyp_alias of core_type * string
|
2013-04-12 09:08:52 -07:00
|
|
|
(* T as 'a *)
|
|
|
|
| Ptyp_variant of row_field list * closed_flag * label list option
|
|
|
|
(* [ `A|`B ] (flag = Closed; labels = None)
|
|
|
|
[> `A|`B ] (flag = Open; labels = None)
|
|
|
|
[< `A|`B ] (flag = Closed; labels = Some [])
|
|
|
|
[< `A|`B > `X `Y ](flag = Closed; labels = Some ["X";"Y"])
|
|
|
|
*)
|
2002-04-18 00:27:47 -07:00
|
|
|
| Ptyp_poly of string list * core_type
|
2013-04-15 09:47:27 -07:00
|
|
|
(* 'a1 ... 'an. T
|
|
|
|
|
|
|
|
Can only appear in the following context:
|
|
|
|
|
|
|
|
- As the core_type of a Ppat_constraint node corresponding
|
|
|
|
to a constraint on a let-binding: let x : 'a1 ... 'an. T
|
|
|
|
= e ...
|
|
|
|
|
|
|
|
- Under Cfk_virtual for methods (not values).
|
|
|
|
|
|
|
|
- As the core_type of a Pctf_method node.
|
|
|
|
|
|
|
|
- As the core_type of a Pexp_poly node.
|
|
|
|
|
|
|
|
- As the pld_type field of a label_declaration.
|
|
|
|
|
|
|
|
- As a core_type of a Ptyp_object node.
|
|
|
|
*)
|
|
|
|
|
2009-10-26 03:53:16 -07:00
|
|
|
| Ptyp_package of package_type
|
2013-04-12 09:08:52 -07:00
|
|
|
(* (module S) *)
|
2013-02-28 08:51:59 -08:00
|
|
|
| Ptyp_extension of extension
|
2013-04-19 00:40:57 -07:00
|
|
|
(* [%id] *)
|
2012-05-30 07:52:37 -07:00
|
|
|
|
|
|
|
and package_type = Longident.t loc * (Longident.t loc * core_type) list
|
2013-04-12 09:08:52 -07:00
|
|
|
(*
|
|
|
|
(module S)
|
|
|
|
(module S with type t1 = T1 and ... and tn = Tn)
|
|
|
|
*)
|
1996-04-22 04:15:41 -07:00
|
|
|
|
2001-09-25 02:54:18 -07:00
|
|
|
and row_field =
|
2014-04-30 01:19:55 -07:00
|
|
|
| Rtag of label * attributes * bool * core_type list
|
2013-04-12 09:08:52 -07:00
|
|
|
(* [`A] ( true, [] )
|
|
|
|
[`A of T] ( false, [T] )
|
|
|
|
[`A of T1 & .. & Tn] ( false, [T1;...Tn] )
|
|
|
|
[`A of & T1 & .. & Tn] ( true, [T1;...Tn] )
|
2014-04-11 23:56:51 -07:00
|
|
|
|
|
|
|
- The 2nd field is true if the tag contains a
|
|
|
|
constant (empty) constructor.
|
|
|
|
- '&' occurs when several types are used for the same constructor
|
|
|
|
(see 4.2 in the manual)
|
2014-04-30 01:19:55 -07:00
|
|
|
|
|
|
|
- TODO: switch to a record representation, and keep location
|
2014-04-11 23:56:51 -07:00
|
|
|
*)
|
2001-09-25 02:54:18 -07:00
|
|
|
| Rinherit of core_type
|
2013-04-12 09:08:52 -07:00
|
|
|
(* [ T ] *)
|
2001-09-25 02:54:18 -07:00
|
|
|
|
2013-04-16 00:58:04 -07:00
|
|
|
(* Patterns *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2013-02-28 08:51:59 -08:00
|
|
|
and pattern =
|
2013-04-16 00:37:16 -07:00
|
|
|
{
|
|
|
|
ppat_desc: pattern_desc;
|
|
|
|
ppat_loc: Location.t;
|
2013-04-19 00:40:57 -07:00
|
|
|
ppat_attributes: attributes; (* ... [@id1] [@id2] *)
|
2013-04-16 00:37:16 -07:00
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and pattern_desc =
|
2013-04-12 09:53:55 -07:00
|
|
|
| Ppat_any
|
|
|
|
(* _ *)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Ppat_var of string loc
|
2013-04-12 10:20:47 -07:00
|
|
|
(* x *)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Ppat_alias of pattern * string loc
|
2013-04-12 09:53:55 -07:00
|
|
|
(* P as 'a *)
|
2013-05-23 08:12:04 -07:00
|
|
|
| Ppat_constant of constant
|
2013-04-12 09:53:55 -07:00
|
|
|
(* 1, 'a', "true", 1.0, 1l, 1L, 1n *)
|
2013-05-23 08:12:04 -07:00
|
|
|
| Ppat_interval of constant * constant
|
2013-04-16 08:34:09 -07:00
|
|
|
(* 'a'..'z'
|
|
|
|
|
|
|
|
Other forms of interval are recognized by the parser
|
|
|
|
but rejected by the type-checker. *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Ppat_tuple of pattern list
|
2014-08-22 06:45:02 -07:00
|
|
|
(* (P1, ..., Pn)
|
|
|
|
|
|
|
|
Invariant: n >= 2
|
|
|
|
*)
|
2013-04-17 02:46:52 -07:00
|
|
|
| Ppat_construct of Longident.t loc * pattern option
|
|
|
|
(* C None
|
|
|
|
C P Some P
|
|
|
|
C (P1, ..., Pn) Some (Ppat_tuple [P1; ...; Pn])
|
2013-04-12 09:53:55 -07:00
|
|
|
*)
|
1999-11-30 08:07:38 -08:00
|
|
|
| Ppat_variant of label * pattern option
|
2013-04-12 09:53:55 -07:00
|
|
|
(* `A (None)
|
2013-04-16 05:20:57 -07:00
|
|
|
`A P (Some P)
|
2013-04-12 09:53:55 -07:00
|
|
|
*)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Ppat_record of (Longident.t loc * pattern) list * closed_flag
|
2013-04-12 09:53:55 -07:00
|
|
|
(* { l1=P1; ...; ln=Pn } (flag = Closed)
|
|
|
|
{ l1=P1; ...; ln=Pn; _} (flag = Open)
|
2014-08-22 06:45:02 -07:00
|
|
|
|
|
|
|
Invariant: n > 0
|
2013-04-12 09:53:55 -07:00
|
|
|
*)
|
1998-04-06 02:16:54 -07:00
|
|
|
| Ppat_array of pattern list
|
2013-04-12 09:53:55 -07:00
|
|
|
(* [| P1; ...; Pn |] *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Ppat_or of pattern * pattern
|
2013-04-12 09:53:55 -07:00
|
|
|
(* P1 | P2 *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Ppat_constraint of pattern * core_type
|
2013-04-12 09:53:55 -07:00
|
|
|
(* (P : T) *)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Ppat_type of Longident.t loc
|
2013-04-12 09:53:55 -07:00
|
|
|
(* #tconst *)
|
2008-07-09 06:03:38 -07:00
|
|
|
| Ppat_lazy of pattern
|
2013-04-12 09:53:55 -07:00
|
|
|
(* lazy P *)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Ppat_unpack of string loc
|
2013-04-12 09:53:55 -07:00
|
|
|
(* (module P)
|
2014-04-12 03:17:02 -07:00
|
|
|
Note: (module P : S) is represented as
|
|
|
|
Ppat_constraint(Ppat_unpack, Ptyp_package)
|
2013-04-12 09:53:55 -07:00
|
|
|
*)
|
2014-05-05 04:49:37 -07:00
|
|
|
| Ppat_exception of pattern
|
|
|
|
(* exception P *)
|
2013-03-04 05:52:23 -08:00
|
|
|
| Ppat_extension of extension
|
2013-04-19 00:40:57 -07:00
|
|
|
(* [%id] *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2013-04-16 00:58:04 -07:00
|
|
|
(* Value expressions *)
|
|
|
|
|
2013-02-28 08:51:59 -08:00
|
|
|
and expression =
|
2013-04-12 10:20:47 -07:00
|
|
|
{
|
|
|
|
pexp_desc: expression_desc;
|
|
|
|
pexp_loc: Location.t;
|
2013-04-19 00:40:57 -07:00
|
|
|
pexp_attributes: attributes; (* ... [@id1] [@id2] *)
|
2013-04-12 10:20:47 -07:00
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and expression_desc =
|
2013-04-12 10:20:47 -07:00
|
|
|
| Pexp_ident of Longident.t loc
|
|
|
|
(* x
|
|
|
|
M.x
|
|
|
|
*)
|
2013-05-23 08:12:04 -07:00
|
|
|
| Pexp_constant of constant
|
2013-04-12 10:20:47 -07:00
|
|
|
(* 1, 'a', "true", 1.0, 1l, 1L, 1n *)
|
2013-06-03 08:14:19 -07:00
|
|
|
| Pexp_let of rec_flag * value_binding list * expression
|
2013-04-12 10:20:47 -07:00
|
|
|
(* let P1 = E1 and ... and Pn = EN in E (flag = Nonrecursive)
|
|
|
|
let rec P1 = E1 and ... and Pn = EN in E (flag = Recursive)
|
|
|
|
*)
|
2013-04-17 04:43:29 -07:00
|
|
|
| Pexp_function of case list
|
|
|
|
(* function P1 -> E1 | ... | Pn -> En *)
|
2014-12-22 00:45:55 -08:00
|
|
|
| Pexp_fun of arg_label * expression option * pattern * expression
|
|
|
|
(* fun P -> E1 (Simple, None)
|
|
|
|
fun ~l:P -> E1 (Labelled l, None)
|
|
|
|
fun ?l:P -> E1 (Optional l, None)
|
|
|
|
fun ?l:(P = E0) -> E1 (Optional l, Some E0)
|
2013-04-12 10:20:47 -07:00
|
|
|
|
|
|
|
Notes:
|
2014-12-22 00:45:55 -08:00
|
|
|
- If E0 is provided, only Optional is allowed.
|
2013-04-17 04:43:29 -07:00
|
|
|
- "fun P1 P2 .. Pn -> E1" is represented as nested Pexp_fun.
|
|
|
|
- "let f P = E" is represented using Pexp_fun.
|
2013-04-12 10:20:47 -07:00
|
|
|
*)
|
2014-12-22 00:45:55 -08:00
|
|
|
| Pexp_apply of expression * (arg_label * expression) list
|
2013-04-12 10:20:47 -07:00
|
|
|
(* E0 ~l1:E1 ... ~ln:En
|
|
|
|
li can be empty (non labeled argument) or start with '?'
|
|
|
|
(optional argument).
|
2014-08-22 06:45:02 -07:00
|
|
|
|
|
|
|
Invariant: n > 0
|
2013-04-12 10:20:47 -07:00
|
|
|
*)
|
2013-04-15 09:23:22 -07:00
|
|
|
| Pexp_match of expression * case list
|
2013-04-12 10:20:47 -07:00
|
|
|
(* match E0 with P1 -> E1 | ... | Pn -> En *)
|
2013-04-15 09:23:22 -07:00
|
|
|
| Pexp_try of expression * case list
|
2013-04-12 10:20:47 -07:00
|
|
|
(* try E0 with P1 -> E1 | ... | Pn -> En *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pexp_tuple of expression list
|
2014-08-22 06:45:02 -07:00
|
|
|
(* (E1, ..., En)
|
|
|
|
|
|
|
|
Invariant: n >= 2
|
|
|
|
*)
|
2013-04-17 02:46:52 -07:00
|
|
|
| Pexp_construct of Longident.t loc * expression option
|
|
|
|
(* C None
|
|
|
|
C E Some E
|
|
|
|
C (E1, ..., En) Some (Pexp_tuple[E1;...;En])
|
2013-04-12 10:20:47 -07:00
|
|
|
*)
|
1999-11-30 08:07:38 -08:00
|
|
|
| Pexp_variant of label * expression option
|
2013-04-12 10:20:47 -07:00
|
|
|
(* `A (None)
|
2013-04-16 05:20:57 -07:00
|
|
|
`A E (Some E)
|
2013-04-12 10:20:47 -07:00
|
|
|
*)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Pexp_record of (Longident.t loc * expression) list * expression option
|
2013-04-12 10:20:47 -07:00
|
|
|
(* { l1=P1; ...; ln=Pn } (None)
|
|
|
|
{ E0 with l1=P1; ...; ln=Pn } (Some E0)
|
2014-08-22 06:45:02 -07:00
|
|
|
|
|
|
|
Invariant: n > 0
|
2013-04-12 10:20:47 -07:00
|
|
|
*)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Pexp_field of expression * Longident.t loc
|
2013-04-12 10:20:47 -07:00
|
|
|
(* E.l *)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Pexp_setfield of expression * Longident.t loc * expression
|
2013-04-12 10:20:47 -07:00
|
|
|
(* E1.l <- E2 *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pexp_array of expression list
|
2013-04-12 10:20:47 -07:00
|
|
|
(* [| E1; ...; En |] *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pexp_ifthenelse of expression * expression * expression option
|
2013-04-12 10:20:47 -07:00
|
|
|
(* if E1 then E2 else E3 *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pexp_sequence of expression * expression
|
2013-04-12 10:20:47 -07:00
|
|
|
(* E1; E2 *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pexp_while of expression * expression
|
2013-04-12 10:20:47 -07:00
|
|
|
(* while E1 do E2 done *)
|
2012-12-08 12:55:42 -08:00
|
|
|
| Pexp_for of
|
2013-12-02 10:00:18 -08:00
|
|
|
pattern * expression * expression * direction_flag * expression
|
2013-04-12 10:20:47 -07:00
|
|
|
(* for i = E1 to E2 do E3 done (flag = Upto)
|
|
|
|
for i = E1 downto E2 do E3 done (flag = Downto)
|
|
|
|
*)
|
2013-04-17 05:23:44 -07:00
|
|
|
| Pexp_constraint of expression * core_type
|
|
|
|
(* (E : T) *)
|
|
|
|
| Pexp_coerce of expression * core_type option * core_type
|
|
|
|
(* (E :> T) (None, T)
|
|
|
|
(E : T0 :> T) (Some T0, T)
|
2013-04-12 10:20:47 -07:00
|
|
|
*)
|
1996-05-16 09:10:16 -07:00
|
|
|
| Pexp_send of expression * string
|
2013-04-12 10:20:47 -07:00
|
|
|
(* E # m *)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Pexp_new of Longident.t loc
|
2013-04-12 10:20:47 -07:00
|
|
|
(* new M.c *)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Pexp_setinstvar of string loc * expression
|
2013-04-12 10:20:47 -07:00
|
|
|
(* x <- 2 *)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Pexp_override of (string loc * expression) list
|
2013-04-12 10:20:47 -07:00
|
|
|
(* {< x1 = E1; ...; Xn = En >} *)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Pexp_letmodule of string loc * module_expr * expression
|
2013-04-12 10:20:47 -07:00
|
|
|
(* let module M = ME in E *)
|
2000-12-04 07:37:05 -08:00
|
|
|
| Pexp_assert of expression
|
2013-04-12 10:20:47 -07:00
|
|
|
(* assert E
|
2014-04-12 03:17:02 -07:00
|
|
|
Note: "assert false" is treated in a special way by the
|
|
|
|
type-checker. *)
|
2002-01-20 09:39:10 -08:00
|
|
|
| Pexp_lazy of expression
|
2013-04-12 10:20:47 -07:00
|
|
|
(* lazy E *)
|
2002-04-18 00:27:47 -07:00
|
|
|
| Pexp_poly of expression * core_type option
|
2013-04-12 10:20:47 -07:00
|
|
|
(* Used for method bodies.
|
2013-04-15 10:26:32 -07:00
|
|
|
|
|
|
|
Can only be used as the expression under Cfk_concrete
|
|
|
|
for methods (not values). *)
|
2003-11-25 00:46:45 -08:00
|
|
|
| Pexp_object of class_structure
|
2013-04-12 10:20:47 -07:00
|
|
|
(* object ... end *)
|
2009-10-06 05:51:42 -07:00
|
|
|
| Pexp_newtype of string * expression
|
2013-04-12 10:20:47 -07:00
|
|
|
(* fun (type t) -> E *)
|
2010-10-21 16:59:33 -07:00
|
|
|
| Pexp_pack of module_expr
|
2013-04-12 10:20:47 -07:00
|
|
|
(* (module ME)
|
|
|
|
|
|
|
|
(module ME : S) is represented as
|
2013-04-17 06:48:35 -07:00
|
|
|
Pexp_constraint(Pexp_pack, Ptyp_package S) *)
|
2013-05-16 06:34:53 -07:00
|
|
|
| Pexp_open of override_flag * Longident.t loc * expression
|
2014-04-15 04:27:22 -07:00
|
|
|
(* let open M in E
|
2014-04-22 08:28:20 -07:00
|
|
|
let! open M in E
|
2014-04-15 04:27:22 -07:00
|
|
|
*)
|
2013-02-28 08:51:59 -08:00
|
|
|
| Pexp_extension of extension
|
2013-04-19 00:40:57 -07:00
|
|
|
(* [%id] *)
|
2013-04-12 10:20:47 -07:00
|
|
|
|
2013-04-15 09:23:22 -07:00
|
|
|
and case = (* (P -> E) or (P when E0 -> E) *)
|
2013-04-16 00:37:16 -07:00
|
|
|
{
|
|
|
|
pc_lhs: pattern;
|
|
|
|
pc_guard: expression option;
|
|
|
|
pc_rhs: expression;
|
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
(* Value descriptions *)
|
|
|
|
|
1998-02-26 04:54:44 -08:00
|
|
|
and value_description =
|
2013-04-16 00:37:16 -07:00
|
|
|
{
|
|
|
|
pval_name: string loc;
|
|
|
|
pval_type: core_type;
|
|
|
|
pval_prim: string list;
|
2013-04-19 00:40:57 -07:00
|
|
|
pval_attributes: attributes; (* ... [@@id1] [@@id2] *)
|
2013-04-16 00:37:16 -07:00
|
|
|
pval_loc: Location.t;
|
2012-05-30 07:52:37 -07:00
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2013-04-16 01:59:09 -07:00
|
|
|
(*
|
2013-04-16 02:31:16 -07:00
|
|
|
val x: T (prim = [])
|
|
|
|
external x: T = "s1" ... "sn" (prim = ["s1";..."sn"])
|
2013-04-16 01:59:09 -07:00
|
|
|
*)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Type declarations *)
|
|
|
|
|
1998-02-26 04:54:44 -08:00
|
|
|
and type_declaration =
|
2013-04-16 00:37:16 -07:00
|
|
|
{
|
|
|
|
ptype_name: string loc;
|
2014-05-04 16:08:45 -07:00
|
|
|
ptype_params: (core_type * variance) list;
|
2013-04-16 01:59:09 -07:00
|
|
|
(* ('a1,...'an) t; None represents _*)
|
2013-04-16 00:37:16 -07:00
|
|
|
ptype_cstrs: (core_type * core_type * Location.t) list;
|
2013-04-16 01:59:09 -07:00
|
|
|
(* ... constraint T1=T1' ... constraint Tn=Tn' *)
|
2013-04-16 00:37:16 -07:00
|
|
|
ptype_kind: type_kind;
|
2013-04-16 01:59:09 -07:00
|
|
|
ptype_private: private_flag; (* = private ... *)
|
|
|
|
ptype_manifest: core_type option; (* = T *)
|
2013-04-19 00:40:57 -07:00
|
|
|
ptype_attributes: attributes; (* ... [@@id1] [@@id2] *)
|
2013-04-16 00:37:16 -07:00
|
|
|
ptype_loc: Location.t;
|
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2013-04-16 01:59:09 -07:00
|
|
|
(*
|
|
|
|
type t (abstract, no manifest)
|
|
|
|
type t = T0 (abstract, manifest=T0)
|
|
|
|
type t = C of T | ... (variant, no manifest)
|
|
|
|
type t = T0 = C of T | ... (variant, manifest=T0)
|
|
|
|
type t = {l: T; ...} (record, no manifest)
|
|
|
|
type t = T0 = {l : T; ...} (record, manifest=T0)
|
2014-05-04 16:08:45 -07:00
|
|
|
type t = .. (open, no manifest)
|
2013-04-16 01:59:09 -07:00
|
|
|
*)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
and type_kind =
|
2013-04-16 00:37:16 -07:00
|
|
|
| Ptype_abstract
|
2013-03-04 07:35:47 -08:00
|
|
|
| Ptype_variant of constructor_declaration list
|
2014-08-22 06:45:02 -07:00
|
|
|
(* Invariant: non-empty list *)
|
2013-03-06 05:51:18 -08:00
|
|
|
| Ptype_record of label_declaration list
|
2014-08-22 06:45:02 -07:00
|
|
|
(* Invariant: non-empty list *)
|
2014-05-04 16:08:45 -07:00
|
|
|
| Ptype_open
|
2013-03-06 05:51:18 -08:00
|
|
|
|
|
|
|
and label_declaration =
|
|
|
|
{
|
|
|
|
pld_name: string loc;
|
|
|
|
pld_mutable: mutable_flag;
|
|
|
|
pld_type: core_type;
|
|
|
|
pld_loc: Location.t;
|
2013-04-19 00:40:57 -07:00
|
|
|
pld_attributes: attributes; (* l [@id1] [@id2] : T *)
|
2013-03-06 05:51:18 -08:00
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2013-04-16 01:59:09 -07:00
|
|
|
(* { ...; l: T; ... } (mutable=Immutable)
|
|
|
|
{ ...; mutable l: T; ... } (mutable=Mutable)
|
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
Note: T can be a Ptyp_poly.
|
2013-04-16 01:59:09 -07:00
|
|
|
*)
|
|
|
|
|
2013-03-04 07:35:47 -08:00
|
|
|
and constructor_declaration =
|
|
|
|
{
|
|
|
|
pcd_name: string loc;
|
2014-03-28 10:08:53 -07:00
|
|
|
pcd_args: constructor_arguments;
|
2013-03-04 07:35:47 -08:00
|
|
|
pcd_res: core_type option;
|
|
|
|
pcd_loc: Location.t;
|
2013-04-19 00:40:57 -07:00
|
|
|
pcd_attributes: attributes; (* C [@id1] [@id2] of ... *)
|
2013-03-04 07:35:47 -08:00
|
|
|
}
|
2014-03-28 10:08:53 -07:00
|
|
|
|
|
|
|
and constructor_arguments =
|
|
|
|
| Pcstr_tuple of core_type list
|
2014-04-04 01:57:05 -07:00
|
|
|
| Pcstr_record of label_declaration list
|
2014-03-28 10:08:53 -07:00
|
|
|
|
2013-04-16 01:59:09 -07:00
|
|
|
(*
|
2014-04-01 09:15:07 -07:00
|
|
|
| C of T1 * ... * Tn (res = None, args = Pcstr_tuple [])
|
|
|
|
| C: T0 (res = Some T0, args = [])
|
|
|
|
| C: T1 * ... * Tn -> T0 (res = Some T0, args = Pcstr_tuple)
|
|
|
|
| C of {...} (res = None, args = Pcstr_record)
|
|
|
|
| C: {...} -> T0 (res = Some T0, args = Pcstr_record)
|
|
|
|
| C of {...} as t (res = None, args = Pcstr_record)
|
2013-04-16 01:59:09 -07:00
|
|
|
*)
|
2013-03-04 07:35:47 -08:00
|
|
|
|
2014-05-04 16:08:45 -07:00
|
|
|
and type_extension =
|
2014-04-15 04:26:00 -07:00
|
|
|
{
|
2014-05-04 16:08:45 -07:00
|
|
|
ptyext_path: Longident.t loc;
|
|
|
|
ptyext_params: (core_type * variance) list;
|
|
|
|
ptyext_constructors: extension_constructor list;
|
|
|
|
ptyext_private: private_flag;
|
|
|
|
ptyext_attributes: attributes; (* ... [@@id1] [@@id2] *)
|
|
|
|
}
|
|
|
|
(*
|
|
|
|
type t += ...
|
|
|
|
*)
|
|
|
|
|
|
|
|
and extension_constructor =
|
|
|
|
{
|
|
|
|
pext_name: string loc;
|
|
|
|
pext_kind : extension_constructor_kind;
|
|
|
|
pext_loc : Location.t;
|
|
|
|
pext_attributes: attributes; (* C [@id1] [@id2] of ... *)
|
2014-04-15 04:26:00 -07:00
|
|
|
}
|
2014-05-04 16:08:45 -07:00
|
|
|
|
|
|
|
and extension_constructor_kind =
|
2014-10-14 08:51:30 -07:00
|
|
|
Pext_decl of constructor_arguments * core_type option
|
2014-05-04 16:08:45 -07:00
|
|
|
(*
|
|
|
|
| C of T1 * ... * Tn ([T1; ...; Tn], None)
|
|
|
|
| C: T0 ([], Some T0)
|
|
|
|
| C: T1 * ... * Tn -> T0 ([T1; ...; Tn], Some T0)
|
|
|
|
*)
|
|
|
|
| Pext_rebind of Longident.t loc
|
|
|
|
(*
|
|
|
|
| C = D
|
|
|
|
*)
|
2014-04-15 04:26:00 -07:00
|
|
|
|
2013-04-16 00:58:04 -07:00
|
|
|
(** {2 Class language} *)
|
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
(* Type expressions for the class language *)
|
|
|
|
|
1998-02-26 04:54:44 -08:00
|
|
|
and class_type =
|
2013-04-10 10:44:15 -07:00
|
|
|
{
|
|
|
|
pcty_desc: class_type_desc;
|
|
|
|
pcty_loc: Location.t;
|
2013-04-19 00:40:57 -07:00
|
|
|
pcty_attributes: attributes; (* ... [@id1] [@id2] *)
|
2013-04-10 10:44:15 -07:00
|
|
|
}
|
1996-04-22 04:15:41 -07:00
|
|
|
|
1998-06-24 12:22:26 -07:00
|
|
|
and class_type_desc =
|
2013-04-16 00:37:16 -07:00
|
|
|
| Pcty_constr of Longident.t loc * core_type list
|
2013-04-16 02:11:54 -07:00
|
|
|
(* c
|
|
|
|
['a1, ..., 'an] c *)
|
1998-06-24 12:22:26 -07:00
|
|
|
| Pcty_signature of class_signature
|
2013-04-16 01:59:09 -07:00
|
|
|
(* object ... end *)
|
2014-12-22 00:45:55 -08:00
|
|
|
| Pcty_arrow of arg_label * core_type * class_type
|
|
|
|
(* T -> CT Simple
|
|
|
|
~l:T -> CT Labelled l
|
|
|
|
?l:T -> CT Optional l
|
2013-04-16 01:59:09 -07:00
|
|
|
*)
|
2013-04-10 10:44:15 -07:00
|
|
|
| Pcty_extension of extension
|
2013-04-19 00:40:57 -07:00
|
|
|
(* [%id] *)
|
1998-06-24 12:22:26 -07:00
|
|
|
|
2013-04-16 00:37:16 -07:00
|
|
|
and class_signature =
|
|
|
|
{
|
|
|
|
pcsig_self: core_type;
|
|
|
|
pcsig_fields: class_type_field list;
|
|
|
|
}
|
2013-04-16 02:21:05 -07:00
|
|
|
(* object('selfpat) ... end
|
|
|
|
object ... end (self = Ptyp_any)
|
|
|
|
*)
|
2012-05-30 07:52:37 -07:00
|
|
|
|
2013-04-16 00:37:16 -07:00
|
|
|
and class_type_field =
|
|
|
|
{
|
|
|
|
pctf_desc: class_type_field_desc;
|
|
|
|
pctf_loc: Location.t;
|
2013-04-19 00:40:57 -07:00
|
|
|
pctf_attributes: attributes; (* ... [@@id1] [@@id2] *)
|
2013-04-16 00:37:16 -07:00
|
|
|
}
|
1998-06-24 12:22:26 -07:00
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
and class_type_field_desc =
|
2013-04-16 00:37:16 -07:00
|
|
|
| Pctf_inherit of class_type
|
2013-04-16 02:11:54 -07:00
|
|
|
(* inherit CT *)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Pctf_val of (string * mutable_flag * virtual_flag * core_type)
|
2013-04-16 02:11:54 -07:00
|
|
|
(* val x: T *)
|
2013-04-10 04:17:41 -07:00
|
|
|
| Pctf_method of (string * private_flag * virtual_flag * core_type)
|
2013-04-16 02:11:54 -07:00
|
|
|
(* method x: T
|
|
|
|
|
2014-08-22 06:45:02 -07:00
|
|
|
Note: T can be a Ptyp_poly.
|
2013-04-16 02:11:54 -07:00
|
|
|
*)
|
2013-04-10 04:17:41 -07:00
|
|
|
| Pctf_constraint of (core_type * core_type)
|
2013-04-16 02:11:54 -07:00
|
|
|
(* constraint T1 = T2 *)
|
2014-05-04 13:42:34 -07:00
|
|
|
| Pctf_attribute of attribute
|
|
|
|
(* [@@@id] *)
|
2013-04-10 10:54:54 -07:00
|
|
|
| Pctf_extension of extension
|
2013-04-19 00:40:57 -07:00
|
|
|
(* [%%id] *)
|
1998-06-24 12:22:26 -07:00
|
|
|
|
2013-04-16 00:58:04 -07:00
|
|
|
and 'a class_infos =
|
|
|
|
{
|
|
|
|
pci_virt: virtual_flag;
|
2014-05-04 16:08:45 -07:00
|
|
|
pci_params: (core_type * variance) list;
|
2013-04-16 00:58:04 -07:00
|
|
|
pci_name: string loc;
|
|
|
|
pci_expr: 'a;
|
|
|
|
pci_loc: Location.t;
|
2013-04-19 00:40:57 -07:00
|
|
|
pci_attributes: attributes; (* ... [@@id1] [@@id2] *)
|
2013-04-16 00:58:04 -07:00
|
|
|
}
|
2013-04-16 02:11:54 -07:00
|
|
|
(* class c = ...
|
|
|
|
class ['a1,...,'an] c = ...
|
|
|
|
class virtual c = ...
|
|
|
|
|
|
|
|
Also used for "class type" declaration.
|
|
|
|
*)
|
2013-04-16 00:58:04 -07:00
|
|
|
|
1998-06-24 12:22:26 -07:00
|
|
|
and class_description = class_type class_infos
|
|
|
|
|
|
|
|
and class_type_declaration = class_type class_infos
|
|
|
|
|
|
|
|
(* Value expressions for the class language *)
|
|
|
|
|
|
|
|
and class_expr =
|
2013-04-16 00:37:16 -07:00
|
|
|
{
|
|
|
|
pcl_desc: class_expr_desc;
|
|
|
|
pcl_loc: Location.t;
|
2013-04-19 00:40:57 -07:00
|
|
|
pcl_attributes: attributes; (* ... [@id1] [@id2] *)
|
2013-04-16 00:37:16 -07:00
|
|
|
}
|
1996-04-22 04:15:41 -07:00
|
|
|
|
1998-06-24 12:22:26 -07:00
|
|
|
and class_expr_desc =
|
2013-04-16 00:37:16 -07:00
|
|
|
| Pcl_constr of Longident.t loc * core_type list
|
2013-04-16 02:11:54 -07:00
|
|
|
(* c
|
|
|
|
['a1, ..., 'an] c *)
|
1998-06-24 12:22:26 -07:00
|
|
|
| Pcl_structure of class_structure
|
2013-04-16 02:11:54 -07:00
|
|
|
(* object ... end *)
|
2014-12-22 00:45:55 -08:00
|
|
|
| Pcl_fun of arg_label * expression option * pattern * class_expr
|
|
|
|
(* fun P -> CE (Simple, None)
|
|
|
|
fun ~l:P -> CE (Labelled l, None)
|
|
|
|
fun ?l:P -> CE (Optional l, None)
|
|
|
|
fun ?l:(P = E0) -> CE (Optional l, Some E0)
|
2013-04-16 02:11:54 -07:00
|
|
|
*)
|
2014-12-22 00:45:55 -08:00
|
|
|
| Pcl_apply of class_expr * (arg_label * expression) list
|
2013-04-16 02:11:54 -07:00
|
|
|
(* CE ~l1:E1 ... ~ln:En
|
|
|
|
li can be empty (non labeled argument) or start with '?'
|
|
|
|
(optional argument).
|
2014-08-22 06:45:02 -07:00
|
|
|
|
|
|
|
Invariant: n > 0
|
2013-04-16 02:11:54 -07:00
|
|
|
*)
|
2013-06-03 08:14:19 -07:00
|
|
|
| Pcl_let of rec_flag * value_binding list * class_expr
|
2013-04-16 02:11:54 -07:00
|
|
|
(* let P1 = E1 and ... and Pn = EN in CE (flag = Nonrecursive)
|
|
|
|
let rec P1 = E1 and ... and Pn = EN in CE (flag = Recursive)
|
|
|
|
*)
|
1998-06-24 12:22:26 -07:00
|
|
|
| Pcl_constraint of class_expr * class_type
|
2013-04-16 02:11:54 -07:00
|
|
|
(* (CE : CT) *)
|
2013-04-10 10:26:55 -07:00
|
|
|
| Pcl_extension of extension
|
2013-04-19 00:40:57 -07:00
|
|
|
(* [%id] *)
|
1998-06-24 12:22:26 -07:00
|
|
|
|
2013-04-16 00:37:16 -07:00
|
|
|
and class_structure =
|
|
|
|
{
|
|
|
|
pcstr_self: pattern;
|
|
|
|
pcstr_fields: class_field list;
|
|
|
|
}
|
2013-04-16 02:21:05 -07:00
|
|
|
(* object(selfpat) ... end
|
|
|
|
object ... end (self = Ppat_any)
|
|
|
|
*)
|
2012-05-30 07:52:37 -07:00
|
|
|
|
2013-04-16 00:37:16 -07:00
|
|
|
and class_field =
|
|
|
|
{
|
|
|
|
pcf_desc: class_field_desc;
|
|
|
|
pcf_loc: Location.t;
|
2014-04-15 06:06:35 -07:00
|
|
|
pcf_attributes: attributes; (* ... [@@id1] [@@id2] *)
|
2013-04-16 00:37:16 -07:00
|
|
|
}
|
1998-06-24 12:22:26 -07:00
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
and class_field_desc =
|
2013-04-16 00:37:16 -07:00
|
|
|
| Pcf_inherit of override_flag * class_expr * string option
|
2013-04-16 02:31:16 -07:00
|
|
|
(* inherit CE
|
|
|
|
inherit CE as x
|
|
|
|
inherit! CE
|
|
|
|
inherit! CE as x
|
|
|
|
*)
|
2013-04-10 04:17:41 -07:00
|
|
|
| Pcf_val of (string loc * mutable_flag * class_field_kind)
|
2013-04-16 02:31:16 -07:00
|
|
|
(* val x = E
|
|
|
|
val virtual x: T
|
|
|
|
*)
|
2013-04-10 04:17:41 -07:00
|
|
|
| Pcf_method of (string loc * private_flag * class_field_kind)
|
2013-04-16 02:31:16 -07:00
|
|
|
(* method x = E (E can be a Pexp_poly)
|
|
|
|
method virtual x: T (T can be a Ptyp_poly)
|
|
|
|
*)
|
2013-04-10 04:17:41 -07:00
|
|
|
| Pcf_constraint of (core_type * core_type)
|
2013-04-16 02:31:16 -07:00
|
|
|
(* constraint T1 = T2 *)
|
2013-04-10 04:17:41 -07:00
|
|
|
| Pcf_initializer of expression
|
2013-04-16 02:31:16 -07:00
|
|
|
(* initializer E *)
|
2014-05-04 13:42:34 -07:00
|
|
|
| Pcf_attribute of attribute
|
|
|
|
(* [@@@id] *)
|
2013-04-10 10:54:54 -07:00
|
|
|
| Pcf_extension of extension
|
2014-04-16 05:40:24 -07:00
|
|
|
(* [%%id] *)
|
2013-04-10 04:17:41 -07:00
|
|
|
|
|
|
|
and class_field_kind =
|
|
|
|
| Cfk_virtual of core_type
|
|
|
|
| Cfk_concrete of override_flag * expression
|
1998-06-24 12:22:26 -07:00
|
|
|
|
|
|
|
and class_declaration = class_expr class_infos
|
|
|
|
|
2013-04-16 00:58:04 -07:00
|
|
|
(** {2 Module language} *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Type expressions for the module language *)
|
|
|
|
|
1998-02-26 04:54:44 -08:00
|
|
|
and module_type =
|
2013-04-16 00:37:16 -07:00
|
|
|
{
|
|
|
|
pmty_desc: module_type_desc;
|
|
|
|
pmty_loc: Location.t;
|
2013-04-19 00:40:57 -07:00
|
|
|
pmty_attributes: attributes; (* ... [@id1] [@id2] *)
|
2013-04-16 00:37:16 -07:00
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and module_type_desc =
|
2013-04-16 00:37:16 -07:00
|
|
|
| Pmty_ident of Longident.t loc
|
2013-04-16 03:53:50 -07:00
|
|
|
(* S *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pmty_signature of signature
|
2013-04-16 02:31:16 -07:00
|
|
|
(* sig ... end *)
|
2013-12-16 19:52:50 -08:00
|
|
|
| Pmty_functor of string loc * module_type option * module_type
|
2013-04-16 02:31:16 -07:00
|
|
|
(* functor(X : MT1) -> MT2 *)
|
2013-04-16 03:47:45 -07:00
|
|
|
| Pmty_with of module_type * with_constraint list
|
2013-04-16 02:31:16 -07:00
|
|
|
(* MT with ... *)
|
2010-04-02 05:53:33 -07:00
|
|
|
| Pmty_typeof of module_expr
|
2013-04-16 02:31:16 -07:00
|
|
|
(* module type of ME *)
|
2013-03-04 06:11:15 -08:00
|
|
|
| Pmty_extension of extension
|
2013-04-19 00:40:57 -07:00
|
|
|
(* [%id] *)
|
2013-09-29 00:22:34 -07:00
|
|
|
| Pmty_alias of Longident.t loc
|
|
|
|
(* (module M) *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and signature = signature_item list
|
|
|
|
|
|
|
|
and signature_item =
|
2013-04-16 00:37:16 -07:00
|
|
|
{
|
|
|
|
psig_desc: signature_item_desc;
|
|
|
|
psig_loc: Location.t;
|
|
|
|
}
|
1995-10-05 08:18:49 -07:00
|
|
|
|
|
|
|
and signature_item_desc =
|
2013-04-16 00:37:16 -07:00
|
|
|
| Psig_value of value_description
|
2013-04-16 02:31:16 -07:00
|
|
|
(*
|
|
|
|
val x: T
|
|
|
|
external x: T = "s1" ... "sn"
|
|
|
|
*)
|
2013-03-06 03:47:59 -08:00
|
|
|
| Psig_type of type_declaration list
|
2013-04-16 02:31:16 -07:00
|
|
|
(* type t1 = ... and ... and tn = ... *)
|
2014-05-04 16:08:45 -07:00
|
|
|
| Psig_typext of type_extension
|
|
|
|
(* type t1 += ... *)
|
|
|
|
| Psig_exception of extension_constructor
|
2013-04-16 02:31:16 -07:00
|
|
|
(* exception C of T *)
|
2013-03-04 09:39:07 -08:00
|
|
|
| Psig_module of module_declaration
|
2013-04-16 02:31:16 -07:00
|
|
|
(* module X : MT *)
|
2013-03-04 09:39:07 -08:00
|
|
|
| Psig_recmodule of module_declaration list
|
2013-04-16 02:31:16 -07:00
|
|
|
(* module rec X1 : MT1 and ... and Xn : MTn *)
|
2013-03-06 04:14:02 -08:00
|
|
|
| Psig_modtype of module_type_declaration
|
2013-04-18 06:14:53 -07:00
|
|
|
(* module type S = MT
|
2013-04-16 03:53:50 -07:00
|
|
|
module type S *)
|
2014-04-15 04:26:00 -07:00
|
|
|
| Psig_open of open_description
|
2013-04-16 02:31:16 -07:00
|
|
|
(* open X *)
|
2014-04-15 04:26:00 -07:00
|
|
|
| Psig_include of include_description
|
2013-04-16 02:31:16 -07:00
|
|
|
(* include MT *)
|
1998-06-24 12:22:26 -07:00
|
|
|
| Psig_class of class_description list
|
2013-04-16 03:53:50 -07:00
|
|
|
(* class c1 : ... and ... and cn : ... *)
|
1998-06-24 12:22:26 -07:00
|
|
|
| Psig_class_type of class_type_declaration list
|
2013-04-16 02:31:16 -07:00
|
|
|
(* class type ct1 = ... and ... and ctn = ... *)
|
2013-03-06 04:27:32 -08:00
|
|
|
| Psig_attribute of attribute
|
2014-04-15 04:28:03 -07:00
|
|
|
(* [@@@id] *)
|
2013-04-10 11:00:11 -07:00
|
|
|
| Psig_extension of extension * attributes
|
2013-04-19 00:40:57 -07:00
|
|
|
(* [%%id] *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2013-03-04 09:39:07 -08:00
|
|
|
and module_declaration =
|
|
|
|
{
|
|
|
|
pmd_name: string loc;
|
|
|
|
pmd_type: module_type;
|
2013-04-19 00:40:57 -07:00
|
|
|
pmd_attributes: attributes; (* ... [@@id1] [@@id2] *)
|
2014-01-30 04:18:34 -08:00
|
|
|
pmd_loc: Location.t;
|
2013-03-04 09:39:07 -08:00
|
|
|
}
|
2013-04-18 06:14:53 -07:00
|
|
|
(* S : MT *)
|
2013-03-04 09:39:07 -08:00
|
|
|
|
2013-03-06 04:14:02 -08:00
|
|
|
and module_type_declaration =
|
|
|
|
{
|
|
|
|
pmtd_name: string loc;
|
|
|
|
pmtd_type: module_type option;
|
2013-04-19 00:40:57 -07:00
|
|
|
pmtd_attributes: attributes; (* ... [@@id1] [@@id2] *)
|
2014-01-30 04:18:34 -08:00
|
|
|
pmtd_loc: Location.t;
|
2013-03-06 04:14:02 -08:00
|
|
|
}
|
2013-04-18 06:14:53 -07:00
|
|
|
(* S = MT
|
|
|
|
S (abstract module type declaration, pmtd_type = None)
|
|
|
|
*)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2014-04-15 04:26:00 -07:00
|
|
|
and open_description =
|
|
|
|
{
|
|
|
|
popen_lid: Longident.t loc;
|
|
|
|
popen_override: override_flag;
|
2014-04-22 08:28:20 -07:00
|
|
|
popen_loc: Location.t;
|
2014-04-15 04:26:00 -07:00
|
|
|
popen_attributes: attributes;
|
|
|
|
}
|
2014-04-15 05:05:40 -07:00
|
|
|
(* open! X - popen_override = Override (silences the 'used identifier
|
|
|
|
shadowing' warning)
|
2014-04-15 04:27:22 -07:00
|
|
|
open X - popen_override = Fresh
|
2014-04-15 04:26:00 -07:00
|
|
|
*)
|
|
|
|
|
|
|
|
and 'a include_infos =
|
|
|
|
{
|
|
|
|
pincl_mod: 'a;
|
2014-04-22 08:28:20 -07:00
|
|
|
pincl_loc: Location.t;
|
2014-04-15 04:26:00 -07:00
|
|
|
pincl_attributes: attributes;
|
|
|
|
}
|
|
|
|
|
|
|
|
and include_description = module_type include_infos
|
|
|
|
(* include MT *)
|
|
|
|
|
|
|
|
and include_declaration = module_expr include_infos
|
|
|
|
(* include ME *)
|
|
|
|
|
1995-10-01 06:39:43 -07:00
|
|
|
and with_constraint =
|
2013-04-16 03:47:45 -07:00
|
|
|
| Pwith_type of Longident.t loc * type_declaration
|
|
|
|
(* with type X.t = ...
|
|
|
|
|
|
|
|
Note: the last component of the longident must match
|
|
|
|
the name of the type_declaration. *)
|
|
|
|
| Pwith_module of Longident.t loc * Longident.t loc
|
|
|
|
(* with module X.Y = Z *)
|
2010-04-17 07:45:12 -07:00
|
|
|
| Pwith_typesubst of type_declaration
|
2013-04-16 03:47:45 -07:00
|
|
|
(* with type t := ... *)
|
|
|
|
| Pwith_modsubst of string loc * Longident.t loc
|
|
|
|
(* with module X := Z *)
|
1995-10-01 06:39:43 -07:00
|
|
|
|
2011-10-28 14:26:01 -07:00
|
|
|
(* Value expressions for the module language *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1998-02-26 04:54:44 -08:00
|
|
|
and module_expr =
|
2013-04-16 00:37:16 -07:00
|
|
|
{
|
|
|
|
pmod_desc: module_expr_desc;
|
|
|
|
pmod_loc: Location.t;
|
2013-04-19 00:40:57 -07:00
|
|
|
pmod_attributes: attributes; (* ... [@id1] [@id2] *)
|
2013-04-16 00:37:16 -07:00
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and module_expr_desc =
|
2013-04-16 00:37:16 -07:00
|
|
|
| Pmod_ident of Longident.t loc
|
2013-04-16 03:53:50 -07:00
|
|
|
(* X *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pmod_structure of structure
|
2013-04-16 03:53:50 -07:00
|
|
|
(* struct ... end *)
|
2013-12-16 19:52:50 -08:00
|
|
|
| Pmod_functor of string loc * module_type option * module_expr
|
2013-04-16 03:53:50 -07:00
|
|
|
(* functor(X : MT1) -> ME *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pmod_apply of module_expr * module_expr
|
2013-04-16 03:53:50 -07:00
|
|
|
(* ME1(ME2) *)
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pmod_constraint of module_expr * module_type
|
2013-04-16 03:53:50 -07:00
|
|
|
(* (ME : MT) *)
|
2010-10-21 16:59:33 -07:00
|
|
|
| Pmod_unpack of expression
|
2013-04-16 03:53:50 -07:00
|
|
|
(* (val E) *)
|
2013-03-04 04:54:57 -08:00
|
|
|
| Pmod_extension of extension
|
2013-04-19 00:40:57 -07:00
|
|
|
(* [%id] *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and structure = structure_item list
|
|
|
|
|
|
|
|
and structure_item =
|
2013-04-16 00:37:16 -07:00
|
|
|
{
|
|
|
|
pstr_desc: structure_item_desc;
|
|
|
|
pstr_loc: Location.t;
|
|
|
|
}
|
1995-10-05 08:18:49 -07:00
|
|
|
|
|
|
|
and structure_item_desc =
|
2013-04-16 00:37:16 -07:00
|
|
|
| Pstr_eval of expression * attributes
|
2013-04-16 03:53:50 -07:00
|
|
|
(* E *)
|
2013-06-03 08:14:19 -07:00
|
|
|
| Pstr_value of rec_flag * value_binding list
|
2013-04-16 03:53:50 -07:00
|
|
|
(* let P1 = E1 and ... and Pn = EN (flag = Nonrecursive)
|
|
|
|
let rec P1 = E1 and ... and Pn = EN (flag = Recursive)
|
|
|
|
*)
|
2013-03-06 04:00:18 -08:00
|
|
|
| Pstr_primitive of value_description
|
2014-12-10 05:39:39 -08:00
|
|
|
(* val x: T
|
|
|
|
external x: T = "s1" ... "sn" *)
|
2013-03-06 03:47:59 -08:00
|
|
|
| Pstr_type of type_declaration list
|
2013-04-16 03:53:50 -07:00
|
|
|
(* type t1 = ... and ... and tn = ... *)
|
2014-05-04 16:08:45 -07:00
|
|
|
| Pstr_typext of type_extension
|
|
|
|
(* type t1 += ... *)
|
|
|
|
| Pstr_exception of extension_constructor
|
|
|
|
(* exception C of T
|
|
|
|
exception C = M.X *)
|
2013-03-05 08:50:05 -08:00
|
|
|
| Pstr_module of module_binding
|
2013-04-16 03:53:50 -07:00
|
|
|
(* module X = ME *)
|
2013-03-05 08:50:05 -08:00
|
|
|
| Pstr_recmodule of module_binding list
|
2013-04-16 03:53:50 -07:00
|
|
|
(* module rec X1 = ME1 and ... and Xn = MEn *)
|
2013-04-18 06:14:53 -07:00
|
|
|
| Pstr_modtype of module_type_declaration
|
2013-04-16 03:53:50 -07:00
|
|
|
(* module type S = MT *)
|
2014-04-15 04:26:00 -07:00
|
|
|
| Pstr_open of open_description
|
|
|
|
(* open X *)
|
1998-06-24 12:22:26 -07:00
|
|
|
| Pstr_class of class_declaration list
|
2013-04-16 03:53:50 -07:00
|
|
|
(* class c1 = ... and ... and cn = ... *)
|
1998-06-24 12:22:26 -07:00
|
|
|
| Pstr_class_type of class_type_declaration list
|
2013-04-16 03:53:50 -07:00
|
|
|
(* class type ct1 = ... and ... and ctn = ... *)
|
2014-04-15 04:26:00 -07:00
|
|
|
| Pstr_include of include_declaration
|
2013-04-16 03:53:50 -07:00
|
|
|
(* include ME *)
|
2013-03-06 04:27:32 -08:00
|
|
|
| Pstr_attribute of attribute
|
2014-04-15 04:28:03 -07:00
|
|
|
(* [@@@id] *)
|
2013-04-10 11:00:11 -07:00
|
|
|
| Pstr_extension of extension * attributes
|
2013-04-19 00:40:57 -07:00
|
|
|
(* [%%id] *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2013-06-03 08:14:19 -07:00
|
|
|
and value_binding =
|
|
|
|
{
|
|
|
|
pvb_pat: pattern;
|
|
|
|
pvb_expr: expression;
|
|
|
|
pvb_attributes: attributes;
|
2014-04-22 08:28:20 -07:00
|
|
|
pvb_loc: Location.t;
|
2013-06-03 08:14:19 -07:00
|
|
|
}
|
|
|
|
|
2013-03-05 08:50:05 -08:00
|
|
|
and module_binding =
|
|
|
|
{
|
|
|
|
pmb_name: string loc;
|
|
|
|
pmb_expr: module_expr;
|
2013-04-10 11:00:11 -07:00
|
|
|
pmb_attributes: attributes;
|
2014-01-30 04:18:34 -08:00
|
|
|
pmb_loc: Location.t;
|
2013-03-05 08:50:05 -08:00
|
|
|
}
|
2013-04-16 03:53:50 -07:00
|
|
|
(* X = ME *)
|
2013-03-05 08:50:05 -08:00
|
|
|
|
2013-04-16 00:58:04 -07:00
|
|
|
(** {2 Toplevel} *)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
(* Toplevel phrases *)
|
|
|
|
|
|
|
|
type toplevel_phrase =
|
2013-04-16 00:37:16 -07:00
|
|
|
| Ptop_def of structure
|
2014-04-28 01:04:43 -07:00
|
|
|
| Ptop_dir of string * directive_argument
|
2014-04-11 23:56:51 -07:00
|
|
|
(* #use, #load ... *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
and directive_argument =
|
2014-04-28 01:04:43 -07:00
|
|
|
| Pdir_none
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pdir_string of string
|
|
|
|
| Pdir_int of int
|
|
|
|
| Pdir_ident of Longident.t
|
1999-12-03 02:26:08 -08:00
|
|
|
| Pdir_bool of bool
|