2016-02-18 07:11:59 -08:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* OCaml *)
|
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique. *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. This file is distributed under the terms of *)
|
|
|
|
(* the GNU Lesser General Public License version 2.1, with the *)
|
|
|
|
(* special exception on linking described in the file LICENSE. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
1995-08-09 08:06:35 -07:00
|
|
|
|
2018-09-12 00:51:47 -07:00
|
|
|
(** Abstract syntax tree produced by parsing
|
|
|
|
|
|
|
|
{b Warning:} this module is unstable and part of
|
2018-09-12 06:36:40 -07:00
|
|
|
{{!Compiler_libs}compiler-libs}.
|
2018-09-12 00:51:47 -07:00
|
|
|
|
|
|
|
*)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
open Asttypes
|
|
|
|
|
2015-04-18 20:07:32 -07:00
|
|
|
type constant =
|
2016-01-08 06:48:47 -08:00
|
|
|
Pconst_integer of string * char option
|
2016-01-07 07:01:23 -08:00
|
|
|
(* 3 3l 3L 3n
|
|
|
|
|
|
|
|
Suffixes [g-z][G-Z] are accepted by the parser.
|
|
|
|
Suffixes except 'l', 'L' and 'n' are rejected by the typechecker
|
|
|
|
*)
|
2016-01-08 06:48:47 -08:00
|
|
|
| Pconst_char of char
|
2016-01-07 07:01:23 -08:00
|
|
|
(* 'c' *)
|
2019-07-22 09:04:09 -07:00
|
|
|
| Pconst_string of string * Location.t * string option
|
2016-01-07 07:01:23 -08:00
|
|
|
(* "constant"
|
|
|
|
{delim|other constant|delim}
|
2019-07-22 09:04:09 -07:00
|
|
|
|
|
|
|
The location span the content of the string, without the delimiters.
|
2016-01-07 07:01:23 -08:00
|
|
|
*)
|
2016-01-08 06:48:47 -08:00
|
|
|
| Pconst_float of string * char option
|
2016-01-07 07:01:23 -08:00
|
|
|
(* 3.4 2e5 1.4e-4
|
|
|
|
|
|
|
|
Suffixes [g-z][G-Z] are accepted by the parser.
|
|
|
|
Suffixes are rejected by the typechecker.
|
|
|
|
*)
|
2015-04-18 20:07:32 -07:00
|
|
|
|
2019-07-12 03:18:28 -07:00
|
|
|
type location_stack = Location.t list
|
|
|
|
|
2016-10-01 13:35:05 -07:00
|
|
|
(** {1 Extension points} *)
|
2013-02-28 08:51:59 -08:00
|
|
|
|
2018-07-21 05:04:53 -07:00
|
|
|
type attribute = {
|
|
|
|
attr_name : string loc;
|
|
|
|
attr_payload : payload;
|
|
|
|
attr_loc : Location.t;
|
|
|
|
}
|
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
|
2015-12-02 06:20:26 -08:00
|
|
|
| PSig of signature (* : SIG *)
|
2013-07-22 08:15:07 -07:00
|
|
|
| PTyp of core_type (* : T *)
|
2014-12-23 08:52:51 -08:00
|
|
|
| PPat of pattern * expression option (* ? P or ? P when E *)
|
2013-07-22 07:58:15 -07:00
|
|
|
|
2016-10-01 13:35:05 -07:00
|
|
|
(** {1 Core language} *)
|
2013-04-16 00:58:04 -07:00
|
|
|
|
|
|
|
(* 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;
|
2019-07-12 03:18:28 -07:00
|
|
|
ptyp_loc_stack: location_stack;
|
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
|
2017-08-10 03:59:23 -07:00
|
|
|
?l:T1 -> T2 Optional
|
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
|
|
|
|
*)
|
2017-03-09 20:46:48 -08:00
|
|
|
| Ptyp_object of object_field 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"])
|
|
|
|
*)
|
2016-08-29 07:21:38 -07:00
|
|
|
| Ptyp_poly of string loc 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
|
|
|
|
2018-07-14 14:10:39 -07:00
|
|
|
and row_field = {
|
|
|
|
prf_desc : row_field_desc;
|
|
|
|
prf_loc : Location.t;
|
2018-08-16 23:36:36 -07:00
|
|
|
prf_attributes : attributes;
|
2018-07-14 14:10:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
and row_field_desc =
|
2018-08-16 23:36:36 -07:00
|
|
|
| Rtag of label loc * 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
|
|
|
|
2018-08-16 23:36:36 -07:00
|
|
|
- The 'bool' field is true if the tag contains a
|
2014-04-11 23:56:51 -07:00
|
|
|
constant (empty) constructor.
|
|
|
|
- '&' occurs when several types are used for the same constructor
|
|
|
|
(see 4.2 in the manual)
|
|
|
|
*)
|
2001-09-25 02:54:18 -07:00
|
|
|
| Rinherit of core_type
|
2020-09-09 13:37:36 -07:00
|
|
|
(* [ | t ] *)
|
2001-09-25 02:54:18 -07:00
|
|
|
|
2018-07-14 14:10:39 -07:00
|
|
|
and object_field = {
|
|
|
|
pof_desc : object_field_desc;
|
|
|
|
pof_loc : Location.t;
|
2018-08-16 23:36:36 -07:00
|
|
|
pof_attributes : attributes;
|
2018-07-14 14:10:39 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
and object_field_desc =
|
2018-08-16 23:36:36 -07:00
|
|
|
| Otag of label loc * core_type
|
2017-03-09 20:46:48 -08:00
|
|
|
| Oinherit of core_type
|
|
|
|
|
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;
|
2019-07-12 03:18:28 -07:00
|
|
|
ppat_loc_stack: location_stack;
|
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 *)
|
2019-10-09 06:15:37 -07:00
|
|
|
| Ppat_unpack of string option loc
|
|
|
|
(* (module P) Some "P"
|
|
|
|
(module _) None
|
|
|
|
|
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] *)
|
2016-05-05 10:50:56 -07:00
|
|
|
| Ppat_open of Longident.t loc * pattern
|
2016-08-03 03:18:59 -07:00
|
|
|
(* M.(P) *)
|
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;
|
2019-07-12 03:18:28 -07:00
|
|
|
pexp_loc_stack: location_stack;
|
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
|
|
|
*)
|
2017-07-27 23:40:09 -07:00
|
|
|
| Pexp_send of expression * label loc
|
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 *)
|
2017-07-27 23:40:09 -07:00
|
|
|
| Pexp_setinstvar of label loc * expression
|
2013-04-12 10:20:47 -07:00
|
|
|
(* x <- 2 *)
|
2017-07-27 23:40:09 -07:00
|
|
|
| Pexp_override of (label loc * expression) list
|
2013-04-12 10:20:47 -07:00
|
|
|
(* {< x1 = E1; ...; Xn = En >} *)
|
2019-10-09 06:15:37 -07:00
|
|
|
| Pexp_letmodule of string option loc * module_expr * expression
|
2013-04-12 10:20:47 -07:00
|
|
|
(* let module M = ME in E *)
|
2015-11-20 01:18:49 -08:00
|
|
|
| Pexp_letexception of extension_constructor * expression
|
|
|
|
(* let exception C 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 *)
|
2016-08-29 07:21:38 -07:00
|
|
|
| Pexp_newtype of string loc * 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) *)
|
2018-04-08 01:51:15 -07:00
|
|
|
| Pexp_open of open_declaration * expression
|
2016-08-03 03:18:59 -07:00
|
|
|
(* M.(E)
|
|
|
|
let open M in E
|
|
|
|
let! open M in E *)
|
2019-03-21 07:09:35 -07:00
|
|
|
| Pexp_letop of letop
|
2018-07-29 14:29:01 -07:00
|
|
|
(* let* P = E in E
|
|
|
|
let* P = E and* P = E in E *)
|
2013-02-28 08:51:59 -08:00
|
|
|
| Pexp_extension of extension
|
2013-04-19 00:40:57 -07:00
|
|
|
(* [%id] *)
|
2015-10-15 17:13:40 -07:00
|
|
|
| Pexp_unreachable
|
|
|
|
(* . *)
|
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;
|
2015-10-15 17:13:40 -07:00
|
|
|
pc_rhs: expression;
|
2019-03-21 07:09:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
and letop =
|
|
|
|
{
|
|
|
|
let_ : binding_op;
|
|
|
|
ands : binding_op list;
|
|
|
|
body : expression;
|
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2018-07-29 14:29:01 -07:00
|
|
|
and binding_op =
|
|
|
|
{
|
|
|
|
pbop_op : string loc;
|
|
|
|
pbop_pat : pattern;
|
|
|
|
pbop_exp : expression;
|
|
|
|
pbop_loc : Location.t;
|
|
|
|
}
|
|
|
|
|
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;
|
2020-06-15 04:51:50 -07:00
|
|
|
ptype_params: (core_type * (variance * injectivity)) 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
|
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;
|
2017-07-18 02:22:43 -07:00
|
|
|
pld_attributes: attributes; (* l : T [@id1] [@id2] *)
|
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;
|
2017-07-18 02:22:43 -07:00
|
|
|
pcd_attributes: attributes; (* C of ... [@id1] [@id2] *)
|
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;
|
2020-06-15 04:51:50 -07:00
|
|
|
ptyext_params: (core_type * (variance * injectivity)) list;
|
2014-05-04 16:08:45 -07:00
|
|
|
ptyext_constructors: extension_constructor list;
|
|
|
|
ptyext_private: private_flag;
|
2018-07-14 14:10:39 -07:00
|
|
|
ptyext_loc: Location.t;
|
2014-05-04 16:08:45 -07:00
|
|
|
ptyext_attributes: attributes; (* ... [@@id1] [@@id2] *)
|
|
|
|
}
|
|
|
|
(*
|
|
|
|
type t += ...
|
|
|
|
*)
|
|
|
|
|
|
|
|
and extension_constructor =
|
|
|
|
{
|
|
|
|
pext_name: string loc;
|
|
|
|
pext_kind : extension_constructor_kind;
|
|
|
|
pext_loc : Location.t;
|
2017-07-18 02:22:43 -07:00
|
|
|
pext_attributes: attributes; (* C of ... [@id1] [@id2] *)
|
2018-04-06 10:02:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
(* exception E *)
|
|
|
|
and type_exception =
|
|
|
|
{
|
|
|
|
ptyexn_constructor: extension_constructor;
|
2018-07-14 14:10:39 -07:00
|
|
|
ptyexn_loc: Location.t;
|
2018-04-06 10:02:46 -07:00
|
|
|
ptyexn_attributes: attributes; (* ... [@@id1] [@@id2] *)
|
|
|
|
}
|
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
|
|
|
|
2016-10-01 13:35:05 -07:00
|
|
|
(** {1 Class language} *)
|
2013-04-16 00:58:04 -07:00
|
|
|
|
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] *)
|
2018-04-08 01:51:15 -07:00
|
|
|
| Pcty_open of open_description * class_type
|
2017-07-19 23:17:30 -07:00
|
|
|
(* let open M in CT *)
|
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 *)
|
2017-07-27 23:40:09 -07:00
|
|
|
| Pctf_val of (label loc * mutable_flag * virtual_flag * core_type)
|
2013-04-16 02:11:54 -07:00
|
|
|
(* val x: T *)
|
2017-07-27 23:40:09 -07:00
|
|
|
| Pctf_method of (label loc * 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;
|
2020-06-15 04:51:50 -07:00
|
|
|
pci_params: (core_type * (variance * injectivity)) 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
|
2017-07-19 23:17:30 -07:00
|
|
|
(* [%id] *)
|
2018-04-08 01:51:15 -07:00
|
|
|
| Pcl_open of open_description * class_expr
|
2017-07-19 23:17:30 -07:00
|
|
|
(* let open M in CE *)
|
|
|
|
|
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 =
|
2016-08-29 07:21:38 -07:00
|
|
|
| Pcf_inherit of override_flag * class_expr * string loc option
|
2013-04-16 02:31:16 -07:00
|
|
|
(* inherit CE
|
|
|
|
inherit CE as x
|
|
|
|
inherit! CE
|
|
|
|
inherit! CE as x
|
|
|
|
*)
|
2017-07-27 23:40:09 -07:00
|
|
|
| Pcf_val of (label loc * mutable_flag * class_field_kind)
|
2013-04-16 02:31:16 -07:00
|
|
|
(* val x = E
|
|
|
|
val virtual x: T
|
|
|
|
*)
|
2017-07-27 23:40:09 -07:00
|
|
|
| Pcf_method of (label 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
|
|
|
|
|
2016-10-01 13:35:05 -07:00
|
|
|
(** {1 Module language} *)
|
2013-04-16 00:58:04 -07:00
|
|
|
|
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 *)
|
2019-10-09 06:15:37 -07:00
|
|
|
| Pmty_functor of functor_parameter * 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
|
|
|
|
2019-10-09 06:15:37 -07:00
|
|
|
and functor_parameter =
|
|
|
|
| Unit
|
|
|
|
(* () *)
|
|
|
|
| Named of string option loc * module_type
|
|
|
|
(* (X : MT) Some X, MT
|
|
|
|
(_ : MT) None, MT *)
|
|
|
|
|
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"
|
|
|
|
*)
|
2015-03-13 04:07:29 -07:00
|
|
|
| Psig_type of rec_flag * type_declaration list
|
2018-10-26 07:47:15 -07:00
|
|
|
(* type t1 = ... and ... and tn = ... *)
|
|
|
|
| Psig_typesubst of type_declaration list
|
|
|
|
(* type t1 := ... and ... and tn := ... *)
|
2014-05-04 16:08:45 -07:00
|
|
|
| Psig_typext of type_extension
|
|
|
|
(* type t1 += ... *)
|
2018-04-06 10:02:46 -07:00
|
|
|
| Psig_exception of type_exception
|
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
|
2018-10-26 07:47:15 -07:00
|
|
|
(* module X = M
|
|
|
|
module X : MT *)
|
|
|
|
| Psig_modsubst of module_substitution
|
|
|
|
(* module X := M *)
|
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 =
|
|
|
|
{
|
2019-10-09 06:15:37 -07:00
|
|
|
pmd_name: string option loc;
|
2013-03-04 09:39:07 -08:00
|
|
|
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
|
|
|
|
2018-10-26 07:47:15 -07:00
|
|
|
and module_substitution =
|
|
|
|
{
|
|
|
|
pms_name: string loc;
|
|
|
|
pms_manifest: Longident.t loc;
|
|
|
|
pms_attributes: attributes; (* ... [@@id1] [@@id2] *)
|
|
|
|
pms_loc: Location.t;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-04-08 01:51:15 -07:00
|
|
|
and 'a open_infos =
|
2014-04-15 04:26:00 -07:00
|
|
|
{
|
2018-04-08 01:51:15 -07:00
|
|
|
popen_expr: 'a;
|
2014-04-15 04:26:00 -07:00
|
|
|
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
|
|
|
*)
|
|
|
|
|
2018-04-08 01:51:15 -07:00
|
|
|
and open_description = Longident.t loc open_infos
|
|
|
|
(* open M.N
|
|
|
|
open M(N).O *)
|
|
|
|
|
|
|
|
and open_declaration = module_expr open_infos
|
|
|
|
(* open M.N
|
|
|
|
open M(N).O
|
|
|
|
open struct ... end *)
|
|
|
|
|
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 *)
|
2016-08-29 21:16:28 -07:00
|
|
|
| Pwith_typesubst of Longident.t loc * type_declaration
|
|
|
|
(* with type X.t := ..., same format as [Pwith_type] *)
|
2016-09-04 11:06:50 -07:00
|
|
|
| Pwith_modsubst of Longident.t loc * Longident.t loc
|
|
|
|
(* with module X.Y := 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 *)
|
2019-10-09 06:15:37 -07:00
|
|
|
| Pmod_functor of functor_parameter * 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" *)
|
2015-03-13 04:07:29 -07:00
|
|
|
| Pstr_type of rec_flag * 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 += ... *)
|
2018-04-06 10:02:46 -07:00
|
|
|
| Pstr_exception of type_exception
|
2014-05-04 16:08:45 -07:00
|
|
|
(* 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 *)
|
2018-04-08 01:51:15 -07:00
|
|
|
| Pstr_open of open_declaration
|
2014-04-15 04:26:00 -07:00
|
|
|
(* 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 =
|
|
|
|
{
|
2019-10-09 06:15:37 -07:00
|
|
|
pmb_name: string option loc;
|
2013-03-05 08:50:05 -08:00
|
|
|
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
|
|
|
|
2016-10-01 13:35:05 -07:00
|
|
|
(** {1 Toplevel} *)
|
2013-04-16 00:58:04 -07:00
|
|
|
|
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
|
2018-07-24 01:25:21 -07:00
|
|
|
| Ptop_dir of toplevel_directive
|
2014-04-11 23:56:51 -07:00
|
|
|
(* #use, #load ... *)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2018-07-24 01:25:21 -07:00
|
|
|
and toplevel_directive =
|
|
|
|
{
|
|
|
|
pdir_name : string loc;
|
|
|
|
pdir_arg : directive_argument option;
|
|
|
|
pdir_loc : Location.t;
|
|
|
|
}
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
and directive_argument =
|
2018-07-24 01:25:21 -07:00
|
|
|
{
|
|
|
|
pdira_desc : directive_argument_desc;
|
|
|
|
pdira_loc : Location.t;
|
|
|
|
}
|
|
|
|
|
|
|
|
and directive_argument_desc =
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pdir_string of string
|
2015-04-18 20:07:32 -07:00
|
|
|
| Pdir_int of string * char option
|
1995-05-04 03:15:53 -07:00
|
|
|
| Pdir_ident of Longident.t
|
1999-12-03 02:26:08 -08:00
|
|
|
| Pdir_bool of bool
|