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
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* The parser definition */
|
|
|
|
|
|
|
|
%{
|
|
|
|
open Location
|
|
|
|
open Asttypes
|
|
|
|
open Longident
|
|
|
|
open Parsetree
|
2013-03-08 06:59:45 -08:00
|
|
|
open Ast_helper
|
2015-06-28 06:11:50 -07:00
|
|
|
open Docstrings
|
2013-03-08 06:59:45 -08:00
|
|
|
|
|
|
|
let mktyp d = Typ.mk ~loc:(symbol_rloc()) d
|
|
|
|
let mkpat d = Pat.mk ~loc:(symbol_rloc()) d
|
|
|
|
let mkexp d = Exp.mk ~loc:(symbol_rloc()) d
|
2016-02-02 08:41:43 -08:00
|
|
|
let mkmty ?attrs d = Mty.mk ~loc:(symbol_rloc()) ?attrs d
|
2013-03-08 06:59:45 -08:00
|
|
|
let mksig d = Sig.mk ~loc:(symbol_rloc()) d
|
2016-02-02 07:38:07 -08:00
|
|
|
let mkmod ?attrs d = Mod.mk ~loc:(symbol_rloc()) ?attrs d
|
2013-03-08 06:59:45 -08:00
|
|
|
let mkstr d = Str.mk ~loc:(symbol_rloc()) d
|
2016-02-02 08:12:11 -08:00
|
|
|
let mkclass ?attrs d = Cl.mk ~loc:(symbol_rloc()) ?attrs d
|
2016-02-23 08:13:16 -08:00
|
|
|
let mkcty ?attrs d = Cty.mk ~loc:(symbol_rloc()) ?attrs d
|
2015-06-28 06:11:50 -07:00
|
|
|
let mkctf ?attrs ?docs d =
|
|
|
|
Ctf.mk ~loc:(symbol_rloc()) ?attrs ?docs d
|
|
|
|
let mkcf ?attrs ?docs d =
|
|
|
|
Cf.mk ~loc:(symbol_rloc()) ?attrs ?docs d
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
let mkrhs rhs pos = mkloc rhs (rhs_loc pos)
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2003-04-06 05:45:03 -07:00
|
|
|
let reloc_pat x = { x with ppat_loc = symbol_rloc () };;
|
|
|
|
let reloc_exp x = { x with pexp_loc = symbol_rloc () };;
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
let mkoperator name pos =
|
2012-05-30 07:52:37 -07:00
|
|
|
let loc = rhs_loc pos in
|
2013-03-08 06:59:45 -08:00
|
|
|
Exp.mk ~loc (Pexp_ident(mkloc (Lident name) loc))
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2011-12-14 00:59:07 -08:00
|
|
|
let mkpatvar name pos =
|
2013-03-08 06:59:45 -08:00
|
|
|
Pat.mk ~loc:(rhs_loc pos) (Ppat_var (mkrhs name pos))
|
2011-12-14 00:59:07 -08:00
|
|
|
|
2003-04-02 08:03:33 -08:00
|
|
|
(*
|
|
|
|
Ghost expressions and patterns:
|
2012-04-13 05:44:29 -07:00
|
|
|
expressions and patterns that do not appear explicitly in the
|
2003-04-02 08:03:33 -08:00
|
|
|
source file they have the loc_ghost flag set to true.
|
|
|
|
Then the profiler will not try to instrument them and the
|
2012-09-10 03:32:49 -07:00
|
|
|
-annot option will not try to display their type.
|
1999-09-08 10:42:36 -07:00
|
|
|
|
2003-04-02 08:03:33 -08:00
|
|
|
Every grammar rule that generates an element with a location must
|
|
|
|
make at most one non-ghost element, the topmost one.
|
|
|
|
|
|
|
|
How to tell whether your location must be ghost:
|
|
|
|
A location corresponds to a range of characters in the source file.
|
|
|
|
If the location contains a piece of code that is syntactically
|
|
|
|
valid (according to the documentation), and corresponds to the
|
|
|
|
AST node, then the location must be real; in all other cases,
|
|
|
|
it must be ghost.
|
1998-05-23 07:10:59 -07:00
|
|
|
*)
|
2013-03-08 06:59:45 -08:00
|
|
|
let ghexp d = Exp.mk ~loc:(symbol_gloc ()) d
|
|
|
|
let ghpat d = Pat.mk ~loc:(symbol_gloc ()) d
|
|
|
|
let ghtyp d = Typ.mk ~loc:(symbol_gloc ()) d
|
|
|
|
let ghloc d = { txt = d; loc = symbol_gloc () }
|
2014-04-15 04:40:13 -07:00
|
|
|
let ghstr d = Str.mk ~loc:(symbol_gloc()) d
|
2015-12-02 09:36:02 -08:00
|
|
|
let ghsig d = Sig.mk ~loc:(symbol_gloc()) d
|
1998-05-23 07:10:59 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
let mkinfix arg1 name arg2 =
|
2014-12-22 00:45:55 -08:00
|
|
|
mkexp(Pexp_apply(mkoperator name 2, [Nolabel, arg1; Nolabel, arg2]))
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2015-04-18 20:07:32 -07:00
|
|
|
let neg_string f =
|
1999-10-19 09:43:49 -07:00
|
|
|
if String.length f > 0 && f.[0] = '-'
|
|
|
|
then String.sub f 1 (String.length f - 1)
|
|
|
|
else "-" ^ f
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
let mkuminus name arg =
|
2003-03-12 08:33:38 -08:00
|
|
|
match name, arg.pexp_desc with
|
2016-01-08 06:48:47 -08:00
|
|
|
| "-", Pexp_constant(Pconst_integer (n,m)) ->
|
|
|
|
mkexp(Pexp_constant(Pconst_integer(neg_string n,m)))
|
|
|
|
| ("-" | "-."), Pexp_constant(Pconst_float (f, m)) ->
|
|
|
|
mkexp(Pexp_constant(Pconst_float(neg_string f, m)))
|
1995-05-04 03:15:53 -07:00
|
|
|
| _ ->
|
2014-12-22 00:45:55 -08:00
|
|
|
mkexp(Pexp_apply(mkoperator ("~" ^ name) 1, [Nolabel, arg]))
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2009-12-07 08:40:39 -08:00
|
|
|
let mkuplus name arg =
|
2010-06-04 09:44:08 -07:00
|
|
|
let desc = arg.pexp_desc in
|
|
|
|
match name, desc with
|
2016-01-08 06:48:47 -08:00
|
|
|
| "+", Pexp_constant(Pconst_integer _)
|
|
|
|
| ("+" | "+."), Pexp_constant(Pconst_float _) -> mkexp desc
|
2009-12-07 08:40:39 -08:00
|
|
|
| _ ->
|
2014-12-22 00:45:55 -08:00
|
|
|
mkexp(Pexp_apply(mkoperator ("~" ^ name) 1, [Nolabel, arg]))
|
2009-12-07 08:40:39 -08:00
|
|
|
|
2012-12-08 12:56:07 -08:00
|
|
|
let mkexp_cons consloc args loc =
|
2013-04-17 02:46:52 -07:00
|
|
|
Exp.mk ~loc (Pexp_construct(mkloc (Lident "::") consloc, Some args))
|
2012-05-30 07:52:37 -07:00
|
|
|
|
2012-12-08 12:56:07 -08:00
|
|
|
let mkpat_cons consloc args loc =
|
2013-04-17 02:46:52 -07:00
|
|
|
Pat.mk ~loc (Ppat_construct(mkloc (Lident "::") consloc, Some args))
|
2012-05-30 07:52:37 -07:00
|
|
|
|
2012-12-08 12:56:07 -08:00
|
|
|
let rec mktailexp nilloc = function
|
1995-05-04 03:15:53 -07:00
|
|
|
[] ->
|
2012-12-08 12:56:07 -08:00
|
|
|
let loc = { nilloc with loc_ghost = true } in
|
|
|
|
let nil = { txt = Lident "[]"; loc = loc } in
|
2013-04-17 02:46:52 -07:00
|
|
|
Exp.mk ~loc (Pexp_construct (nil, None))
|
1995-05-04 03:15:53 -07:00
|
|
|
| e1 :: el ->
|
2012-12-08 12:56:07 -08:00
|
|
|
let exp_el = mktailexp nilloc el in
|
2013-03-08 06:59:45 -08:00
|
|
|
let loc = {loc_start = e1.pexp_loc.loc_start;
|
1999-09-08 10:42:36 -07:00
|
|
|
loc_end = exp_el.pexp_loc.loc_end;
|
2003-04-01 17:17:19 -08:00
|
|
|
loc_ghost = true}
|
1998-05-23 07:10:59 -07:00
|
|
|
in
|
2013-03-08 06:59:45 -08:00
|
|
|
let arg = Exp.mk ~loc (Pexp_tuple [e1; exp_el]) in
|
|
|
|
mkexp_cons {loc with loc_ghost = true} arg loc
|
1998-05-23 07:10:59 -07:00
|
|
|
|
2012-12-08 12:56:07 -08:00
|
|
|
let rec mktailpat nilloc = function
|
1995-05-04 03:15:53 -07:00
|
|
|
[] ->
|
2012-12-08 12:56:07 -08:00
|
|
|
let loc = { nilloc with loc_ghost = true } in
|
|
|
|
let nil = { txt = Lident "[]"; loc = loc } in
|
2013-04-17 02:46:52 -07:00
|
|
|
Pat.mk ~loc (Ppat_construct (nil, None))
|
1995-05-04 03:15:53 -07:00
|
|
|
| p1 :: pl ->
|
2012-12-08 12:56:07 -08:00
|
|
|
let pat_pl = mktailpat nilloc pl in
|
2013-03-08 06:59:45 -08:00
|
|
|
let loc = {loc_start = p1.ppat_loc.loc_start;
|
1999-09-08 10:42:36 -07:00
|
|
|
loc_end = pat_pl.ppat_loc.loc_end;
|
2003-04-06 05:45:03 -07:00
|
|
|
loc_ghost = true}
|
1998-05-23 07:10:59 -07:00
|
|
|
in
|
2013-03-08 06:59:45 -08:00
|
|
|
let arg = Pat.mk ~loc (Ppat_tuple [p1; pat_pl]) in
|
|
|
|
mkpat_cons {loc with loc_ghost = true} arg loc
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2013-04-11 07:07:32 -07:00
|
|
|
let mkstrexp e attrs =
|
|
|
|
{ pstr_desc = Pstr_eval (e, attrs); pstr_loc = e.pexp_loc }
|
1995-10-05 08:18:49 -07:00
|
|
|
|
2013-04-17 05:23:44 -07:00
|
|
|
let mkexp_constraint e (t1, t2) =
|
|
|
|
match t1, t2 with
|
|
|
|
| Some t, None -> ghexp(Pexp_constraint(e, t))
|
|
|
|
| _, Some t -> ghexp(Pexp_coerce(e, t1, t))
|
|
|
|
| None, None -> assert false
|
|
|
|
|
2015-11-04 10:35:34 -08:00
|
|
|
let mkexp_opt_constraint e = function
|
|
|
|
| None -> e
|
|
|
|
| Some constraint_ -> mkexp_constraint e constraint_
|
|
|
|
|
|
|
|
let mkpat_opt_constraint p = function
|
|
|
|
| None -> p
|
|
|
|
| Some typ -> mkpat (Ppat_constraint(p, typ))
|
|
|
|
|
2015-11-29 09:59:33 -08:00
|
|
|
let array_function str name =
|
|
|
|
ghloc (Ldot(Lident str, (if !Clflags.fast then "unsafe_" ^ name else name)))
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1997-11-12 04:32:53 -08:00
|
|
|
let syntax_error () =
|
|
|
|
raise Syntaxerr.Escape_error
|
|
|
|
|
1997-08-22 01:55:41 -07:00
|
|
|
let unclosed opening_name opening_num closing_name closing_num =
|
|
|
|
raise(Syntaxerr.Error(Syntaxerr.Unclosed(rhs_loc opening_num, opening_name,
|
|
|
|
rhs_loc closing_num, closing_name)))
|
|
|
|
|
2012-10-16 07:04:33 -07:00
|
|
|
let expecting pos nonterm =
|
|
|
|
raise Syntaxerr.(Error(Expecting(rhs_loc pos, nonterm)))
|
|
|
|
|
2013-04-11 06:52:06 -07:00
|
|
|
let not_expecting pos nonterm =
|
|
|
|
raise Syntaxerr.(Error(Not_expecting(rhs_loc pos, nonterm)))
|
|
|
|
|
2015-11-29 09:53:13 -08:00
|
|
|
let bigarray_function str name =
|
|
|
|
ghloc (Ldot(Ldot(Lident "Bigarray", str), name))
|
2000-02-24 09:42:32 -08:00
|
|
|
|
|
|
|
let bigarray_untuplify = function
|
2011-10-28 14:21:55 -07:00
|
|
|
{ pexp_desc = Pexp_tuple explist; pexp_loc = _ } -> explist
|
2000-02-24 09:42:32 -08:00
|
|
|
| exp -> [exp]
|
|
|
|
|
|
|
|
let bigarray_get arr arg =
|
2015-11-29 09:53:13 -08:00
|
|
|
let get = if !Clflags.fast then "unsafe_get" else "get" in
|
2000-02-24 09:42:32 -08:00
|
|
|
match bigarray_untuplify arg with
|
|
|
|
[c1] ->
|
2015-11-29 09:53:13 -08:00
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array1" get)),
|
2014-12-22 00:45:55 -08:00
|
|
|
[Nolabel, arr; Nolabel, c1]))
|
2000-02-24 09:42:32 -08:00
|
|
|
| [c1;c2] ->
|
2015-11-29 09:53:13 -08:00
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array2" get)),
|
2014-12-22 00:45:55 -08:00
|
|
|
[Nolabel, arr; Nolabel, c1; Nolabel, c2]))
|
2000-02-24 09:42:32 -08:00
|
|
|
| [c1;c2;c3] ->
|
2015-11-29 09:53:13 -08:00
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array3" get)),
|
2014-12-22 00:45:55 -08:00
|
|
|
[Nolabel, arr; Nolabel, c1; Nolabel, c2; Nolabel, c3]))
|
2000-02-24 09:42:32 -08:00
|
|
|
| coords ->
|
2015-11-29 09:53:13 -08:00
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Genarray" "get")),
|
2014-12-22 00:45:55 -08:00
|
|
|
[Nolabel, arr; Nolabel, ghexp(Pexp_array coords)]))
|
2000-02-24 09:42:32 -08:00
|
|
|
|
|
|
|
let bigarray_set arr arg newval =
|
2015-11-29 09:53:13 -08:00
|
|
|
let set = if !Clflags.fast then "unsafe_set" else "set" in
|
2000-02-24 09:42:32 -08:00
|
|
|
match bigarray_untuplify arg with
|
|
|
|
[c1] ->
|
2015-11-29 09:53:13 -08:00
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array1" set)),
|
2014-12-22 00:45:55 -08:00
|
|
|
[Nolabel, arr; Nolabel, c1; Nolabel, newval]))
|
2000-02-24 09:42:32 -08:00
|
|
|
| [c1;c2] ->
|
2015-11-29 09:53:13 -08:00
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array2" set)),
|
|
|
|
[Nolabel, arr; Nolabel, c1;
|
|
|
|
Nolabel, c2; Nolabel, newval]))
|
2000-02-24 09:42:32 -08:00
|
|
|
| [c1;c2;c3] ->
|
2015-11-29 09:53:13 -08:00
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array3" set)),
|
|
|
|
[Nolabel, arr; Nolabel, c1;
|
|
|
|
Nolabel, c2; Nolabel, c3; Nolabel, newval]))
|
2000-02-24 09:42:32 -08:00
|
|
|
| coords ->
|
2015-11-29 09:53:13 -08:00
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Genarray" "set")),
|
2014-12-22 00:45:55 -08:00
|
|
|
[Nolabel, arr;
|
|
|
|
Nolabel, ghexp(Pexp_array coords);
|
|
|
|
Nolabel, newval]))
|
2009-07-15 07:06:37 -07:00
|
|
|
|
|
|
|
let lapply p1 p2 =
|
|
|
|
if !Clflags.applicative_functors
|
|
|
|
then Lapply(p1, p2)
|
|
|
|
else raise (Syntaxerr.Error(Syntaxerr.Applicative_path (symbol_rloc())))
|
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
let exp_of_label lbl pos =
|
|
|
|
mkexp (Pexp_ident(mkrhs (Lident(Longident.last lbl)) pos))
|
2009-08-27 01:19:08 -07:00
|
|
|
|
2012-05-30 07:52:37 -07:00
|
|
|
let pat_of_label lbl pos =
|
|
|
|
mkpat (Ppat_var (mkrhs (Longident.last lbl) pos))
|
2009-08-27 01:19:08 -07:00
|
|
|
|
2012-03-22 19:20:24 -07:00
|
|
|
let check_variable vl loc v =
|
|
|
|
if List.mem v vl then
|
|
|
|
raise Syntaxerr.(Error(Variable_in_scope(loc,v)))
|
2010-11-24 05:37:24 -08:00
|
|
|
|
2011-11-29 07:49:25 -08:00
|
|
|
let varify_constructors var_names t =
|
|
|
|
let rec loop t =
|
|
|
|
let desc =
|
2010-10-17 21:54:24 -07:00
|
|
|
match t.ptyp_desc with
|
|
|
|
| Ptyp_any -> Ptyp_any
|
2012-03-22 19:20:24 -07:00
|
|
|
| Ptyp_var x ->
|
|
|
|
check_variable var_names t.ptyp_loc x;
|
|
|
|
Ptyp_var x
|
2010-10-17 21:54:24 -07:00
|
|
|
| Ptyp_arrow (label,core_type,core_type') ->
|
2011-11-29 07:49:25 -08:00
|
|
|
Ptyp_arrow(label, loop core_type, loop core_type')
|
2010-10-17 21:54:24 -07:00
|
|
|
| Ptyp_tuple lst -> Ptyp_tuple (List.map loop lst)
|
2012-05-30 07:52:37 -07:00
|
|
|
| Ptyp_constr( { txt = Lident s }, []) when List.mem s var_names ->
|
2012-03-22 19:20:24 -07:00
|
|
|
Ptyp_var s
|
2010-10-17 21:54:24 -07:00
|
|
|
| Ptyp_constr(longident, lst) ->
|
2011-11-29 07:49:25 -08:00
|
|
|
Ptyp_constr(longident, List.map loop lst)
|
2013-04-09 06:29:00 -07:00
|
|
|
| Ptyp_object (lst, o) ->
|
2014-05-05 04:21:45 -07:00
|
|
|
Ptyp_object
|
|
|
|
(List.map (fun (s, attrs, t) -> (s, attrs, loop t)) lst, o)
|
2013-04-16 05:17:17 -07:00
|
|
|
| Ptyp_class (longident, lst) ->
|
|
|
|
Ptyp_class (longident, List.map loop lst)
|
2010-10-17 21:54:24 -07:00
|
|
|
| Ptyp_alias(core_type, string) ->
|
2012-03-22 19:20:24 -07:00
|
|
|
check_variable var_names t.ptyp_loc string;
|
2011-11-29 07:49:25 -08:00
|
|
|
Ptyp_alias(loop core_type, string)
|
|
|
|
| Ptyp_variant(row_field_list, flag, lbl_lst_option) ->
|
2012-03-22 19:20:24 -07:00
|
|
|
Ptyp_variant(List.map loop_row_field row_field_list,
|
|
|
|
flag, lbl_lst_option)
|
2010-10-17 21:54:24 -07:00
|
|
|
| Ptyp_poly(string_lst, core_type) ->
|
2012-03-22 19:20:24 -07:00
|
|
|
List.iter (check_variable var_names t.ptyp_loc) string_lst;
|
2011-11-29 07:49:25 -08:00
|
|
|
Ptyp_poly(string_lst, loop core_type)
|
2010-10-17 21:54:24 -07:00
|
|
|
| Ptyp_package(longident,lst) ->
|
2011-11-29 07:49:25 -08:00
|
|
|
Ptyp_package(longident,List.map (fun (n,typ) -> (n,loop typ) ) lst)
|
2013-02-28 08:51:59 -08:00
|
|
|
| Ptyp_extension (s, arg) ->
|
|
|
|
Ptyp_extension (s, arg)
|
2010-10-17 21:54:24 -07:00
|
|
|
in
|
|
|
|
{t with ptyp_desc = desc}
|
2011-11-29 07:49:25 -08:00
|
|
|
and loop_row_field =
|
2010-10-17 21:54:24 -07:00
|
|
|
function
|
2014-04-30 01:19:55 -07:00
|
|
|
| Rtag(label,attrs,flag,lst) ->
|
|
|
|
Rtag(label,attrs,flag,List.map loop lst)
|
2010-10-17 21:54:24 -07:00
|
|
|
| Rinherit t ->
|
2011-11-29 07:49:25 -08:00
|
|
|
Rinherit (loop t)
|
2010-10-17 21:54:24 -07:00
|
|
|
in
|
2012-03-22 19:20:24 -07:00
|
|
|
loop t
|
2010-10-17 21:54:24 -07:00
|
|
|
|
2015-07-26 12:01:42 -07:00
|
|
|
let mk_newtypes newtypes exp =
|
|
|
|
List.fold_right (fun newtype exp -> mkexp (Pexp_newtype (newtype, exp)))
|
|
|
|
newtypes exp
|
|
|
|
|
2011-11-24 01:02:48 -08:00
|
|
|
let wrap_type_annotation newtypes core_type body =
|
2013-04-17 05:23:44 -07:00
|
|
|
let exp = mkexp(Pexp_constraint(body,core_type)) in
|
2015-07-26 12:01:42 -07:00
|
|
|
let exp = mk_newtypes newtypes exp in
|
2012-03-22 19:20:24 -07:00
|
|
|
(exp, ghtyp(Ptyp_poly(newtypes,varify_constructors newtypes core_type)))
|
2010-10-17 21:54:24 -07:00
|
|
|
|
2013-03-08 01:17:30 -08:00
|
|
|
let wrap_exp_attrs body (ext, attrs) =
|
2013-03-06 06:53:39 -08:00
|
|
|
(* todo: keep exact location for the entire attribute *)
|
2013-03-22 04:25:52 -07:00
|
|
|
let body = {body with pexp_attributes = attrs @ body.pexp_attributes} in
|
|
|
|
match ext with
|
2013-03-08 01:17:30 -08:00
|
|
|
| None -> body
|
2013-07-22 07:58:15 -07:00
|
|
|
| Some id -> ghexp(Pexp_extension (id, PStr [mkstrexp body []]))
|
2013-03-06 06:53:39 -08:00
|
|
|
|
|
|
|
let mkexp_attrs d attrs =
|
|
|
|
wrap_exp_attrs (mkexp d) attrs
|
|
|
|
|
2016-02-02 07:38:07 -08:00
|
|
|
let wrap_typ_attrs typ (ext, attrs) =
|
|
|
|
(* todo: keep exact location for the entire attribute *)
|
|
|
|
let typ = {typ with ptyp_attributes = attrs @ typ.ptyp_attributes} in
|
|
|
|
match ext with
|
|
|
|
| None -> typ
|
|
|
|
| Some id -> ghtyp(Ptyp_extension (id, PTyp typ))
|
|
|
|
|
|
|
|
let mktyp_attrs d attrs =
|
|
|
|
wrap_typ_attrs (mktyp d) attrs
|
|
|
|
|
2016-02-02 07:44:55 -08:00
|
|
|
let wrap_pat_attrs pat (ext, attrs) =
|
|
|
|
(* todo: keep exact location for the entire attribute *)
|
|
|
|
let pat = {pat with ppat_attributes = attrs @ pat.ppat_attributes} in
|
|
|
|
match ext with
|
|
|
|
| None -> pat
|
|
|
|
| Some id -> ghpat(Ppat_extension (id, PPat (pat, None)))
|
|
|
|
|
|
|
|
let mkpat_attrs d attrs =
|
|
|
|
wrap_pat_attrs (mkpat d) attrs
|
|
|
|
|
2016-02-02 08:12:11 -08:00
|
|
|
let wrap_class_attrs body attrs =
|
|
|
|
{body with pcl_attributes = attrs @ body.pcl_attributes}
|
2016-02-02 08:41:43 -08:00
|
|
|
let wrap_mod_attrs body attrs =
|
|
|
|
{body with pmod_attributes = attrs @ body.pmod_attributes}
|
|
|
|
let wrap_mty_attrs body attrs =
|
|
|
|
{body with pmty_attributes = attrs @ body.pmty_attributes}
|
2016-02-02 08:12:11 -08:00
|
|
|
|
2015-12-02 09:36:02 -08:00
|
|
|
let wrap_str_ext body ext =
|
|
|
|
match ext with
|
|
|
|
| None -> body
|
|
|
|
| Some id -> ghstr(Pstr_extension ((id, PStr [body]), []))
|
|
|
|
|
|
|
|
let mkstr_ext d ext =
|
|
|
|
wrap_str_ext (mkstr d) ext
|
|
|
|
|
|
|
|
let wrap_sig_ext body ext =
|
|
|
|
match ext with
|
|
|
|
| None -> body
|
|
|
|
| Some id -> ghsig(Psig_extension ((id, PSig [body]), []))
|
|
|
|
|
|
|
|
let mksig_ext d ext =
|
|
|
|
wrap_sig_ext (mksig d) ext
|
|
|
|
|
2015-06-28 06:11:50 -07:00
|
|
|
let text_str pos = Str.text (rhs_text pos)
|
|
|
|
let text_sig pos = Sig.text (rhs_text pos)
|
|
|
|
let text_cstr pos = Cf.text (rhs_text pos)
|
|
|
|
let text_csig pos = Ctf.text (rhs_text pos)
|
|
|
|
let text_def pos = [Ptop_def (Str.text (rhs_text pos))]
|
2014-05-04 13:42:34 -07:00
|
|
|
|
2015-06-28 06:11:50 -07:00
|
|
|
let extra_text text pos items =
|
|
|
|
let pre_extras = rhs_pre_extra_text pos in
|
|
|
|
let post_extras = rhs_post_extra_text pos in
|
|
|
|
text pre_extras @ items @ text post_extras
|
2014-05-04 13:42:34 -07:00
|
|
|
|
2015-06-28 06:11:50 -07:00
|
|
|
let extra_str pos items = extra_text Str.text pos items
|
|
|
|
let extra_sig pos items = extra_text Sig.text pos items
|
|
|
|
let extra_cstr pos items = extra_text Cf.text pos items
|
|
|
|
let extra_csig pos items = extra_text Ctf.text pos items
|
|
|
|
let extra_def pos items =
|
|
|
|
extra_text (fun txt -> [Ptop_def (Str.text txt)]) pos items
|
2015-05-04 11:44:11 -07:00
|
|
|
|
2016-03-03 05:18:33 -08:00
|
|
|
let extra_rhs_core_type ct ~pos =
|
|
|
|
let docs = rhs_info pos in
|
|
|
|
{ ct with ptyp_attributes = add_info_attrs docs ct.ptyp_attributes }
|
|
|
|
|
2015-05-04 11:44:11 -07:00
|
|
|
type let_binding =
|
|
|
|
{ lb_pattern: pattern;
|
|
|
|
lb_expression: expression;
|
|
|
|
lb_attributes: attributes;
|
2015-06-28 06:11:50 -07:00
|
|
|
lb_docs: docs Lazy.t;
|
|
|
|
lb_text: text Lazy.t;
|
2015-05-04 11:44:11 -07:00
|
|
|
lb_loc: Location.t; }
|
|
|
|
|
|
|
|
type let_bindings =
|
|
|
|
{ lbs_bindings: let_binding list;
|
|
|
|
lbs_rec: rec_flag;
|
|
|
|
lbs_extension: string Asttypes.loc option;
|
|
|
|
lbs_loc: Location.t }
|
|
|
|
|
2016-04-28 07:00:18 -07:00
|
|
|
let mklb first (p, e) attrs =
|
2015-05-04 11:44:11 -07:00
|
|
|
{ lb_pattern = p;
|
|
|
|
lb_expression = e;
|
|
|
|
lb_attributes = attrs;
|
2015-06-28 06:11:50 -07:00
|
|
|
lb_docs = symbol_docs_lazy ();
|
2016-04-28 07:00:18 -07:00
|
|
|
lb_text = if first then empty_text_lazy
|
|
|
|
else symbol_text_lazy ();
|
2015-05-04 11:44:11 -07:00
|
|
|
lb_loc = symbol_rloc (); }
|
|
|
|
|
2016-02-02 05:52:03 -08:00
|
|
|
let mklbs ext rf lb =
|
2015-05-04 11:44:11 -07:00
|
|
|
{ lbs_bindings = [lb];
|
|
|
|
lbs_rec = rf;
|
|
|
|
lbs_extension = ext ;
|
|
|
|
lbs_loc = symbol_rloc (); }
|
|
|
|
|
|
|
|
let addlb lbs lb =
|
|
|
|
{ lbs with lbs_bindings = lb :: lbs.lbs_bindings }
|
|
|
|
|
|
|
|
let val_of_let_bindings lbs =
|
2015-12-02 14:39:19 -08:00
|
|
|
let bindings =
|
|
|
|
List.map
|
|
|
|
(fun lb ->
|
|
|
|
Vb.mk ~loc:lb.lb_loc ~attrs:lb.lb_attributes
|
|
|
|
~docs:(Lazy.force lb.lb_docs)
|
|
|
|
~text:(Lazy.force lb.lb_text)
|
|
|
|
lb.lb_pattern lb.lb_expression)
|
|
|
|
lbs.lbs_bindings
|
2015-07-13 03:47:54 -07:00
|
|
|
in
|
2015-12-02 14:39:19 -08:00
|
|
|
let str = mkstr(Pstr_value(lbs.lbs_rec, List.rev bindings)) in
|
2015-07-13 03:47:54 -07:00
|
|
|
match lbs.lbs_extension with
|
|
|
|
| None -> str
|
|
|
|
| Some id -> ghstr (Pstr_extension((id, PStr [str]), []))
|
2015-05-04 11:44:11 -07:00
|
|
|
|
|
|
|
let expr_of_let_bindings lbs body =
|
|
|
|
let bindings =
|
|
|
|
List.map
|
|
|
|
(fun lb ->
|
2016-02-02 05:52:03 -08:00
|
|
|
Vb.mk ~loc:lb.lb_loc ~attrs:lb.lb_attributes
|
|
|
|
lb.lb_pattern lb.lb_expression)
|
2015-05-04 11:44:11 -07:00
|
|
|
lbs.lbs_bindings
|
|
|
|
in
|
|
|
|
mkexp_attrs (Pexp_let(lbs.lbs_rec, List.rev bindings, body))
|
2016-02-02 05:52:03 -08:00
|
|
|
(lbs.lbs_extension, [])
|
2015-05-04 11:44:11 -07:00
|
|
|
|
|
|
|
let class_of_let_bindings lbs body =
|
|
|
|
let bindings =
|
|
|
|
List.map
|
|
|
|
(fun lb ->
|
2016-02-02 05:52:03 -08:00
|
|
|
Vb.mk ~loc:lb.lb_loc ~attrs:lb.lb_attributes
|
|
|
|
lb.lb_pattern lb.lb_expression)
|
2015-05-04 11:44:11 -07:00
|
|
|
lbs.lbs_bindings
|
|
|
|
in
|
|
|
|
if lbs.lbs_extension <> None then
|
|
|
|
raise Syntaxerr.(Error(Not_expecting(lbs.lbs_loc, "extension")));
|
|
|
|
mkclass(Pcl_let (lbs.lbs_rec, List.rev bindings, body))
|
|
|
|
|
2016-01-05 04:10:25 -08:00
|
|
|
|
|
|
|
(* Alternatively, we could keep the generic module type in the Parsetree
|
|
|
|
and extract the package type during type-checking. In that case,
|
|
|
|
the assertions below should be turned into explicit checks. *)
|
|
|
|
let package_type_of_module_type pmty =
|
|
|
|
let err loc s =
|
|
|
|
raise (Syntaxerr.Error (Syntaxerr.Invalid_package_type (loc, s)))
|
|
|
|
in
|
|
|
|
let map_cstr = function
|
|
|
|
| Pwith_type (lid, ptyp) ->
|
|
|
|
let loc = ptyp.ptype_loc in
|
|
|
|
if ptyp.ptype_params <> [] then
|
|
|
|
err loc "parametrized types are not supported";
|
|
|
|
if ptyp.ptype_cstrs <> [] then
|
|
|
|
err loc "constrained types are not supported";
|
|
|
|
if ptyp.ptype_private <> Public then
|
|
|
|
err loc "private types are not supported";
|
|
|
|
|
|
|
|
(* restrictions below are checked by the 'with_constraint' rule *)
|
|
|
|
assert (ptyp.ptype_kind = Ptype_abstract);
|
|
|
|
assert (ptyp.ptype_attributes = []);
|
|
|
|
let ty =
|
|
|
|
match ptyp.ptype_manifest with
|
|
|
|
| Some ty -> ty
|
|
|
|
| None -> assert false
|
|
|
|
in
|
|
|
|
(lid, ty)
|
|
|
|
| _ ->
|
|
|
|
err pmty.pmty_loc "only 'with type t =' constraints are supported"
|
|
|
|
in
|
|
|
|
match pmty with
|
|
|
|
| {pmty_desc = Pmty_ident lid} -> (lid, [])
|
|
|
|
| {pmty_desc = Pmty_with({pmty_desc = Pmty_ident lid}, cstrs)} ->
|
|
|
|
(lid, List.map map_cstr cstrs)
|
|
|
|
| _ ->
|
|
|
|
err pmty.pmty_loc
|
|
|
|
"only module type identifier and 'with type' constraints are supported"
|
|
|
|
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
%}
|
|
|
|
|
|
|
|
/* Tokens */
|
|
|
|
|
1995-12-15 02:20:24 -08:00
|
|
|
%token AMPERAMPER
|
1995-05-04 03:15:53 -07:00
|
|
|
%token AMPERSAND
|
|
|
|
%token AND
|
|
|
|
%token AS
|
1997-05-13 11:28:25 -07:00
|
|
|
%token ASSERT
|
1999-11-30 08:07:38 -08:00
|
|
|
%token BACKQUOTE
|
2010-04-07 20:58:41 -07:00
|
|
|
%token BANG
|
1995-05-04 03:15:53 -07:00
|
|
|
%token BAR
|
1995-12-15 02:20:24 -08:00
|
|
|
%token BARBAR
|
1995-05-04 03:15:53 -07:00
|
|
|
%token BARRBRACKET
|
|
|
|
%token BEGIN
|
2013-05-23 08:12:04 -07:00
|
|
|
%token <char> CHAR
|
1996-04-22 04:15:41 -07:00
|
|
|
%token CLASS
|
1995-05-04 03:15:53 -07:00
|
|
|
%token COLON
|
|
|
|
%token COLONCOLON
|
|
|
|
%token COLONEQUAL
|
1996-04-22 04:15:41 -07:00
|
|
|
%token COLONGREATER
|
1995-05-04 03:15:53 -07:00
|
|
|
%token COMMA
|
1996-04-22 04:15:41 -07:00
|
|
|
%token CONSTRAINT
|
1995-05-04 03:15:53 -07:00
|
|
|
%token DO
|
|
|
|
%token DONE
|
|
|
|
%token DOT
|
|
|
|
%token DOTDOT
|
|
|
|
%token DOWNTO
|
|
|
|
%token ELSE
|
|
|
|
%token END
|
|
|
|
%token EOF
|
|
|
|
%token EQUAL
|
|
|
|
%token EXCEPTION
|
|
|
|
%token EXTERNAL
|
|
|
|
%token FALSE
|
2015-04-18 20:07:32 -07:00
|
|
|
%token <string * char option> FLOAT
|
1995-05-04 03:15:53 -07:00
|
|
|
%token FOR
|
|
|
|
%token FUN
|
|
|
|
%token FUNCTION
|
|
|
|
%token FUNCTOR
|
1996-04-30 07:53:58 -07:00
|
|
|
%token GREATER
|
1996-04-22 04:15:41 -07:00
|
|
|
%token GREATERRBRACE
|
1995-11-28 07:00:53 -08:00
|
|
|
%token GREATERRBRACKET
|
1995-05-04 03:15:53 -07:00
|
|
|
%token IF
|
|
|
|
%token IN
|
|
|
|
%token INCLUDE
|
1996-04-30 07:53:58 -07:00
|
|
|
%token <string> INFIXOP0
|
1995-05-04 03:15:53 -07:00
|
|
|
%token <string> INFIXOP1
|
|
|
|
%token <string> INFIXOP2
|
|
|
|
%token <string> INFIXOP3
|
|
|
|
%token <string> INFIXOP4
|
1996-04-22 04:15:41 -07:00
|
|
|
%token INHERIT
|
1998-06-24 12:22:26 -07:00
|
|
|
%token INITIALIZER
|
2015-04-18 20:07:32 -07:00
|
|
|
%token <string * char option> INT
|
1999-11-30 08:07:38 -08:00
|
|
|
%token <string> LABEL
|
1997-10-14 06:17:48 -07:00
|
|
|
%token LAZY
|
1995-05-04 03:15:53 -07:00
|
|
|
%token LBRACE
|
1996-04-22 04:15:41 -07:00
|
|
|
%token LBRACELESS
|
1995-05-04 03:15:53 -07:00
|
|
|
%token LBRACKET
|
|
|
|
%token LBRACKETBAR
|
1995-11-28 07:00:53 -08:00
|
|
|
%token LBRACKETLESS
|
2003-12-18 05:16:22 -08:00
|
|
|
%token LBRACKETGREATER
|
2013-03-05 03:30:15 -08:00
|
|
|
%token LBRACKETPERCENT
|
2013-03-05 03:46:25 -08:00
|
|
|
%token LBRACKETPERCENTPERCENT
|
1996-04-30 07:53:58 -07:00
|
|
|
%token LESS
|
1995-05-04 03:15:53 -07:00
|
|
|
%token LESSMINUS
|
|
|
|
%token LET
|
|
|
|
%token <string> LIDENT
|
|
|
|
%token LPAREN
|
2013-03-04 07:00:30 -08:00
|
|
|
%token LBRACKETAT
|
|
|
|
%token LBRACKETATAT
|
2014-04-14 07:42:41 -07:00
|
|
|
%token LBRACKETATATAT
|
1995-05-04 03:15:53 -07:00
|
|
|
%token MATCH
|
1996-04-22 04:15:41 -07:00
|
|
|
%token METHOD
|
2000-09-07 03:57:32 -07:00
|
|
|
%token MINUS
|
|
|
|
%token MINUSDOT
|
1995-05-04 03:15:53 -07:00
|
|
|
%token MINUSGREATER
|
|
|
|
%token MODULE
|
|
|
|
%token MUTABLE
|
1996-04-22 04:15:41 -07:00
|
|
|
%token NEW
|
2015-03-13 04:07:57 -07:00
|
|
|
%token NONREC
|
1998-06-24 12:22:26 -07:00
|
|
|
%token OBJECT
|
1995-05-04 03:15:53 -07:00
|
|
|
%token OF
|
|
|
|
%token OPEN
|
2000-04-11 20:43:25 -07:00
|
|
|
%token <string> OPTLABEL
|
1995-05-04 03:15:53 -07:00
|
|
|
%token OR
|
2003-08-25 06:15:47 -07:00
|
|
|
/* %token PARSER */
|
2013-03-08 01:17:30 -08:00
|
|
|
%token PERCENT
|
2000-09-07 03:57:32 -07:00
|
|
|
%token PLUS
|
2009-12-07 08:40:39 -08:00
|
|
|
%token PLUSDOT
|
2014-05-04 16:08:45 -07:00
|
|
|
%token PLUSEQ
|
1995-05-04 03:15:53 -07:00
|
|
|
%token <string> PREFIXOP
|
1996-04-22 04:15:41 -07:00
|
|
|
%token PRIVATE
|
1995-11-13 05:28:09 -08:00
|
|
|
%token QUESTION
|
1995-05-04 03:15:53 -07:00
|
|
|
%token QUOTE
|
|
|
|
%token RBRACE
|
|
|
|
%token RBRACKET
|
|
|
|
%token REC
|
|
|
|
%token RPAREN
|
|
|
|
%token SEMI
|
|
|
|
%token SEMISEMI
|
2016-05-03 08:39:45 -07:00
|
|
|
%token HASH
|
|
|
|
%token <string> HASHOP
|
1995-05-04 03:15:53 -07:00
|
|
|
%token SIG
|
|
|
|
%token STAR
|
2013-05-23 08:12:04 -07:00
|
|
|
%token <string * string option> STRING
|
1995-05-04 03:15:53 -07:00
|
|
|
%token STRUCT
|
|
|
|
%token THEN
|
2000-04-11 20:43:25 -07:00
|
|
|
%token TILDE
|
1995-05-04 03:15:53 -07:00
|
|
|
%token TO
|
|
|
|
%token TRUE
|
|
|
|
%token TRY
|
|
|
|
%token TYPE
|
|
|
|
%token <string> UIDENT
|
|
|
|
%token UNDERSCORE
|
|
|
|
%token VAL
|
1996-04-22 04:15:41 -07:00
|
|
|
%token VIRTUAL
|
1995-05-04 03:15:53 -07:00
|
|
|
%token WHEN
|
|
|
|
%token WHILE
|
|
|
|
%token WITH
|
2012-05-30 07:52:37 -07:00
|
|
|
%token <string * Location.t> COMMENT
|
2015-06-28 06:11:50 -07:00
|
|
|
%token <Docstrings.docstring> DOCSTRING
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2014-04-17 13:19:12 -07:00
|
|
|
%token EOL
|
|
|
|
|
2002-02-05 09:11:33 -08:00
|
|
|
/* Precedences and associativities.
|
|
|
|
|
|
|
|
Tokens and rules have precedences. A reduce/reduce conflict is resolved
|
2003-06-19 11:12:59 -07:00
|
|
|
in favor of the first rule (in source file order). A shift/reduce conflict
|
|
|
|
is resolved by comparing the precedence and associativity of the token to
|
|
|
|
be shifted with those of the rule to be reduced.
|
2002-02-05 09:11:33 -08:00
|
|
|
|
|
|
|
By default, a rule has the precedence of its rightmost terminal (if any).
|
|
|
|
|
|
|
|
When there is a shift/reduce conflict between a rule and a token that
|
|
|
|
have the same precedence, it is resolved using the associativity:
|
|
|
|
if the token is left-associative, the parser will reduce; if
|
|
|
|
right-associative, the parser will shift; if non-associative,
|
|
|
|
the parser will declare a syntax error.
|
|
|
|
|
|
|
|
We will only use associativities with operators of the kind x * x -> x
|
|
|
|
for example, in the rules of the form expr: expr BINOP expr
|
|
|
|
in all other cases, we define two precedences if needed to resolve
|
|
|
|
conflicts.
|
|
|
|
|
|
|
|
The precedences must be listed from low to high.
|
|
|
|
*/
|
|
|
|
|
|
|
|
%nonassoc IN
|
|
|
|
%nonassoc below_SEMI
|
|
|
|
%nonassoc SEMI /* below EQUAL ({lbl=...; lbl=...}) */
|
2003-06-20 08:16:57 -07:00
|
|
|
%nonassoc LET /* above SEMI ( ...; let ... in ...) */
|
2002-02-05 09:11:33 -08:00
|
|
|
%nonassoc below_WITH
|
|
|
|
%nonassoc FUNCTION WITH /* below BAR (match ... with ...) */
|
2003-06-20 08:16:57 -07:00
|
|
|
%nonassoc AND /* above WITH (module rec A: SIG with ... and ...) */
|
2002-02-05 09:11:33 -08:00
|
|
|
%nonassoc THEN /* below ELSE (if ... then ...) */
|
|
|
|
%nonassoc ELSE /* (if ... then ... else ...) */
|
|
|
|
%nonassoc LESSMINUS /* below COLONEQUAL (lbl <- x := e) */
|
|
|
|
%right COLONEQUAL /* expr (e := e := e) */
|
|
|
|
%nonassoc AS
|
|
|
|
%left BAR /* pattern (p|p|p) */
|
|
|
|
%nonassoc below_COMMA
|
|
|
|
%left COMMA /* expr/expr_comma_list (e,e,e) */
|
|
|
|
%right MINUSGREATER /* core_type2 (t -> t -> t) */
|
|
|
|
%right OR BARBAR /* expr (e || e || e) */
|
|
|
|
%right AMPERSAND AMPERAMPER /* expr (e && e && e) */
|
|
|
|
%nonassoc below_EQUAL
|
|
|
|
%left INFIXOP0 EQUAL LESS GREATER /* expr (e OP e OP e) */
|
|
|
|
%right INFIXOP1 /* expr (e OP e OP e) */
|
2013-03-04 07:00:30 -08:00
|
|
|
%nonassoc below_LBRACKETAT
|
|
|
|
%nonassoc LBRACKETAT
|
|
|
|
%nonassoc LBRACKETATAT
|
2002-02-05 09:11:33 -08:00
|
|
|
%right COLONCOLON /* expr (e :: e :: e) */
|
2014-05-04 16:08:45 -07:00
|
|
|
%left INFIXOP2 PLUS PLUSDOT MINUS MINUSDOT PLUSEQ /* expr (e OP e OP e) */
|
2013-03-08 01:17:30 -08:00
|
|
|
%left PERCENT INFIXOP3 STAR /* expr (e OP e OP e) */
|
2002-02-05 09:11:33 -08:00
|
|
|
%right INFIXOP4 /* expr (e OP e OP e) */
|
2009-12-07 08:40:39 -08:00
|
|
|
%nonassoc prec_unary_minus prec_unary_plus /* unary - */
|
2002-02-05 09:11:33 -08:00
|
|
|
%nonassoc prec_constant_constructor /* cf. simple_expr (C versus C x) */
|
|
|
|
%nonassoc prec_constr_appl /* above AS BAR COLONCOLON COMMA */
|
2016-05-03 08:39:45 -07:00
|
|
|
%nonassoc below_HASH
|
|
|
|
%nonassoc HASH /* simple_expr/toplevel_directive */
|
|
|
|
%left HASHOP
|
2002-02-05 09:11:33 -08:00
|
|
|
%nonassoc below_DOT
|
|
|
|
%nonassoc DOT
|
|
|
|
/* Finally, the first tokens of simple_expr are above everything else. */
|
2015-04-18 20:07:32 -07:00
|
|
|
%nonassoc BACKQUOTE BANG BEGIN CHAR FALSE FLOAT INT
|
2003-04-29 00:03:36 -07:00
|
|
|
LBRACE LBRACELESS LBRACKET LBRACKETBAR LIDENT LPAREN
|
2015-04-18 20:07:32 -07:00
|
|
|
NEW PREFIXOP STRING TRUE UIDENT
|
2014-04-30 01:05:52 -07:00
|
|
|
LBRACKETPERCENT LBRACKETPERCENTPERCENT
|
2002-02-05 09:11:33 -08:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
/* Entry points */
|
|
|
|
|
|
|
|
%start implementation /* for implementation files */
|
|
|
|
%type <Parsetree.structure> implementation
|
|
|
|
%start interface /* for interface files */
|
|
|
|
%type <Parsetree.signature> interface
|
|
|
|
%start toplevel_phrase /* for interactive use */
|
|
|
|
%type <Parsetree.toplevel_phrase> toplevel_phrase
|
1995-11-01 10:12:24 -08:00
|
|
|
%start use_file /* for the #use directive */
|
|
|
|
%type <Parsetree.toplevel_phrase list> use_file
|
2013-03-29 02:45:45 -07:00
|
|
|
%start parse_core_type
|
|
|
|
%type <Parsetree.core_type> parse_core_type
|
|
|
|
%start parse_expression
|
|
|
|
%type <Parsetree.expression> parse_expression
|
|
|
|
%start parse_pattern
|
|
|
|
%type <Parsetree.pattern> parse_pattern
|
1995-05-04 03:15:53 -07:00
|
|
|
%%
|
|
|
|
|
|
|
|
/* Entry points */
|
|
|
|
|
|
|
|
implementation:
|
2015-06-28 06:11:50 -07:00
|
|
|
structure EOF { extra_str 1 $1 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
interface:
|
2015-06-28 06:11:50 -07:00
|
|
|
signature EOF { extra_sig 1 $1 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
toplevel_phrase:
|
2015-06-28 06:11:50 -07:00
|
|
|
top_structure SEMISEMI { Ptop_def (extra_str 1 $1) }
|
1995-11-01 10:12:24 -08:00
|
|
|
| toplevel_directive SEMISEMI { $1 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| EOF { raise End_of_file }
|
|
|
|
;
|
1997-03-04 02:21:07 -08:00
|
|
|
top_structure:
|
2015-06-28 06:11:50 -07:00
|
|
|
seq_expr post_item_attributes
|
|
|
|
{ (text_str 1) @ [mkstrexp $1 $2] }
|
|
|
|
| top_structure_tail
|
|
|
|
{ $1 }
|
2013-10-04 00:54:31 -07:00
|
|
|
;
|
|
|
|
top_structure_tail:
|
|
|
|
/* empty */ { [] }
|
2015-06-28 06:11:50 -07:00
|
|
|
| structure_item top_structure_tail { (text_str 1) @ $1 :: $2 }
|
1997-03-04 02:21:07 -08:00
|
|
|
;
|
1995-11-01 10:12:24 -08:00
|
|
|
use_file:
|
2015-06-28 06:11:50 -07:00
|
|
|
use_file_body { extra_def 1 $1 }
|
|
|
|
;
|
|
|
|
use_file_body:
|
1995-11-01 10:12:24 -08:00
|
|
|
use_file_tail { $1 }
|
2014-02-25 00:16:25 -08:00
|
|
|
| seq_expr post_item_attributes use_file_tail
|
2015-06-28 06:11:50 -07:00
|
|
|
{ (text_def 1) @ Ptop_def[mkstrexp $1 $2] :: $3 }
|
1995-11-01 10:12:24 -08:00
|
|
|
;
|
|
|
|
use_file_tail:
|
2015-06-28 06:11:50 -07:00
|
|
|
EOF
|
|
|
|
{ [] }
|
|
|
|
| SEMISEMI EOF
|
|
|
|
{ text_def 1 }
|
2014-02-25 00:16:25 -08:00
|
|
|
| SEMISEMI seq_expr post_item_attributes use_file_tail
|
2015-06-28 06:11:50 -07:00
|
|
|
{ mark_rhs_docs 2 3;
|
|
|
|
(text_def 1) @ (text_def 2) @ Ptop_def[mkstrexp $2 $3] :: $4 }
|
|
|
|
| SEMISEMI structure_item use_file_tail
|
|
|
|
{ (text_def 1) @ (text_def 2) @ Ptop_def[$2] :: $3 }
|
|
|
|
| SEMISEMI toplevel_directive use_file_tail
|
|
|
|
{ mark_rhs_docs 2 3;
|
|
|
|
(text_def 1) @ (text_def 2) @ $2 :: $3 }
|
|
|
|
| structure_item use_file_tail
|
|
|
|
{ (text_def 1) @ Ptop_def[$1] :: $2 }
|
|
|
|
| toplevel_directive use_file_tail
|
|
|
|
{ mark_rhs_docs 1 1;
|
|
|
|
(text_def 1) @ $1 :: $2 }
|
1995-11-01 10:12:24 -08:00
|
|
|
;
|
2013-03-29 02:45:45 -07:00
|
|
|
parse_core_type:
|
|
|
|
core_type EOF { $1 }
|
|
|
|
;
|
|
|
|
parse_expression:
|
|
|
|
seq_expr EOF { $1 }
|
|
|
|
;
|
|
|
|
parse_pattern:
|
|
|
|
pattern EOF { $1 }
|
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
/* Module expressions */
|
|
|
|
|
2014-03-21 06:27:07 -07:00
|
|
|
functor_arg:
|
2014-03-20 08:21:00 -07:00
|
|
|
LPAREN RPAREN
|
2014-10-15 06:34:58 -07:00
|
|
|
{ mkrhs "*" 2, None }
|
2014-03-21 06:27:07 -07:00
|
|
|
| LPAREN functor_arg_name COLON module_type RPAREN
|
2014-03-20 08:21:00 -07:00
|
|
|
{ mkrhs $2 2, Some $4 }
|
|
|
|
;
|
|
|
|
|
2014-03-21 06:27:07 -07:00
|
|
|
functor_arg_name:
|
|
|
|
UIDENT { $1 }
|
|
|
|
| UNDERSCORE { "_" }
|
|
|
|
;
|
|
|
|
|
|
|
|
functor_args:
|
|
|
|
functor_args functor_arg
|
2014-03-20 08:21:00 -07:00
|
|
|
{ $2 :: $1 }
|
2014-03-21 06:27:07 -07:00
|
|
|
| functor_arg
|
2014-03-20 08:21:00 -07:00
|
|
|
{ [ $1 ] }
|
|
|
|
;
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
module_expr:
|
|
|
|
mod_longident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkmod(Pmod_ident (mkrhs $1 1)) }
|
2016-02-02 08:41:43 -08:00
|
|
|
| STRUCT attributes structure END
|
|
|
|
{ mkmod ~attrs:$2 (Pmod_structure(extra_str 3 $3)) }
|
|
|
|
| STRUCT attributes structure error
|
2016-03-08 02:24:30 -08:00
|
|
|
{ unclosed "struct" 1 "end" 4 }
|
2016-02-02 08:41:43 -08:00
|
|
|
| FUNCTOR attributes functor_args MINUSGREATER module_expr
|
|
|
|
{ let modexp =
|
|
|
|
List.fold_left
|
|
|
|
(fun acc (n, t) -> mkmod(Pmod_functor(n, t, acc)))
|
|
|
|
$5 $3
|
|
|
|
in wrap_mod_attrs modexp $2 }
|
1995-08-23 04:55:54 -07:00
|
|
|
| module_expr LPAREN module_expr RPAREN
|
|
|
|
{ mkmod(Pmod_apply($1, $3)) }
|
2013-12-16 19:52:50 -08:00
|
|
|
| module_expr LPAREN RPAREN
|
|
|
|
{ mkmod(Pmod_apply($1, mkmod (Pmod_structure []))) }
|
1997-08-22 01:55:41 -07:00
|
|
|
| module_expr LPAREN module_expr error
|
|
|
|
{ unclosed "(" 2 ")" 4 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| LPAREN module_expr COLON module_type RPAREN
|
|
|
|
{ mkmod(Pmod_constraint($2, $4)) }
|
1997-08-22 01:55:41 -07:00
|
|
|
| LPAREN module_expr COLON module_type error
|
|
|
|
{ unclosed "(" 1 ")" 5 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| LPAREN module_expr RPAREN
|
|
|
|
{ $2 }
|
1997-08-22 01:55:41 -07:00
|
|
|
| LPAREN module_expr error
|
|
|
|
{ unclosed "(" 1 ")" 3 }
|
2016-02-02 07:38:07 -08:00
|
|
|
| LPAREN VAL attributes expr RPAREN
|
|
|
|
{ mkmod ~attrs:$3 (Pmod_unpack $4)}
|
|
|
|
| LPAREN VAL attributes expr COLON package_type RPAREN
|
|
|
|
{ mkmod ~attrs:$3
|
|
|
|
(Pmod_unpack(
|
|
|
|
ghexp(Pexp_constraint($4, ghtyp(Ptyp_package $6))))) }
|
2016-02-16 04:23:31 -08:00
|
|
|
| LPAREN VAL attributes expr COLON package_type COLONGREATER package_type
|
|
|
|
RPAREN
|
2016-02-02 07:38:07 -08:00
|
|
|
{ mkmod ~attrs:$3
|
|
|
|
(Pmod_unpack(
|
|
|
|
ghexp(Pexp_coerce($4, Some(ghtyp(Ptyp_package $6)),
|
|
|
|
ghtyp(Ptyp_package $8))))) }
|
|
|
|
| LPAREN VAL attributes expr COLONGREATER package_type RPAREN
|
|
|
|
{ mkmod ~attrs:$3
|
|
|
|
(Pmod_unpack(
|
|
|
|
ghexp(Pexp_coerce($4, None, ghtyp(Ptyp_package $6))))) }
|
|
|
|
| LPAREN VAL attributes expr COLON error
|
|
|
|
{ unclosed "(" 1 ")" 6 }
|
|
|
|
| LPAREN VAL attributes expr COLONGREATER error
|
|
|
|
{ unclosed "(" 1 ")" 6 }
|
|
|
|
| LPAREN VAL attributes expr error
|
2010-10-21 16:59:33 -07:00
|
|
|
{ unclosed "(" 1 ")" 5 }
|
2013-03-04 04:54:57 -08:00
|
|
|
| module_expr attribute
|
2013-03-08 06:59:45 -08:00
|
|
|
{ Mod.attr $1 $2 }
|
2013-03-04 06:11:15 -08:00
|
|
|
| extension
|
|
|
|
{ mkmod(Pmod_extension $1) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2013-03-07 06:15:23 -08:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
structure:
|
2015-06-28 06:11:50 -07:00
|
|
|
seq_expr post_item_attributes structure_tail
|
|
|
|
{ mark_rhs_docs 1 2;
|
|
|
|
(text_str 1) @ mkstrexp $1 $2 :: $3 }
|
2013-03-07 06:15:23 -08:00
|
|
|
| structure_tail { $1 }
|
|
|
|
;
|
|
|
|
structure_tail:
|
|
|
|
/* empty */ { [] }
|
2015-06-28 06:11:50 -07:00
|
|
|
| SEMISEMI structure { (text_str 1) @ $2 }
|
|
|
|
| structure_item structure_tail { (text_str 1) @ $1 :: $2 }
|
2013-03-07 05:46:44 -08:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
structure_item:
|
2015-05-04 11:44:11 -07:00
|
|
|
let_bindings
|
|
|
|
{ val_of_let_bindings $1 }
|
|
|
|
| primitive_declaration
|
2015-12-02 07:23:47 -08:00
|
|
|
{ let (body, ext) = $1 in mkstr_ext (Pstr_primitive body) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| value_description
|
2015-12-02 07:23:47 -08:00
|
|
|
{ let (body, ext) = $1 in mkstr_ext (Pstr_primitive body) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| type_declarations
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (nr, l, ext ) = $1 in mkstr_ext (Pstr_type (nr, List.rev l)) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| str_type_extension
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (l, ext) = $1 in mkstr_ext (Pstr_typext l) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| str_exception_declaration
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (l, ext) = $1 in mkstr_ext (Pstr_exception l) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| module_binding
|
2015-12-02 09:37:48 -08:00
|
|
|
{ let (body, ext) = $1 in mkstr_ext (Pstr_module body) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| rec_module_bindings
|
2015-12-02 09:37:48 -08:00
|
|
|
{ let (l, ext) = $1 in mkstr_ext (Pstr_recmodule(List.rev l)) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| module_type_declaration
|
2015-12-02 08:42:13 -08:00
|
|
|
{ let (body, ext) = $1 in mkstr_ext (Pstr_modtype body) ext }
|
2015-12-02 08:23:08 -08:00
|
|
|
| open_statement
|
|
|
|
{ let (body, ext) = $1 in mkstr_ext (Pstr_open body) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| class_declarations
|
2015-12-02 08:16:52 -08:00
|
|
|
{ let (l, ext) = $1 in mkstr_ext (Pstr_class (List.rev l)) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| class_type_declarations
|
2015-12-02 08:16:52 -08:00
|
|
|
{ let (l, ext) = $1 in mkstr_ext (Pstr_class_type (List.rev l)) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| str_include_statement
|
2015-12-02 08:42:41 -08:00
|
|
|
{ let (body, ext) = $1 in mkstr_ext (Pstr_include body) ext }
|
2013-03-07 05:00:01 -08:00
|
|
|
| item_extension post_item_attributes
|
2015-06-28 06:11:50 -07:00
|
|
|
{ mkstr(Pstr_extension ($1, (add_docs_attrs (symbol_docs ()) $2))) }
|
2014-04-14 07:42:41 -07:00
|
|
|
| floating_attribute
|
2015-06-28 06:11:50 -07:00
|
|
|
{ mark_symbol_docs ();
|
|
|
|
mkstr(Pstr_attribute $1) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2015-05-04 11:44:11 -07:00
|
|
|
str_include_statement:
|
2015-12-02 08:42:41 -08:00
|
|
|
INCLUDE ext_attributes module_expr post_item_attributes
|
|
|
|
{ let (ext, attrs) = $2 in
|
|
|
|
Incl.mk $3 ~attrs:(attrs@$4)
|
|
|
|
~loc:(symbol_rloc()) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
2013-03-07 05:07:32 -08:00
|
|
|
module_binding_body:
|
1995-05-04 03:15:53 -07:00
|
|
|
EQUAL module_expr
|
|
|
|
{ $2 }
|
|
|
|
| COLON module_type EQUAL module_expr
|
|
|
|
{ mkmod(Pmod_constraint($4, $2)) }
|
2014-03-21 06:27:07 -07:00
|
|
|
| functor_arg module_binding_body
|
|
|
|
{ mkmod(Pmod_functor(fst $1, snd $1, $2)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2013-03-07 05:07:32 -08:00
|
|
|
module_binding:
|
2015-12-02 09:37:48 -08:00
|
|
|
MODULE ext_attributes UIDENT module_binding_body post_item_attributes
|
|
|
|
{ let (ext, attrs) = $2 in
|
|
|
|
Mb.mk (mkrhs $3 3) $4 ~attrs:(attrs@$5)
|
|
|
|
~loc:(symbol_rloc ()) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
rec_module_bindings:
|
2015-12-02 09:37:48 -08:00
|
|
|
rec_module_binding { let (b, ext) = $1 in ([b], ext) }
|
2016-02-16 04:23:31 -08:00
|
|
|
| rec_module_bindings and_module_binding
|
|
|
|
{ let (l, ext) = $1 in ($2 :: l, ext) }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
rec_module_binding:
|
2015-12-02 09:37:48 -08:00
|
|
|
MODULE ext_attributes REC UIDENT module_binding_body post_item_attributes
|
|
|
|
{ let (ext, attrs) = $2 in
|
|
|
|
Mb.mk (mkrhs $4 4) $5 ~attrs:(attrs@$6)
|
|
|
|
~loc:(symbol_rloc ()) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
and_module_binding:
|
2015-12-02 09:37:48 -08:00
|
|
|
AND attributes UIDENT module_binding_body post_item_attributes
|
|
|
|
{ Mb.mk (mkrhs $3 3) $4 ~attrs:($2@$5) ~loc:(symbol_rloc ())
|
2015-06-28 06:11:50 -07:00
|
|
|
~text:(symbol_text ()) ~docs:(symbol_docs ()) }
|
2003-06-19 08:53:53 -07:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
/* Module types */
|
|
|
|
|
|
|
|
module_type:
|
|
|
|
mty_longident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkmty(Pmty_ident (mkrhs $1 1)) }
|
2016-02-02 08:41:43 -08:00
|
|
|
| SIG attributes signature END
|
|
|
|
{ mkmty ~attrs:$2 (Pmty_signature (extra_sig 3 $3)) }
|
|
|
|
| SIG attributes signature error
|
|
|
|
{ unclosed "sig" 1 "end" 4 }
|
|
|
|
| FUNCTOR attributes functor_args MINUSGREATER module_type
|
2013-12-16 19:52:50 -08:00
|
|
|
%prec below_WITH
|
2016-02-02 08:41:43 -08:00
|
|
|
{ let mty =
|
|
|
|
List.fold_left
|
|
|
|
(fun acc (n, t) -> mkmty(Pmty_functor(n, t, acc)))
|
|
|
|
$5 $3
|
|
|
|
in wrap_mty_attrs mty $2 }
|
2015-10-25 09:24:47 -07:00
|
|
|
| module_type MINUSGREATER module_type
|
|
|
|
%prec below_WITH
|
|
|
|
{ mkmty(Pmty_functor(mknoloc "_", Some $1, $3)) }
|
1995-09-28 03:41:50 -07:00
|
|
|
| module_type WITH with_constraints
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkmty(Pmty_with($1, List.rev $3)) }
|
2016-02-02 08:41:43 -08:00
|
|
|
| MODULE TYPE OF attributes module_expr %prec below_LBRACKETAT
|
|
|
|
{ mkmty ~attrs:$4 (Pmty_typeof $5) }
|
2014-08-22 06:45:02 -07:00
|
|
|
/* | LPAREN MODULE mod_longident RPAREN
|
|
|
|
{ mkmty (Pmty_alias (mkrhs $3 3)) } */
|
1995-05-04 03:15:53 -07:00
|
|
|
| LPAREN module_type RPAREN
|
|
|
|
{ $2 }
|
1997-08-22 01:55:41 -07:00
|
|
|
| LPAREN module_type error
|
|
|
|
{ unclosed "(" 1 ")" 3 }
|
2013-03-04 06:11:15 -08:00
|
|
|
| extension
|
|
|
|
{ mkmty(Pmty_extension $1) }
|
|
|
|
| module_type attribute
|
2013-03-08 06:59:45 -08:00
|
|
|
{ Mty.attr $1 $2 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
signature:
|
2013-03-07 06:15:23 -08:00
|
|
|
/* empty */ { [] }
|
2015-06-28 06:11:50 -07:00
|
|
|
| SEMISEMI signature { (text_sig 1) @ $2 }
|
|
|
|
| signature_item signature { (text_sig 1) @ $1 :: $2 }
|
2013-03-07 05:46:44 -08:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
signature_item:
|
2015-05-04 11:44:11 -07:00
|
|
|
value_description
|
2015-12-02 07:23:47 -08:00
|
|
|
{ let (body, ext) = $1 in mksig_ext (Psig_value body) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| primitive_declaration
|
2015-12-02 07:23:47 -08:00
|
|
|
{ let (body, ext) = $1 in mksig_ext (Psig_value body) ext}
|
2015-05-04 11:44:11 -07:00
|
|
|
| type_declarations
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (nr, l, ext) = $1 in mksig_ext (Psig_type (nr, List.rev l)) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| sig_type_extension
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (l, ext) = $1 in mksig_ext (Psig_typext l) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| sig_exception_declaration
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (l, ext) = $1 in mksig_ext (Psig_exception l) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| module_declaration
|
2015-12-02 09:16:20 -08:00
|
|
|
{ let (body, ext) = $1 in mksig_ext (Psig_module body) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| module_alias
|
2015-12-02 09:16:20 -08:00
|
|
|
{ let (body, ext) = $1 in mksig_ext (Psig_module body) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| rec_module_declarations
|
2015-12-02 09:16:20 -08:00
|
|
|
{ let (l, ext) = $1 in mksig_ext (Psig_recmodule (List.rev l)) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| module_type_declaration
|
2015-12-02 08:42:13 -08:00
|
|
|
{ let (body, ext) = $1 in mksig_ext (Psig_modtype body) ext }
|
2014-04-22 08:28:20 -07:00
|
|
|
| open_statement
|
2015-12-02 08:23:08 -08:00
|
|
|
{ let (body, ext) = $1 in mksig_ext (Psig_open body) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| sig_include_statement
|
2015-12-02 08:42:41 -08:00
|
|
|
{ let (body, ext) = $1 in mksig_ext (Psig_include body) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| class_descriptions
|
2015-12-02 08:16:52 -08:00
|
|
|
{ let (l, ext) = $1 in mksig_ext (Psig_class (List.rev l)) ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
| class_type_declarations
|
2015-12-02 08:16:52 -08:00
|
|
|
{ let (l, ext) = $1 in mksig_ext (Psig_class_type (List.rev l)) ext }
|
2013-03-07 05:00:01 -08:00
|
|
|
| item_extension post_item_attributes
|
2015-06-28 06:11:50 -07:00
|
|
|
{ mksig(Psig_extension ($1, (add_docs_attrs (symbol_docs ()) $2))) }
|
2014-04-14 07:42:41 -07:00
|
|
|
| floating_attribute
|
2015-06-28 06:11:50 -07:00
|
|
|
{ mark_symbol_docs ();
|
|
|
|
mksig(Psig_attribute $1) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2014-04-22 08:28:20 -07:00
|
|
|
open_statement:
|
2015-12-02 08:23:08 -08:00
|
|
|
| OPEN override_flag ext_attributes mod_longident post_item_attributes
|
|
|
|
{ let (ext, attrs) = $3 in
|
|
|
|
Opn.mk (mkrhs $4 4) ~override:$2 ~attrs:(attrs@$5)
|
|
|
|
~loc:(symbol_rloc()) ~docs:(symbol_docs ())
|
|
|
|
, ext}
|
2014-04-22 08:28:20 -07:00
|
|
|
;
|
2015-05-04 11:44:11 -07:00
|
|
|
sig_include_statement:
|
2015-12-02 08:42:41 -08:00
|
|
|
INCLUDE ext_attributes module_type post_item_attributes %prec below_WITH
|
|
|
|
{ let (ext, attrs) = $2 in
|
|
|
|
Incl.mk $3 ~attrs:(attrs@$4)
|
|
|
|
~loc:(symbol_rloc()) ~docs:(symbol_docs ())
|
|
|
|
, ext}
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
module_declaration_body:
|
2013-03-07 05:13:36 -08:00
|
|
|
COLON module_type
|
1995-05-04 03:15:53 -07:00
|
|
|
{ $2 }
|
2015-05-04 11:44:11 -07:00
|
|
|
| LPAREN UIDENT COLON module_type RPAREN module_declaration_body
|
2013-12-16 19:52:50 -08:00
|
|
|
{ mkmty(Pmty_functor(mkrhs $2 2, Some $4, $6)) }
|
2015-05-04 11:44:11 -07:00
|
|
|
| LPAREN RPAREN module_declaration_body
|
2014-10-15 06:34:58 -07:00
|
|
|
{ mkmty(Pmty_functor(mkrhs "*" 1, None, $3)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2015-05-04 11:44:11 -07:00
|
|
|
module_declaration:
|
2015-12-02 09:16:20 -08:00
|
|
|
MODULE ext_attributes UIDENT module_declaration_body post_item_attributes
|
|
|
|
{ let (ext, attrs) = $2 in
|
|
|
|
Md.mk (mkrhs $3 3) $4 ~attrs:(attrs@$5)
|
|
|
|
~loc:(symbol_rloc()) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
2003-06-19 08:53:53 -07:00
|
|
|
;
|
2015-05-04 11:44:11 -07:00
|
|
|
module_alias:
|
2015-12-02 09:16:20 -08:00
|
|
|
MODULE ext_attributes UIDENT EQUAL mod_longident post_item_attributes
|
|
|
|
{ let (ext, attrs) = $2 in
|
|
|
|
Md.mk (mkrhs $3 3)
|
|
|
|
(Mty.alias ~loc:(rhs_loc 5) (mkrhs $5 5)) ~attrs:(attrs@$6)
|
|
|
|
~loc:(symbol_rloc()) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
rec_module_declarations:
|
2016-02-16 04:23:31 -08:00
|
|
|
rec_module_declaration
|
|
|
|
{ let (body, ext) = $1 in ([body], ext) }
|
|
|
|
| rec_module_declarations and_module_declaration
|
|
|
|
{ let (l, ext) = $1 in ($2 :: l, ext) }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
rec_module_declaration:
|
2015-12-02 09:16:20 -08:00
|
|
|
MODULE ext_attributes REC UIDENT COLON module_type post_item_attributes
|
|
|
|
{ let (ext, attrs) = $2 in
|
|
|
|
Md.mk (mkrhs $4 4) $6 ~attrs:(attrs@$7)
|
|
|
|
~loc:(symbol_rloc()) ~docs:(symbol_docs ())
|
|
|
|
, ext}
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
and_module_declaration:
|
2015-12-02 09:16:20 -08:00
|
|
|
AND attributes UIDENT COLON module_type post_item_attributes
|
|
|
|
{ Md.mk (mkrhs $3 3) $5 ~attrs:($2@$6) ~loc:(symbol_rloc())
|
2015-06-28 06:11:50 -07:00
|
|
|
~text:(symbol_text()) ~docs:(symbol_docs()) }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
module_type_declaration_body:
|
|
|
|
/* empty */ { None }
|
|
|
|
| EQUAL module_type { Some $2 }
|
|
|
|
;
|
|
|
|
module_type_declaration:
|
2016-02-16 04:23:31 -08:00
|
|
|
MODULE TYPE ext_attributes ident module_type_declaration_body
|
|
|
|
post_item_attributes
|
2015-12-02 08:42:13 -08:00
|
|
|
{ let (ext, attrs) = $3 in
|
|
|
|
Mtd.mk (mkrhs $4 4) ?typ:$5 ~attrs:(attrs@$6)
|
|
|
|
~loc:(symbol_rloc()) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
2003-06-19 08:53:53 -07:00
|
|
|
;
|
1998-06-24 12:22:26 -07:00
|
|
|
/* Class expressions */
|
|
|
|
|
|
|
|
class_declarations:
|
2016-02-16 04:23:31 -08:00
|
|
|
class_declaration
|
|
|
|
{ let (body, ext) = $1 in ([body], ext) }
|
|
|
|
| class_declarations and_class_declaration
|
|
|
|
{ let (l, ext) = $1 in ($2 :: l, ext) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_declaration:
|
2016-02-16 04:23:31 -08:00
|
|
|
CLASS ext_attributes virtual_flag class_type_parameters LIDENT
|
|
|
|
class_fun_binding post_item_attributes
|
2015-12-02 08:16:52 -08:00
|
|
|
{ let (ext, attrs) = $2 in
|
|
|
|
Ci.mk (mkrhs $5 5) $6 ~virt:$3 ~params:$4 ~attrs:(attrs@$7)
|
|
|
|
~loc:(symbol_rloc ()) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
and_class_declaration:
|
2015-12-02 08:16:52 -08:00
|
|
|
AND attributes virtual_flag class_type_parameters LIDENT class_fun_binding
|
2015-05-04 11:44:11 -07:00
|
|
|
post_item_attributes
|
2015-12-02 08:16:52 -08:00
|
|
|
{ Ci.mk (mkrhs $5 5) $6 ~virt:$3 ~params:$4
|
|
|
|
~attrs:($2@$7) ~loc:(symbol_rloc ())
|
2015-06-28 06:11:50 -07:00
|
|
|
~text:(symbol_text ()) ~docs:(symbol_docs ()) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_fun_binding:
|
|
|
|
EQUAL class_expr
|
|
|
|
{ $2 }
|
|
|
|
| COLON class_type EQUAL class_expr
|
|
|
|
{ mkclass(Pcl_constraint($4, $2)) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| labeled_simple_pattern class_fun_binding
|
|
|
|
{ let (l,o,p) = $1 in mkclass(Pcl_fun(l, o, p, $2)) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_type_parameters:
|
2013-04-16 00:51:27 -07:00
|
|
|
/*empty*/ { [] }
|
|
|
|
| LBRACKET type_parameter_list RBRACKET { List.rev $2 }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_fun_def:
|
1999-11-30 08:07:38 -08:00
|
|
|
labeled_simple_pattern MINUSGREATER class_expr
|
|
|
|
{ let (l,o,p) = $1 in mkclass(Pcl_fun(l, o, p, $3)) }
|
|
|
|
| labeled_simple_pattern class_fun_def
|
|
|
|
{ let (l,o,p) = $1 in mkclass(Pcl_fun(l, o, p, $2)) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_expr:
|
2013-03-07 05:13:36 -08:00
|
|
|
class_simple_expr
|
1998-06-24 12:22:26 -07:00
|
|
|
{ $1 }
|
2016-02-02 08:12:11 -08:00
|
|
|
| FUN attributes class_fun_def
|
|
|
|
{ wrap_class_attrs $3 $2 }
|
2013-03-07 05:13:36 -08:00
|
|
|
| class_simple_expr simple_labeled_expr_list
|
1998-06-24 12:22:26 -07:00
|
|
|
{ mkclass(Pcl_apply($1, List.rev $2)) }
|
2015-05-04 11:44:11 -07:00
|
|
|
| let_bindings IN class_expr
|
|
|
|
{ class_of_let_bindings $1 $3 }
|
2013-04-10 10:26:55 -07:00
|
|
|
| class_expr attribute
|
|
|
|
{ Cl.attr $1 $2 }
|
2013-04-10 10:44:15 -07:00
|
|
|
| extension
|
|
|
|
{ mkclass(Pcl_extension $1) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_simple_expr:
|
|
|
|
LBRACKET core_type_comma_list RBRACKET class_longident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkclass(Pcl_constr(mkloc $4 (rhs_loc 4), List.rev $2)) }
|
1998-06-24 12:22:26 -07:00
|
|
|
| class_longident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkclass(Pcl_constr(mkrhs $1 1, [])) }
|
2016-02-02 08:12:11 -08:00
|
|
|
| OBJECT attributes class_structure END
|
|
|
|
{ mkclass ~attrs:$2 (Pcl_structure $3) }
|
|
|
|
| OBJECT attributes class_structure error
|
2016-03-08 02:24:30 -08:00
|
|
|
{ unclosed "object" 1 "end" 4 }
|
1998-06-24 12:22:26 -07:00
|
|
|
| LPAREN class_expr COLON class_type RPAREN
|
|
|
|
{ mkclass(Pcl_constraint($2, $4)) }
|
|
|
|
| LPAREN class_expr COLON class_type error
|
|
|
|
{ unclosed "(" 1 ")" 5 }
|
|
|
|
| LPAREN class_expr RPAREN
|
|
|
|
{ $2 }
|
|
|
|
| LPAREN class_expr error
|
|
|
|
{ unclosed "(" 1 ")" 3 }
|
|
|
|
;
|
|
|
|
class_structure:
|
2015-06-28 06:11:50 -07:00
|
|
|
| class_self_pattern class_fields
|
|
|
|
{ Cstr.mk $1 (extra_cstr 2 (List.rev $2)) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_self_pattern:
|
|
|
|
LPAREN pattern RPAREN
|
2003-04-06 05:45:03 -07:00
|
|
|
{ reloc_pat $2 }
|
1998-06-24 12:22:26 -07:00
|
|
|
| LPAREN pattern COLON core_type RPAREN
|
1998-11-29 09:34:05 -08:00
|
|
|
{ mkpat(Ppat_constraint($2, $4)) }
|
1998-06-24 12:22:26 -07:00
|
|
|
| /* empty */
|
2003-03-31 09:11:06 -08:00
|
|
|
{ ghpat(Ppat_any) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_fields:
|
|
|
|
/* empty */
|
|
|
|
{ [] }
|
2012-05-30 07:52:37 -07:00
|
|
|
| class_fields class_field
|
2015-06-28 06:11:50 -07:00
|
|
|
{ $2 :: (text_cstr 2) @ $1 }
|
2012-05-30 07:52:37 -07:00
|
|
|
;
|
|
|
|
class_field:
|
2016-02-16 04:23:31 -08:00
|
|
|
| INHERIT override_flag attributes class_expr parent_binder
|
|
|
|
post_item_attributes
|
2016-02-02 08:12:11 -08:00
|
|
|
{ mkcf (Pcf_inherit ($2, $4, $5)) ~attrs:($3@$6) ~docs:(symbol_docs ()) }
|
2016-02-23 08:38:06 -08:00
|
|
|
| VAL value post_item_attributes
|
|
|
|
{ let v, attrs = $2 in
|
|
|
|
mkcf (Pcf_val v) ~attrs:(attrs@$3) ~docs:(symbol_docs ()) }
|
2014-05-04 13:42:34 -07:00
|
|
|
| METHOD method_ post_item_attributes
|
2016-02-02 08:12:11 -08:00
|
|
|
{ let meth, attrs = $2 in
|
|
|
|
mkcf (Pcf_method meth) ~attrs:(attrs@$3) ~docs:(symbol_docs ()) }
|
|
|
|
| CONSTRAINT attributes constrain_field post_item_attributes
|
|
|
|
{ mkcf (Pcf_constraint $3) ~attrs:($2@$4) ~docs:(symbol_docs ()) }
|
|
|
|
| INITIALIZER attributes seq_expr post_item_attributes
|
|
|
|
{ mkcf (Pcf_initializer $3) ~attrs:($2@$4) ~docs:(symbol_docs ()) }
|
2014-05-04 13:42:34 -07:00
|
|
|
| item_extension post_item_attributes
|
2015-06-28 06:11:50 -07:00
|
|
|
{ mkcf (Pcf_extension $1) ~attrs:$2 ~docs:(symbol_docs ()) }
|
2014-05-04 13:42:34 -07:00
|
|
|
| floating_attribute
|
2015-06-28 06:11:50 -07:00
|
|
|
{ mark_symbol_docs ();
|
|
|
|
mkcf (Pcf_attribute $1) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
parent_binder:
|
|
|
|
AS LIDENT
|
|
|
|
{ Some $2 }
|
|
|
|
| /* empty */
|
2006-04-04 19:28:13 -07:00
|
|
|
{ None }
|
|
|
|
;
|
2013-04-10 04:17:41 -07:00
|
|
|
value:
|
|
|
|
/* TODO: factorize these rules (also with method): */
|
2016-02-23 08:38:06 -08:00
|
|
|
override_flag attributes MUTABLE VIRTUAL label COLON core_type
|
2010-04-07 20:58:41 -07:00
|
|
|
{ if $1 = Override then syntax_error ();
|
2016-02-23 08:38:06 -08:00
|
|
|
(mkloc $5 (rhs_loc 5), Mutable, Cfk_virtual $7), $2 }
|
|
|
|
| override_flag attributes VIRTUAL mutable_flag label COLON core_type
|
2010-04-07 20:58:41 -07:00
|
|
|
{ if $1 = Override then syntax_error ();
|
2016-02-23 08:38:06 -08:00
|
|
|
(mkrhs $5 5, $4, Cfk_virtual $7), $2 }
|
|
|
|
| override_flag attributes mutable_flag label EQUAL seq_expr
|
|
|
|
{ (mkrhs $4 4, $3, Cfk_concrete ($1, $6)), $2 }
|
|
|
|
| override_flag attributes mutable_flag label type_constraint EQUAL seq_expr
|
2013-04-10 04:17:41 -07:00
|
|
|
{
|
2016-02-23 08:38:06 -08:00
|
|
|
let e = mkexp_constraint $7 $5 in
|
|
|
|
(mkrhs $4 4, $3, Cfk_concrete ($1, e)), $2
|
2013-04-10 04:17:41 -07:00
|
|
|
}
|
|
|
|
;
|
|
|
|
method_:
|
|
|
|
/* TODO: factorize those rules... */
|
2016-02-23 08:38:06 -08:00
|
|
|
override_flag attributes PRIVATE VIRTUAL label COLON poly_type
|
2013-04-10 04:17:41 -07:00
|
|
|
{ if $1 = Override then syntax_error ();
|
2016-02-23 08:38:06 -08:00
|
|
|
(mkloc $5 (rhs_loc 5), Private, Cfk_virtual $7), $2 }
|
|
|
|
| override_flag attributes VIRTUAL private_flag label COLON poly_type
|
2013-04-10 04:17:41 -07:00
|
|
|
{ if $1 = Override then syntax_error ();
|
2016-02-23 08:38:06 -08:00
|
|
|
(mkloc $5 (rhs_loc 5), $4, Cfk_virtual $7), $2 }
|
|
|
|
| override_flag attributes private_flag label strict_binding
|
|
|
|
{ (mkloc $4 (rhs_loc 4), $3,
|
|
|
|
Cfk_concrete ($1, ghexp(Pexp_poly ($5, None)))), $2 }
|
|
|
|
| override_flag attributes private_flag label COLON poly_type EQUAL seq_expr
|
|
|
|
{ (mkloc $4 (rhs_loc 4), $3,
|
|
|
|
Cfk_concrete ($1, ghexp(Pexp_poly($8, Some $6)))), $2 }
|
|
|
|
| override_flag attributes private_flag label COLON TYPE lident_list
|
2011-11-24 01:02:48 -08:00
|
|
|
DOT core_type EQUAL seq_expr
|
2016-02-02 08:12:11 -08:00
|
|
|
{ let exp, poly = wrap_type_annotation $7 $9 $11 in
|
2016-02-23 08:38:06 -08:00
|
|
|
(mkloc $4 (rhs_loc 4), $3,
|
|
|
|
Cfk_concrete ($1, ghexp(Pexp_poly(exp, Some poly)))), $2 }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
/* Class types */
|
|
|
|
|
|
|
|
class_type:
|
|
|
|
class_signature
|
|
|
|
{ $1 }
|
2015-07-17 04:51:17 -07:00
|
|
|
| QUESTION LIDENT COLON simple_core_type_or_tuple MINUSGREATER
|
2014-04-12 03:17:02 -07:00
|
|
|
class_type
|
2014-12-22 01:06:02 -08:00
|
|
|
{ mkcty(Pcty_arrow(Optional $2 , $4, $6)) }
|
2015-07-17 04:51:17 -07:00
|
|
|
| OPTLABEL simple_core_type_or_tuple MINUSGREATER class_type
|
2014-12-22 01:06:02 -08:00
|
|
|
{ mkcty(Pcty_arrow(Optional $1, $2, $4)) }
|
2015-07-17 04:51:17 -07:00
|
|
|
| LIDENT COLON simple_core_type_or_tuple MINUSGREATER class_type
|
2014-12-22 00:45:55 -08:00
|
|
|
{ mkcty(Pcty_arrow(Labelled $1, $3, $5)) }
|
2015-07-17 04:51:17 -07:00
|
|
|
| simple_core_type_or_tuple MINUSGREATER class_type
|
2014-12-22 00:45:55 -08:00
|
|
|
{ mkcty(Pcty_arrow(Nolabel, $1, $3)) }
|
2014-08-22 06:45:02 -07:00
|
|
|
;
|
1998-06-24 12:22:26 -07:00
|
|
|
class_signature:
|
|
|
|
LBRACKET core_type_comma_list RBRACKET clty_longident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkcty(Pcty_constr (mkloc $4 (rhs_loc 4), List.rev $2)) }
|
1998-06-24 12:22:26 -07:00
|
|
|
| clty_longident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkcty(Pcty_constr (mkrhs $1 1, [])) }
|
2016-02-23 08:13:16 -08:00
|
|
|
| OBJECT attributes class_sig_body END
|
|
|
|
{ mkcty ~attrs:$2 (Pcty_signature $3) }
|
|
|
|
| OBJECT attributes class_sig_body error
|
|
|
|
{ unclosed "object" 1 "end" 4 }
|
2014-08-22 06:45:02 -07:00
|
|
|
| class_signature attribute
|
|
|
|
{ Cty.attr $1 $2 }
|
|
|
|
| extension
|
|
|
|
{ mkcty(Pcty_extension $1) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_sig_body:
|
|
|
|
class_self_type class_sig_fields
|
2015-06-28 06:11:50 -07:00
|
|
|
{ Csig.mk $1 (extra_csig 2 (List.rev $2)) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_self_type:
|
|
|
|
LPAREN core_type RPAREN
|
|
|
|
{ $2 }
|
|
|
|
| /* empty */
|
|
|
|
{ mktyp(Ptyp_any) }
|
|
|
|
;
|
|
|
|
class_sig_fields:
|
|
|
|
/* empty */ { [] }
|
2015-06-28 06:11:50 -07:00
|
|
|
| class_sig_fields class_sig_field { $2 :: (text_csig 2) @ $1 }
|
2012-05-30 07:52:37 -07:00
|
|
|
;
|
|
|
|
class_sig_field:
|
2016-02-23 08:13:16 -08:00
|
|
|
INHERIT attributes class_signature post_item_attributes
|
|
|
|
{ mkctf (Pctf_inherit $3) ~attrs:($2@$4) ~docs:(symbol_docs ()) }
|
|
|
|
| VAL attributes value_type post_item_attributes
|
|
|
|
{ mkctf (Pctf_val $3) ~attrs:($2@$4) ~docs:(symbol_docs ()) }
|
2016-04-19 05:40:37 -07:00
|
|
|
| METHOD attributes private_virtual_flags label COLON poly_type
|
|
|
|
post_item_attributes
|
2013-04-10 04:17:41 -07:00
|
|
|
{
|
2016-02-23 08:13:16 -08:00
|
|
|
let (p, v) = $3 in
|
|
|
|
mkctf (Pctf_method ($4, p, v, $6)) ~attrs:($2@$7) ~docs:(symbol_docs ())
|
2013-04-10 04:17:41 -07:00
|
|
|
}
|
2016-02-23 08:13:16 -08:00
|
|
|
| CONSTRAINT attributes constrain_field post_item_attributes
|
|
|
|
{ mkctf (Pctf_constraint $3) ~attrs:($2@$4) ~docs:(symbol_docs ()) }
|
2014-05-04 13:42:34 -07:00
|
|
|
| item_extension post_item_attributes
|
2015-06-28 06:11:50 -07:00
|
|
|
{ mkctf (Pctf_extension $1) ~attrs:$2 ~docs:(symbol_docs ()) }
|
2014-05-04 13:42:34 -07:00
|
|
|
| floating_attribute
|
2015-06-28 06:11:50 -07:00
|
|
|
{ mark_symbol_docs ();
|
|
|
|
mkctf(Pctf_attribute $1) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
value_type:
|
2006-04-04 19:28:13 -07:00
|
|
|
VIRTUAL mutable_flag label COLON core_type
|
2012-05-30 07:52:37 -07:00
|
|
|
{ $3, $2, Virtual, $5 }
|
2006-04-04 19:28:13 -07:00
|
|
|
| MUTABLE virtual_flag label COLON core_type
|
2012-05-30 07:52:37 -07:00
|
|
|
{ $3, Mutable, $2, $5 }
|
2006-04-04 19:28:13 -07:00
|
|
|
| label COLON core_type
|
2012-05-30 07:52:37 -07:00
|
|
|
{ $1, Immutable, Concrete, $3 }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
constrain:
|
2012-05-30 07:52:37 -07:00
|
|
|
core_type EQUAL core_type { $1, $3, symbol_rloc() }
|
|
|
|
;
|
|
|
|
constrain_field:
|
|
|
|
core_type EQUAL core_type { $1, $3 }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_descriptions:
|
2016-02-16 04:23:31 -08:00
|
|
|
class_description
|
|
|
|
{ let (body, ext) = $1 in ([body],ext) }
|
|
|
|
| class_descriptions and_class_description
|
|
|
|
{ let (l, ext) = $1 in ($2 :: l, ext) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_description:
|
2016-02-16 04:23:31 -08:00
|
|
|
CLASS ext_attributes virtual_flag class_type_parameters LIDENT COLON
|
|
|
|
class_type post_item_attributes
|
2015-12-02 08:16:52 -08:00
|
|
|
{ let (ext, attrs) = $2 in
|
2016-03-09 02:40:16 -08:00
|
|
|
Ci.mk (mkrhs $5 5) $7 ~virt:$3 ~params:$4 ~attrs:(attrs @ $8)
|
2015-12-02 08:16:52 -08:00
|
|
|
~loc:(symbol_rloc ()) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
and_class_description:
|
2015-12-02 08:16:52 -08:00
|
|
|
AND attributes virtual_flag class_type_parameters LIDENT COLON class_type
|
2015-05-04 11:44:11 -07:00
|
|
|
post_item_attributes
|
2015-12-02 08:16:52 -08:00
|
|
|
{ Ci.mk (mkrhs $5 5) $7 ~virt:$3 ~params:$4
|
|
|
|
~attrs:($2@$8) ~loc:(symbol_rloc ())
|
2015-06-28 06:11:50 -07:00
|
|
|
~text:(symbol_text ()) ~docs:(symbol_docs ()) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_type_declarations:
|
2016-02-16 04:23:31 -08:00
|
|
|
class_type_declaration
|
|
|
|
{ let (body, ext) = $1 in ([body],ext) }
|
|
|
|
| class_type_declarations and_class_type_declaration
|
|
|
|
{ let (l, ext) = $1 in ($2 :: l, ext) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_type_declaration:
|
2015-12-02 08:16:52 -08:00
|
|
|
CLASS TYPE ext_attributes virtual_flag class_type_parameters LIDENT EQUAL
|
2015-05-04 11:44:11 -07:00
|
|
|
class_signature post_item_attributes
|
2015-12-02 08:16:52 -08:00
|
|
|
{ let (ext, attrs) = $3 in
|
|
|
|
Ci.mk (mkrhs $6 6) $8 ~virt:$4 ~params:$5 ~attrs:(attrs@$9)
|
|
|
|
~loc:(symbol_rloc ()) ~docs:(symbol_docs ())
|
|
|
|
, ext}
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
and_class_type_declaration:
|
2015-12-02 08:16:52 -08:00
|
|
|
AND attributes virtual_flag class_type_parameters LIDENT EQUAL
|
2015-05-04 11:44:11 -07:00
|
|
|
class_signature post_item_attributes
|
2015-12-02 08:16:52 -08:00
|
|
|
{ Ci.mk (mkrhs $5 5) $7 ~virt:$3 ~params:$4
|
|
|
|
~attrs:($2@$8) ~loc:(symbol_rloc ())
|
2015-06-28 06:11:50 -07:00
|
|
|
~text:(symbol_text ()) ~docs:(symbol_docs ()) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Core expressions */
|
|
|
|
|
1997-05-12 08:10:03 -07:00
|
|
|
seq_expr:
|
2002-02-05 09:11:33 -08:00
|
|
|
| expr %prec below_SEMI { $1 }
|
2003-04-06 05:45:03 -07:00
|
|
|
| expr SEMI { reloc_exp $1 }
|
1997-05-12 08:10:03 -07:00
|
|
|
| expr SEMI seq_expr { mkexp(Pexp_sequence($1, $3)) }
|
2016-03-15 04:42:25 -07:00
|
|
|
| expr SEMI PERCENT attr_id seq_expr
|
|
|
|
{ let seq = mkexp(Pexp_sequence ($1, $5)) in
|
|
|
|
let payload = PStr [mkstrexp seq []] in
|
|
|
|
mkexp (Pexp_extension ($4, payload)) }
|
1997-05-12 08:10:03 -07:00
|
|
|
;
|
1999-11-30 08:07:38 -08:00
|
|
|
labeled_simple_pattern:
|
1999-12-08 00:21:57 -08:00
|
|
|
QUESTION LPAREN label_let_pattern opt_default RPAREN
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Optional (fst $3), $4, snd $3) }
|
2000-04-11 20:43:25 -07:00
|
|
|
| QUESTION label_var
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Optional (fst $2), None, snd $2) }
|
2000-04-11 20:43:25 -07:00
|
|
|
| OPTLABEL LPAREN let_pattern opt_default RPAREN
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Optional $1, $4, $3) }
|
2000-04-11 20:43:25 -07:00
|
|
|
| OPTLABEL pattern_var
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Optional $1, None, $2) }
|
2000-04-11 20:43:25 -07:00
|
|
|
| TILDE LPAREN label_let_pattern RPAREN
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Labelled (fst $3), None, snd $3) }
|
2000-04-11 20:43:25 -07:00
|
|
|
| TILDE label_var
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Labelled (fst $2), None, snd $2) }
|
2000-04-11 20:43:25 -07:00
|
|
|
| LABEL simple_pattern
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Labelled $1, None, $2) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| simple_pattern
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Nolabel, None, $1) }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
2000-04-11 20:43:25 -07:00
|
|
|
pattern_var:
|
2012-05-30 07:52:37 -07:00
|
|
|
LIDENT { mkpat(Ppat_var (mkrhs $1 1)) }
|
2006-12-14 20:51:11 -08:00
|
|
|
| UNDERSCORE { mkpat Ppat_any }
|
2000-04-11 20:43:25 -07:00
|
|
|
;
|
1999-12-08 00:21:57 -08:00
|
|
|
opt_default:
|
|
|
|
/* empty */ { None }
|
|
|
|
| EQUAL seq_expr { Some $2 }
|
|
|
|
;
|
|
|
|
label_let_pattern:
|
2000-04-11 20:43:25 -07:00
|
|
|
label_var
|
1999-12-08 00:21:57 -08:00
|
|
|
{ $1 }
|
2000-04-11 20:43:25 -07:00
|
|
|
| label_var COLON core_type
|
1999-12-08 00:21:57 -08:00
|
|
|
{ let (lab, pat) = $1 in (lab, mkpat(Ppat_constraint(pat, $3))) }
|
|
|
|
;
|
2000-04-11 20:43:25 -07:00
|
|
|
label_var:
|
2012-05-30 07:52:37 -07:00
|
|
|
LIDENT { ($1, mkpat(Ppat_var (mkrhs $1 1))) }
|
1999-12-08 00:21:57 -08:00
|
|
|
;
|
2000-04-11 20:43:25 -07:00
|
|
|
let_pattern:
|
|
|
|
pattern
|
|
|
|
{ $1 }
|
|
|
|
| pattern COLON core_type
|
|
|
|
{ mkpat(Ppat_constraint($1, $3)) }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
expr:
|
2016-05-03 08:39:45 -07:00
|
|
|
simple_expr %prec below_HASH
|
1995-05-04 03:15:53 -07:00
|
|
|
{ $1 }
|
2013-03-07 05:13:36 -08:00
|
|
|
| simple_expr simple_labeled_expr_list
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkexp(Pexp_apply($1, List.rev $2)) }
|
2015-05-04 11:44:11 -07:00
|
|
|
| let_bindings IN seq_expr
|
|
|
|
{ expr_of_let_bindings $1 $3 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| LET MODULE ext_attributes UIDENT module_binding_body IN seq_expr
|
2013-03-08 00:42:53 -08:00
|
|
|
{ mkexp_attrs (Pexp_letmodule(mkrhs $4 4, $5, $7)) $3 }
|
2016-06-29 19:00:06 -07:00
|
|
|
| LET EXCEPTION ext_attributes let_exception_declaration IN seq_expr
|
|
|
|
{ mkexp_attrs (Pexp_letexception($4, $6)) $3 }
|
2013-07-16 06:34:30 -07:00
|
|
|
| LET OPEN override_flag ext_attributes mod_longident IN seq_expr
|
|
|
|
{ mkexp_attrs (Pexp_open($3, mkrhs $5 5, $7)) $4 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| FUNCTION ext_attributes opt_bar match_cases
|
2013-04-17 04:43:29 -07:00
|
|
|
{ mkexp_attrs (Pexp_function(List.rev $4)) $2 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| FUN ext_attributes labeled_simple_pattern fun_def
|
2013-04-15 09:23:22 -07:00
|
|
|
{ let (l,o,p) = $3 in
|
2013-04-17 04:43:29 -07:00
|
|
|
mkexp_attrs (Pexp_fun(l, o, p, $4)) $2 }
|
2015-07-26 12:01:42 -07:00
|
|
|
| FUN ext_attributes LPAREN TYPE lident_list RPAREN fun_def
|
|
|
|
{ mkexp_attrs (mk_newtypes $5 $7).pexp_desc $2 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| MATCH ext_attributes seq_expr WITH opt_bar match_cases
|
2013-03-06 06:53:39 -08:00
|
|
|
{ mkexp_attrs (Pexp_match($3, List.rev $6)) $2 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| TRY ext_attributes seq_expr WITH opt_bar match_cases
|
2013-03-06 06:53:39 -08:00
|
|
|
{ mkexp_attrs (Pexp_try($3, List.rev $6)) $2 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| TRY ext_attributes seq_expr WITH error
|
1997-11-12 04:32:53 -08:00
|
|
|
{ syntax_error() }
|
2002-02-05 09:11:33 -08:00
|
|
|
| expr_comma_list %prec below_COMMA
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkexp(Pexp_tuple(List.rev $1)) }
|
2016-05-03 08:39:45 -07:00
|
|
|
| constr_longident simple_expr %prec below_HASH
|
2013-04-17 02:46:52 -07:00
|
|
|
{ mkexp(Pexp_construct(mkrhs $1 1, Some $2)) }
|
2016-05-03 08:39:45 -07:00
|
|
|
| name_tag simple_expr %prec below_HASH
|
1999-11-30 08:07:38 -08:00
|
|
|
{ mkexp(Pexp_variant($1, Some $2)) }
|
2013-03-08 01:17:30 -08:00
|
|
|
| IF ext_attributes seq_expr THEN expr ELSE expr
|
2013-03-08 00:42:53 -08:00
|
|
|
{ mkexp_attrs(Pexp_ifthenelse($3, $5, Some $7)) $2 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| IF ext_attributes seq_expr THEN expr
|
2013-03-08 00:42:53 -08:00
|
|
|
{ mkexp_attrs (Pexp_ifthenelse($3, $5, None)) $2 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| WHILE ext_attributes seq_expr DO seq_expr DONE
|
2013-03-08 00:42:53 -08:00
|
|
|
{ mkexp_attrs (Pexp_while($3, $5)) $2 }
|
2014-04-12 03:17:02 -07:00
|
|
|
| FOR ext_attributes pattern EQUAL seq_expr direction_flag seq_expr DO
|
|
|
|
seq_expr DONE
|
2013-12-02 10:00:18 -08:00
|
|
|
{ mkexp_attrs(Pexp_for($3, $5, $7, $6, $9)) $2 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| expr COLONCOLON expr
|
2012-12-08 12:56:07 -08:00
|
|
|
{ mkexp_cons (rhs_loc 2) (ghexp(Pexp_tuple[$1;$3])) (symbol_rloc()) }
|
2005-02-16 06:38:02 -08:00
|
|
|
| LPAREN COLONCOLON RPAREN LPAREN expr COMMA expr RPAREN
|
2012-12-08 12:56:07 -08:00
|
|
|
{ mkexp_cons (rhs_loc 2) (ghexp(Pexp_tuple[$5;$7])) (symbol_rloc()) }
|
1996-04-30 07:53:58 -07:00
|
|
|
| expr INFIXOP0 expr
|
|
|
|
{ mkinfix $1 $2 $3 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| expr INFIXOP1 expr
|
|
|
|
{ mkinfix $1 $2 $3 }
|
|
|
|
| expr INFIXOP2 expr
|
|
|
|
{ mkinfix $1 $2 $3 }
|
|
|
|
| expr INFIXOP3 expr
|
|
|
|
{ mkinfix $1 $2 $3 }
|
|
|
|
| expr INFIXOP4 expr
|
|
|
|
{ mkinfix $1 $2 $3 }
|
2000-09-07 03:57:32 -07:00
|
|
|
| expr PLUS expr
|
|
|
|
{ mkinfix $1 "+" $3 }
|
2009-12-07 08:40:39 -08:00
|
|
|
| expr PLUSDOT expr
|
|
|
|
{ mkinfix $1 "+." $3 }
|
2014-05-06 12:57:38 -07:00
|
|
|
| expr PLUSEQ expr
|
|
|
|
{ mkinfix $1 "+=" $3 }
|
2000-09-07 03:57:32 -07:00
|
|
|
| expr MINUS expr
|
|
|
|
{ mkinfix $1 "-" $3 }
|
|
|
|
| expr MINUSDOT expr
|
|
|
|
{ mkinfix $1 "-." $3 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| expr STAR expr
|
2000-01-07 08:35:15 -08:00
|
|
|
{ mkinfix $1 "*" $3 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| expr PERCENT expr
|
|
|
|
{ mkinfix $1 "%" $3 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| expr EQUAL expr
|
2000-01-07 08:35:15 -08:00
|
|
|
{ mkinfix $1 "=" $3 }
|
1996-04-30 07:53:58 -07:00
|
|
|
| expr LESS expr
|
2016-03-09 02:40:16 -08:00
|
|
|
{ mkinfix $1 "<" $3 }
|
1996-04-30 07:53:58 -07:00
|
|
|
| expr GREATER expr
|
2000-01-07 08:35:15 -08:00
|
|
|
{ mkinfix $1 ">" $3 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| expr OR expr
|
|
|
|
{ mkinfix $1 "or" $3 }
|
1995-12-15 02:20:24 -08:00
|
|
|
| expr BARBAR expr
|
|
|
|
{ mkinfix $1 "||" $3 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| expr AMPERSAND expr
|
|
|
|
{ mkinfix $1 "&" $3 }
|
1995-12-15 02:20:24 -08:00
|
|
|
| expr AMPERAMPER expr
|
|
|
|
{ mkinfix $1 "&&" $3 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| expr COLONEQUAL expr
|
|
|
|
{ mkinfix $1 ":=" $3 }
|
2000-09-07 03:57:32 -07:00
|
|
|
| subtractive expr %prec prec_unary_minus
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkuminus $1 $2 }
|
2009-12-07 08:40:39 -08:00
|
|
|
| additive expr %prec prec_unary_plus
|
|
|
|
{ mkuplus $1 $2 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| simple_expr DOT label_longident LESSMINUS expr
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkexp(Pexp_setfield($1, mkrhs $3 3, $5)) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| simple_expr DOT LPAREN seq_expr RPAREN LESSMINUS expr
|
2015-11-29 09:59:33 -08:00
|
|
|
{ mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "Array" "set")),
|
2014-12-22 00:45:55 -08:00
|
|
|
[Nolabel,$1; Nolabel,$4; Nolabel,$7])) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| simple_expr DOT LBRACKET seq_expr RBRACKET LESSMINUS expr
|
2015-11-29 09:59:33 -08:00
|
|
|
{ mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "String" "set")),
|
2014-12-22 00:45:55 -08:00
|
|
|
[Nolabel,$1; Nolabel,$4; Nolabel,$7])) }
|
2000-02-24 09:42:32 -08:00
|
|
|
| simple_expr DOT LBRACE expr RBRACE LESSMINUS expr
|
|
|
|
{ bigarray_set $1 $4 $7 }
|
1996-04-22 04:15:41 -07:00
|
|
|
| label LESSMINUS expr
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkexp(Pexp_setinstvar(mkrhs $1 1, $3)) }
|
2016-05-03 08:39:45 -07:00
|
|
|
| ASSERT ext_attributes simple_expr %prec below_HASH
|
2013-04-17 02:18:03 -07:00
|
|
|
{ mkexp_attrs (Pexp_assert $3) $2 }
|
2016-05-03 08:39:45 -07:00
|
|
|
| LAZY ext_attributes simple_expr %prec below_HASH
|
2013-03-08 00:42:53 -08:00
|
|
|
{ mkexp_attrs (Pexp_lazy $3) $2 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| OBJECT ext_attributes class_structure END
|
2013-03-08 00:42:53 -08:00
|
|
|
{ mkexp_attrs (Pexp_object $3) $2 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| OBJECT ext_attributes class_structure error
|
2014-04-11 04:26:59 -07:00
|
|
|
{ unclosed "object" 1 "end" 4 }
|
2013-03-04 04:54:57 -08:00
|
|
|
| expr attribute
|
2013-03-08 06:59:45 -08:00
|
|
|
{ Exp.attr $1 $2 }
|
2015-12-03 04:42:24 -08:00
|
|
|
| UNDERSCORE
|
|
|
|
{ not_expecting 1 "wildcard \"_\"" }
|
2013-02-28 08:51:59 -08:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
simple_expr:
|
|
|
|
val_longident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkexp(Pexp_ident (mkrhs $1 1)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| constant
|
|
|
|
{ mkexp(Pexp_constant $1) }
|
2002-02-05 09:11:33 -08:00
|
|
|
| constr_longident %prec prec_constant_constructor
|
2013-04-17 02:46:52 -07:00
|
|
|
{ mkexp(Pexp_construct(mkrhs $1 1, None)) }
|
2002-02-05 09:11:33 -08:00
|
|
|
| name_tag %prec prec_constant_constructor
|
1999-11-30 08:07:38 -08:00
|
|
|
{ mkexp(Pexp_variant($1, None)) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| LPAREN seq_expr RPAREN
|
2003-04-06 05:45:03 -07:00
|
|
|
{ reloc_exp $2 }
|
2013-03-22 04:25:52 -07:00
|
|
|
| LPAREN seq_expr error
|
1997-08-22 01:55:41 -07:00
|
|
|
{ unclosed "(" 1 ")" 3 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| BEGIN ext_attributes seq_expr END
|
2013-03-06 06:53:39 -08:00
|
|
|
{ wrap_exp_attrs (reloc_exp $3) $2 (* check location *) }
|
2013-03-08 01:17:30 -08:00
|
|
|
| BEGIN ext_attributes END
|
2013-03-06 06:53:39 -08:00
|
|
|
{ mkexp_attrs (Pexp_construct (mkloc (Lident "()") (symbol_rloc ()),
|
2013-04-17 02:46:52 -07:00
|
|
|
None)) $2 }
|
2013-03-08 01:17:30 -08:00
|
|
|
| BEGIN ext_attributes seq_expr error
|
2016-04-28 07:00:18 -07:00
|
|
|
{ unclosed "begin" 1 "end" 4 }
|
1997-05-12 08:10:03 -07:00
|
|
|
| LPAREN seq_expr type_constraint RPAREN
|
2013-04-17 05:23:44 -07:00
|
|
|
{ mkexp_constraint $2 $3 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| simple_expr DOT label_longident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkexp(Pexp_field($1, mkrhs $3 3)) }
|
2010-04-26 11:27:14 -07:00
|
|
|
| mod_longident DOT LPAREN seq_expr RPAREN
|
2013-05-16 06:34:53 -07:00
|
|
|
{ mkexp(Pexp_open(Fresh, mkrhs $1 1, $4)) }
|
2015-04-12 02:54:41 -07:00
|
|
|
| mod_longident DOT LPAREN RPAREN
|
|
|
|
{ mkexp(Pexp_open(Fresh, mkrhs $1 1,
|
2015-09-11 04:58:31 -07:00
|
|
|
mkexp(Pexp_construct(mkrhs (Lident "()") 1, None)))) }
|
2010-04-26 11:27:14 -07:00
|
|
|
| mod_longident DOT LPAREN seq_expr error
|
|
|
|
{ unclosed "(" 3 ")" 5 }
|
1997-05-12 08:10:03 -07:00
|
|
|
| simple_expr DOT LPAREN seq_expr RPAREN
|
2015-11-29 09:59:33 -08:00
|
|
|
{ mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "Array" "get")),
|
2014-12-22 00:45:55 -08:00
|
|
|
[Nolabel,$1; Nolabel,$4])) }
|
1997-08-22 01:55:41 -07:00
|
|
|
| simple_expr DOT LPAREN seq_expr error
|
|
|
|
{ unclosed "(" 3 ")" 5 }
|
1997-05-12 08:10:03 -07:00
|
|
|
| simple_expr DOT LBRACKET seq_expr RBRACKET
|
2015-11-29 09:59:33 -08:00
|
|
|
{ mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "String" "get")),
|
2014-12-22 00:45:55 -08:00
|
|
|
[Nolabel,$1; Nolabel,$4])) }
|
1997-08-22 01:55:41 -07:00
|
|
|
| simple_expr DOT LBRACKET seq_expr error
|
|
|
|
{ unclosed "[" 3 "]" 5 }
|
2000-02-24 09:42:32 -08:00
|
|
|
| simple_expr DOT LBRACE expr RBRACE
|
|
|
|
{ bigarray_get $1 $4 }
|
|
|
|
| simple_expr DOT LBRACE expr_comma_list error
|
|
|
|
{ unclosed "{" 3 "}" 5 }
|
2013-03-22 04:25:52 -07:00
|
|
|
| LBRACE record_expr RBRACE
|
|
|
|
{ let (exten, fields) = $2 in mkexp (Pexp_record(fields, exten)) }
|
|
|
|
| LBRACE record_expr error
|
2004-05-19 05:15:19 -07:00
|
|
|
{ unclosed "{" 1 "}" 3 }
|
2014-02-04 08:55:20 -08:00
|
|
|
| mod_longident DOT LBRACE record_expr RBRACE
|
|
|
|
{ let (exten, fields) = $4 in
|
|
|
|
let rec_exp = mkexp(Pexp_record(fields, exten)) in
|
|
|
|
mkexp(Pexp_open(Fresh, mkrhs $1 1, rec_exp)) }
|
|
|
|
| mod_longident DOT LBRACE record_expr error
|
|
|
|
{ unclosed "{" 3 "}" 5 }
|
2013-03-22 04:25:52 -07:00
|
|
|
| LBRACKETBAR expr_semi_list opt_semi BARRBRACKET
|
|
|
|
{ mkexp (Pexp_array(List.rev $2)) }
|
|
|
|
| LBRACKETBAR expr_semi_list opt_semi error
|
1997-08-22 01:55:41 -07:00
|
|
|
{ unclosed "[|" 1 "|]" 4 }
|
2013-03-22 04:25:52 -07:00
|
|
|
| LBRACKETBAR BARRBRACKET
|
|
|
|
{ mkexp (Pexp_array []) }
|
2014-02-04 08:55:20 -08:00
|
|
|
| mod_longident DOT LBRACKETBAR expr_semi_list opt_semi BARRBRACKET
|
|
|
|
{ mkexp(Pexp_open(Fresh, mkrhs $1 1, mkexp(Pexp_array(List.rev $4)))) }
|
2015-04-12 02:54:41 -07:00
|
|
|
| mod_longident DOT LBRACKETBAR BARRBRACKET
|
|
|
|
{ mkexp(Pexp_open(Fresh, mkrhs $1 1, mkexp(Pexp_array []))) }
|
2014-02-04 08:55:20 -08:00
|
|
|
| mod_longident DOT LBRACKETBAR expr_semi_list opt_semi error
|
|
|
|
{ unclosed "[|" 3 "|]" 6 }
|
2013-03-22 04:25:52 -07:00
|
|
|
| LBRACKET expr_semi_list opt_semi RBRACKET
|
|
|
|
{ reloc_exp (mktailexp (rhs_loc 4) (List.rev $2)) }
|
|
|
|
| LBRACKET expr_semi_list opt_semi error
|
1997-08-22 01:55:41 -07:00
|
|
|
{ unclosed "[" 1 "]" 4 }
|
2014-02-04 08:55:20 -08:00
|
|
|
| mod_longident DOT LBRACKET expr_semi_list opt_semi RBRACKET
|
|
|
|
{ let list_exp = reloc_exp (mktailexp (rhs_loc 6) (List.rev $4)) in
|
|
|
|
mkexp(Pexp_open(Fresh, mkrhs $1 1, list_exp)) }
|
2015-04-12 02:54:41 -07:00
|
|
|
| mod_longident DOT LBRACKET RBRACKET
|
|
|
|
{ mkexp(Pexp_open(Fresh, mkrhs $1 1,
|
|
|
|
mkexp(Pexp_construct(mkrhs (Lident "[]") 1, None)))) }
|
2014-02-04 08:55:20 -08:00
|
|
|
| mod_longident DOT LBRACKET expr_semi_list opt_semi error
|
|
|
|
{ unclosed "[" 3 "]" 6 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| PREFIXOP simple_expr
|
2014-12-22 00:45:55 -08:00
|
|
|
{ mkexp(Pexp_apply(mkoperator $1 1, [Nolabel,$2])) }
|
2010-04-07 20:58:41 -07:00
|
|
|
| BANG simple_expr
|
2014-12-22 00:45:55 -08:00
|
|
|
{ mkexp(Pexp_apply(mkoperator "!" 1, [Nolabel,$2])) }
|
2013-03-08 01:17:30 -08:00
|
|
|
| NEW ext_attributes class_longident
|
2013-03-08 00:42:53 -08:00
|
|
|
{ mkexp_attrs (Pexp_new(mkrhs $3 3)) $2 }
|
2014-11-16 09:52:26 -08:00
|
|
|
| LBRACELESS field_expr_list GREATERRBRACE
|
|
|
|
{ mkexp (Pexp_override $2) }
|
|
|
|
| LBRACELESS field_expr_list error
|
2016-03-08 02:24:30 -08:00
|
|
|
{ unclosed "{<" 1 ">}" 3 }
|
2013-03-22 04:25:52 -07:00
|
|
|
| LBRACELESS GREATERRBRACE
|
|
|
|
{ mkexp (Pexp_override [])}
|
2014-11-16 09:52:26 -08:00
|
|
|
| mod_longident DOT LBRACELESS field_expr_list GREATERRBRACE
|
|
|
|
{ mkexp(Pexp_open(Fresh, mkrhs $1 1, mkexp (Pexp_override $4)))}
|
2015-04-12 02:54:41 -07:00
|
|
|
| mod_longident DOT LBRACELESS GREATERRBRACE
|
|
|
|
{ mkexp(Pexp_open(Fresh, mkrhs $1 1, mkexp (Pexp_override [])))}
|
2014-11-16 09:52:26 -08:00
|
|
|
| mod_longident DOT LBRACELESS field_expr_list error
|
2016-03-08 02:24:30 -08:00
|
|
|
{ unclosed "{<" 3 ">}" 5 }
|
2016-05-03 08:39:45 -07:00
|
|
|
| simple_expr HASH label
|
1998-06-24 12:22:26 -07:00
|
|
|
{ mkexp(Pexp_send($1, $3)) }
|
2016-05-03 08:39:45 -07:00
|
|
|
| simple_expr HASHOP simple_expr
|
2015-03-09 10:39:50 -07:00
|
|
|
{ mkinfix $1 $2 $3 }
|
2016-02-02 07:38:07 -08:00
|
|
|
| LPAREN MODULE ext_attributes module_expr RPAREN
|
|
|
|
{ mkexp_attrs (Pexp_pack $4) $3 }
|
|
|
|
| LPAREN MODULE ext_attributes module_expr COLON package_type RPAREN
|
|
|
|
{ mkexp_attrs (Pexp_constraint (ghexp (Pexp_pack $4),
|
|
|
|
ghtyp (Ptyp_package $6)))
|
|
|
|
$3 }
|
|
|
|
| LPAREN MODULE ext_attributes module_expr COLON error
|
|
|
|
{ unclosed "(" 1 ")" 6 }
|
2016-02-16 04:23:31 -08:00
|
|
|
| mod_longident DOT LPAREN MODULE ext_attributes module_expr COLON
|
|
|
|
package_type RPAREN
|
2014-02-04 08:55:20 -08:00
|
|
|
{ mkexp(Pexp_open(Fresh, mkrhs $1 1,
|
2016-02-02 07:38:07 -08:00
|
|
|
mkexp_attrs (Pexp_constraint (ghexp (Pexp_pack $6),
|
|
|
|
ghtyp (Ptyp_package $8)))
|
|
|
|
$5 )) }
|
|
|
|
| mod_longident DOT LPAREN MODULE ext_attributes module_expr COLON error
|
2016-03-08 02:24:30 -08:00
|
|
|
{ unclosed "(" 3 ")" 8 }
|
2013-03-04 04:58:14 -08:00
|
|
|
| extension
|
|
|
|
{ mkexp (Pexp_extension $1) }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
1999-11-30 08:07:38 -08:00
|
|
|
simple_labeled_expr_list:
|
|
|
|
labeled_simple_expr
|
|
|
|
{ [$1] }
|
|
|
|
| simple_labeled_expr_list labeled_simple_expr
|
|
|
|
{ $2 :: $1 }
|
|
|
|
;
|
|
|
|
labeled_simple_expr:
|
2016-05-03 08:39:45 -07:00
|
|
|
simple_expr %prec below_HASH
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Nolabel, $1) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| label_expr
|
|
|
|
{ $1 }
|
|
|
|
;
|
|
|
|
label_expr:
|
2016-05-03 08:39:45 -07:00
|
|
|
LABEL simple_expr %prec below_HASH
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Labelled $1, $2) }
|
2000-04-11 20:43:25 -07:00
|
|
|
| TILDE label_ident
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Labelled (fst $2), snd $2) }
|
2000-04-11 20:43:25 -07:00
|
|
|
| QUESTION label_ident
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Optional (fst $2), snd $2) }
|
2016-05-03 08:39:45 -07:00
|
|
|
| OPTLABEL simple_expr %prec below_HASH
|
2014-12-22 00:45:55 -08:00
|
|
|
{ (Optional $1, $2) }
|
2000-04-11 20:43:25 -07:00
|
|
|
;
|
|
|
|
label_ident:
|
2012-05-30 07:52:37 -07:00
|
|
|
LIDENT { ($1, mkexp(Pexp_ident(mkrhs (Lident $1) 1))) }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
2010-10-17 21:54:24 -07:00
|
|
|
lident_list:
|
2011-11-24 01:02:48 -08:00
|
|
|
LIDENT { [$1] }
|
2010-10-17 21:54:24 -07:00
|
|
|
| LIDENT lident_list { $1 :: $2 }
|
2011-11-24 01:02:48 -08:00
|
|
|
;
|
2015-05-04 11:44:11 -07:00
|
|
|
let_binding_body:
|
2011-12-14 00:59:07 -08:00
|
|
|
val_ident fun_binding
|
|
|
|
{ (mkpatvar $1 1, $2) }
|
|
|
|
| val_ident COLON typevar_list DOT core_type EQUAL seq_expr
|
2013-03-09 14:38:52 -08:00
|
|
|
{ (ghpat(Ppat_constraint(mkpatvar $1 1,
|
|
|
|
ghtyp(Ptyp_poly(List.rev $3,$5)))),
|
|
|
|
$7) }
|
2011-12-14 00:59:07 -08:00
|
|
|
| val_ident COLON TYPE lident_list DOT core_type EQUAL seq_expr
|
2011-11-24 01:02:48 -08:00
|
|
|
{ let exp, poly = wrap_type_annotation $4 $6 $8 in
|
2011-12-14 00:59:07 -08:00
|
|
|
(ghpat(Ppat_constraint(mkpatvar $1 1, poly)), exp) }
|
2015-11-20 01:18:49 -08:00
|
|
|
| pattern_no_exn EQUAL seq_expr
|
1995-05-05 03:05:18 -07:00
|
|
|
{ ($1, $3) }
|
2013-12-16 09:34:23 -08:00
|
|
|
| simple_pattern_not_ident COLON core_type EQUAL seq_expr
|
|
|
|
{ (ghpat(Ppat_constraint($1, $3)), $5) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2015-05-04 11:44:11 -07:00
|
|
|
let_bindings:
|
|
|
|
let_binding { $1 }
|
|
|
|
| let_bindings and_let_binding { addlb $1 $2 }
|
|
|
|
;
|
|
|
|
let_binding:
|
|
|
|
LET ext_attributes rec_flag let_binding_body post_item_attributes
|
2016-02-02 05:52:03 -08:00
|
|
|
{ let (ext, attr) = $2 in
|
2016-04-28 07:00:18 -07:00
|
|
|
mklbs ext $3 (mklb true $4 (attr@$5)) }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
and_let_binding:
|
2016-02-02 05:52:03 -08:00
|
|
|
AND attributes let_binding_body post_item_attributes
|
2016-04-28 07:00:18 -07:00
|
|
|
{ mklb false $3 ($2@$4) }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
fun_binding:
|
2002-04-18 00:27:47 -07:00
|
|
|
strict_binding
|
|
|
|
{ $1 }
|
2002-02-05 09:11:33 -08:00
|
|
|
| type_constraint EQUAL seq_expr
|
2013-04-17 05:23:44 -07:00
|
|
|
{ mkexp_constraint $3 $1 }
|
2002-04-18 00:27:47 -07:00
|
|
|
;
|
|
|
|
strict_binding:
|
|
|
|
EQUAL seq_expr
|
|
|
|
{ $2 }
|
1999-11-30 08:07:38 -08:00
|
|
|
| labeled_simple_pattern fun_binding
|
2013-04-17 04:43:29 -07:00
|
|
|
{ let (l, o, p) = $1 in ghexp(Pexp_fun(l, o, p, $2)) }
|
2015-07-26 12:01:42 -07:00
|
|
|
| LPAREN TYPE lident_list RPAREN fun_binding
|
|
|
|
{ mk_newtypes $3 $5 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
match_cases:
|
2013-04-15 09:23:22 -07:00
|
|
|
match_case { [$1] }
|
|
|
|
| match_cases BAR match_case { $3 :: $1 }
|
|
|
|
;
|
|
|
|
match_case:
|
|
|
|
pattern MINUSGREATER seq_expr
|
|
|
|
{ Exp.case $1 $3 }
|
|
|
|
| pattern WHEN seq_expr MINUSGREATER seq_expr
|
|
|
|
{ Exp.case $1 ~guard:$3 $5 }
|
2015-10-15 17:13:40 -07:00
|
|
|
| pattern MINUSGREATER DOT
|
|
|
|
{ Exp.case $1 (Exp.unreachable ~loc:(rhs_loc 3) ())}
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
fun_def:
|
2016-02-16 04:23:31 -08:00
|
|
|
MINUSGREATER seq_expr
|
|
|
|
{ $2 }
|
|
|
|
| COLON simple_core_type MINUSGREATER seq_expr
|
|
|
|
{ mkexp (Pexp_constraint ($4, $2)) }
|
2013-04-15 09:23:22 -07:00
|
|
|
/* Cf #5939: we used to accept (fun p when e0 -> e) */
|
1999-11-30 08:07:38 -08:00
|
|
|
| labeled_simple_pattern fun_def
|
2013-04-15 09:23:22 -07:00
|
|
|
{
|
|
|
|
let (l,o,p) = $1 in
|
2013-04-17 04:43:29 -07:00
|
|
|
ghexp(Pexp_fun(l, o, p, $2))
|
2013-04-15 09:23:22 -07:00
|
|
|
}
|
2015-07-26 12:01:42 -07:00
|
|
|
| LPAREN TYPE lident_list RPAREN fun_def
|
|
|
|
{ mk_newtypes $3 $5 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
expr_comma_list:
|
|
|
|
expr_comma_list COMMA expr { $3 :: $1 }
|
|
|
|
| expr COMMA expr { [$3; $1] }
|
|
|
|
;
|
1998-04-27 08:17:11 -07:00
|
|
|
record_expr:
|
2012-06-21 10:00:46 -07:00
|
|
|
simple_expr WITH lbl_expr_list { (Some $1, $3) }
|
|
|
|
| lbl_expr_list { (None, $1) }
|
1998-04-27 08:17:11 -07:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
lbl_expr_list:
|
2012-06-21 10:00:46 -07:00
|
|
|
lbl_expr { [$1] }
|
|
|
|
| lbl_expr SEMI lbl_expr_list { $1 :: $3 }
|
|
|
|
| lbl_expr SEMI { [$1] }
|
|
|
|
;
|
|
|
|
lbl_expr:
|
2015-11-04 10:35:34 -08:00
|
|
|
label_longident opt_type_constraint EQUAL expr
|
|
|
|
{ (mkrhs $1 1, mkexp_opt_constraint $4 $2) }
|
|
|
|
| label_longident opt_type_constraint
|
|
|
|
{ (mkrhs $1 1, mkexp_opt_constraint (exp_of_label $1 1) $2) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
1998-04-27 08:17:11 -07:00
|
|
|
field_expr_list:
|
2014-11-16 09:52:26 -08:00
|
|
|
field_expr opt_semi { [$1] }
|
|
|
|
| field_expr SEMI field_expr_list { $1 :: $3 }
|
|
|
|
;
|
|
|
|
field_expr:
|
2002-02-05 09:11:33 -08:00
|
|
|
label EQUAL expr
|
2014-11-16 09:52:26 -08:00
|
|
|
{ (mkrhs $1 1, $3) }
|
|
|
|
| label
|
|
|
|
{ (mkrhs $1 1, exp_of_label (Lident $1) 1) }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
expr_semi_list:
|
2002-02-05 09:11:33 -08:00
|
|
|
expr { [$1] }
|
|
|
|
| expr_semi_list SEMI expr { $3 :: $1 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
1996-04-22 04:15:41 -07:00
|
|
|
type_constraint:
|
1997-05-13 11:28:25 -07:00
|
|
|
COLON core_type { (Some $2, None) }
|
|
|
|
| COLON core_type COLONGREATER core_type { (Some $2, Some $4) }
|
|
|
|
| COLONGREATER core_type { (None, Some $2) }
|
1997-11-12 04:32:53 -08:00
|
|
|
| COLON error { syntax_error() }
|
|
|
|
| COLONGREATER error { syntax_error() }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
2015-11-04 10:35:34 -08:00
|
|
|
opt_type_constraint:
|
|
|
|
type_constraint { Some $1 }
|
|
|
|
| /* empty */ { None }
|
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
/* Patterns */
|
|
|
|
|
|
|
|
pattern:
|
1995-09-11 01:09:22 -07:00
|
|
|
| pattern AS val_ident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkpat(Ppat_alias($1, mkrhs $3 3)) }
|
2012-10-16 07:04:33 -07:00
|
|
|
| pattern AS error
|
|
|
|
{ expecting 3 "identifier" }
|
2002-02-05 09:11:33 -08:00
|
|
|
| pattern_comma_list %prec below_COMMA
|
1995-09-11 01:09:22 -07:00
|
|
|
{ mkpat(Ppat_tuple(List.rev $1)) }
|
|
|
|
| pattern COLONCOLON pattern
|
2012-12-08 12:56:07 -08:00
|
|
|
{ mkpat_cons (rhs_loc 2) (ghpat(Ppat_tuple[$1;$3])) (symbol_rloc()) }
|
2012-10-16 07:04:33 -07:00
|
|
|
| pattern COLONCOLON error
|
|
|
|
{ expecting 3 "pattern" }
|
1995-09-11 01:09:22 -07:00
|
|
|
| pattern BAR pattern
|
|
|
|
{ mkpat(Ppat_or($1, $3)) }
|
2012-10-16 07:04:33 -07:00
|
|
|
| pattern BAR error
|
|
|
|
{ expecting 3 "pattern" }
|
2016-02-02 07:44:55 -08:00
|
|
|
| EXCEPTION ext_attributes pattern %prec prec_constr_appl
|
|
|
|
{ mkpat_attrs (Ppat_exception $3) $2}
|
2013-03-04 05:52:23 -08:00
|
|
|
| pattern attribute
|
2013-03-08 06:59:45 -08:00
|
|
|
{ Pat.attr $1 $2 }
|
2015-11-20 01:18:49 -08:00
|
|
|
| pattern_gen { $1 }
|
|
|
|
;
|
|
|
|
pattern_no_exn:
|
|
|
|
| pattern_no_exn AS val_ident
|
|
|
|
{ mkpat(Ppat_alias($1, mkrhs $3 3)) }
|
|
|
|
| pattern_no_exn AS error
|
|
|
|
{ expecting 3 "identifier" }
|
|
|
|
| pattern_no_exn_comma_list %prec below_COMMA
|
|
|
|
{ mkpat(Ppat_tuple(List.rev $1)) }
|
|
|
|
| pattern_no_exn COLONCOLON pattern
|
|
|
|
{ mkpat_cons (rhs_loc 2) (ghpat(Ppat_tuple[$1;$3])) (symbol_rloc()) }
|
|
|
|
| pattern_no_exn COLONCOLON error
|
|
|
|
{ expecting 3 "pattern" }
|
|
|
|
| pattern_no_exn BAR pattern
|
|
|
|
{ mkpat(Ppat_or($1, $3)) }
|
|
|
|
| pattern_no_exn BAR error
|
|
|
|
{ expecting 3 "pattern" }
|
|
|
|
| pattern_no_exn attribute
|
|
|
|
{ Pat.attr $1 $2 }
|
|
|
|
| pattern_gen { $1 }
|
|
|
|
;
|
|
|
|
pattern_gen:
|
|
|
|
simple_pattern
|
|
|
|
{ $1 }
|
|
|
|
| constr_longident pattern %prec prec_constr_appl
|
|
|
|
{ mkpat(Ppat_construct(mkrhs $1 1, Some $2)) }
|
|
|
|
| name_tag pattern %prec prec_constr_appl
|
|
|
|
{ mkpat(Ppat_variant($1, Some $2)) }
|
|
|
|
| LPAREN COLONCOLON RPAREN LPAREN pattern COMMA pattern RPAREN
|
|
|
|
{ mkpat_cons (rhs_loc 2) (ghpat(Ppat_tuple[$5;$7])) (symbol_rloc()) }
|
|
|
|
| LPAREN COLONCOLON RPAREN LPAREN pattern COMMA pattern error
|
|
|
|
{ unclosed "(" 4 ")" 8 }
|
|
|
|
| LAZY ext_attributes simple_pattern
|
|
|
|
{ mkpat_attrs (Ppat_lazy $3) $2}
|
1995-09-11 01:09:22 -07:00
|
|
|
;
|
|
|
|
simple_pattern:
|
2002-02-05 09:11:33 -08:00
|
|
|
val_ident %prec below_EQUAL
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkpat(Ppat_var (mkrhs $1 1)) }
|
2013-12-16 09:34:23 -08:00
|
|
|
| simple_pattern_not_ident { $1 }
|
|
|
|
;
|
|
|
|
simple_pattern_not_ident:
|
1995-05-04 03:15:53 -07:00
|
|
|
| UNDERSCORE
|
|
|
|
{ mkpat(Ppat_any) }
|
|
|
|
| signed_constant
|
|
|
|
{ mkpat(Ppat_constant $1) }
|
2013-04-16 08:34:09 -07:00
|
|
|
| signed_constant DOTDOT signed_constant
|
|
|
|
{ mkpat(Ppat_interval ($1, $3)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| constr_longident
|
2013-04-17 02:46:52 -07:00
|
|
|
{ mkpat(Ppat_construct(mkrhs $1 1, None)) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| name_tag
|
|
|
|
{ mkpat(Ppat_variant($1, None)) }
|
2016-05-03 08:39:45 -07:00
|
|
|
| HASH type_longident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mkpat(Ppat_type (mkrhs $2 2)) }
|
2016-05-05 10:50:56 -07:00
|
|
|
| simple_delimited_pattern
|
|
|
|
{ $1 }
|
|
|
|
| mod_longident DOT simple_delimited_pattern
|
|
|
|
{ mkpat @@ Ppat_open(mkrhs $1 1, $3) }
|
2016-05-31 14:22:35 -07:00
|
|
|
| mod_longident DOT LBRACKET RBRACKET
|
2016-06-03 00:44:36 -07:00
|
|
|
{ mkpat @@ Ppat_open(mkrhs $1 1, mkpat @@
|
|
|
|
Ppat_construct ( mkrhs (Lident "[]") 4, None)) }
|
2016-05-05 10:50:56 -07:00
|
|
|
| mod_longident DOT LPAREN RPAREN
|
|
|
|
{ mkpat @@ Ppat_open( mkrhs $1 1, mkpat @@
|
|
|
|
Ppat_construct ( mkrhs (Lident "()") 4, None) ) }
|
|
|
|
| mod_longident DOT LPAREN pattern RPAREN
|
|
|
|
{ mkpat @@ Ppat_open (mkrhs $1 1, $4)}
|
|
|
|
| mod_longident DOT LPAREN pattern error
|
|
|
|
{unclosed "(" 3 ")" 5 }
|
|
|
|
| mod_longident DOT LPAREN error
|
|
|
|
{ expecting 4 "pattern" }
|
1995-05-04 03:15:53 -07:00
|
|
|
| LPAREN pattern RPAREN
|
2003-04-06 05:45:03 -07:00
|
|
|
{ reloc_pat $2 }
|
1997-08-22 01:55:41 -07:00
|
|
|
| LPAREN pattern error
|
|
|
|
{ unclosed "(" 1 ")" 3 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| LPAREN pattern COLON core_type RPAREN
|
|
|
|
{ mkpat(Ppat_constraint($2, $4)) }
|
1997-08-22 01:55:41 -07:00
|
|
|
| LPAREN pattern COLON core_type error
|
|
|
|
{ unclosed "(" 1 ")" 5 }
|
2012-10-16 07:04:33 -07:00
|
|
|
| LPAREN pattern COLON error
|
|
|
|
{ expecting 4 "type" }
|
2016-02-02 07:44:55 -08:00
|
|
|
| LPAREN MODULE ext_attributes UIDENT RPAREN
|
|
|
|
{ mkpat_attrs (Ppat_unpack (mkrhs $4 4)) $3 }
|
|
|
|
| LPAREN MODULE ext_attributes UIDENT COLON package_type RPAREN
|
|
|
|
{ mkpat_attrs
|
|
|
|
(Ppat_constraint(mkpat(Ppat_unpack (mkrhs $4 4)),
|
|
|
|
ghtyp(Ptyp_package $6)))
|
|
|
|
$3 }
|
|
|
|
| LPAREN MODULE ext_attributes UIDENT COLON package_type error
|
|
|
|
{ unclosed "(" 1 ")" 7 }
|
2013-03-04 05:52:23 -08:00
|
|
|
| extension
|
|
|
|
{ mkpat(Ppat_extension $1) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2016-05-31 14:22:35 -07:00
|
|
|
|
2016-05-05 10:50:56 -07:00
|
|
|
simple_delimited_pattern:
|
|
|
|
| LBRACE lbl_pattern_list RBRACE
|
|
|
|
{ let (fields, closed) = $2 in mkpat(Ppat_record(fields, closed)) }
|
|
|
|
| LBRACE lbl_pattern_list error
|
|
|
|
{ unclosed "{" 1 "}" 3 }
|
|
|
|
| LBRACKET pattern_semi_list opt_semi RBRACKET
|
|
|
|
{ reloc_pat (mktailpat (rhs_loc 4) (List.rev $2)) }
|
|
|
|
| LBRACKET pattern_semi_list opt_semi error
|
|
|
|
{ unclosed "[" 1 "]" 4 }
|
|
|
|
| LBRACKETBAR pattern_semi_list opt_semi BARRBRACKET
|
|
|
|
{ mkpat(Ppat_array(List.rev $2)) }
|
|
|
|
| LBRACKETBAR BARRBRACKET
|
|
|
|
{ mkpat(Ppat_array []) }
|
|
|
|
| LBRACKETBAR pattern_semi_list opt_semi error
|
|
|
|
{ unclosed "[|" 1 "|]" 4 }
|
1995-09-11 01:09:22 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
pattern_comma_list:
|
|
|
|
pattern_comma_list COMMA pattern { $3 :: $1 }
|
|
|
|
| pattern COMMA pattern { [$3; $1] }
|
2012-10-16 07:04:33 -07:00
|
|
|
| pattern COMMA error { expecting 3 "pattern" }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2015-11-20 01:18:49 -08:00
|
|
|
pattern_no_exn_comma_list:
|
|
|
|
pattern_no_exn_comma_list COMMA pattern { $3 :: $1 }
|
|
|
|
| pattern_no_exn COMMA pattern { [$3; $1] }
|
|
|
|
| pattern_no_exn COMMA error { expecting 3 "pattern" }
|
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
pattern_semi_list:
|
|
|
|
pattern { [$1] }
|
|
|
|
| pattern_semi_list SEMI pattern { $3 :: $1 }
|
|
|
|
;
|
|
|
|
lbl_pattern_list:
|
2013-03-09 14:38:52 -08:00
|
|
|
lbl_pattern { [$1], Closed }
|
|
|
|
| lbl_pattern SEMI { [$1], Closed }
|
|
|
|
| lbl_pattern SEMI UNDERSCORE opt_semi { [$1], Open }
|
|
|
|
| lbl_pattern SEMI lbl_pattern_list
|
|
|
|
{ let (fields, closed) = $3 in $1 :: fields, closed }
|
2012-06-21 10:07:19 -07:00
|
|
|
;
|
|
|
|
lbl_pattern:
|
2015-11-04 10:35:34 -08:00
|
|
|
label_longident opt_pattern_type_constraint EQUAL pattern
|
|
|
|
{ (mkrhs $1 1, mkpat_opt_constraint $4 $2) }
|
|
|
|
| label_longident opt_pattern_type_constraint
|
|
|
|
{ (mkrhs $1 1, mkpat_opt_constraint (pat_of_label $1 1) $2) }
|
|
|
|
;
|
|
|
|
opt_pattern_type_constraint:
|
|
|
|
COLON core_type { Some $2 }
|
|
|
|
| /* empty */ { None }
|
2009-09-12 05:41:07 -07:00
|
|
|
;
|
2010-01-22 04:48:24 -08:00
|
|
|
|
2015-05-04 11:44:11 -07:00
|
|
|
/* Value descriptions */
|
|
|
|
|
|
|
|
value_description:
|
2015-12-02 07:23:47 -08:00
|
|
|
VAL ext_attributes val_ident COLON core_type post_item_attributes
|
|
|
|
{ let (ext, attrs) = $2 in
|
|
|
|
Val.mk (mkrhs $3 3) $5 ~attrs:(attrs@$6)
|
|
|
|
~loc:(symbol_rloc()) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
|
1995-07-25 04:38:42 -07:00
|
|
|
/* Primitive declarations */
|
|
|
|
|
2015-05-04 11:44:11 -07:00
|
|
|
primitive_declaration_body:
|
2013-05-23 08:12:04 -07:00
|
|
|
STRING { [fst $1] }
|
2015-05-04 11:44:11 -07:00
|
|
|
| STRING primitive_declaration_body { fst $1 :: $2 }
|
|
|
|
;
|
|
|
|
primitive_declaration:
|
2016-02-16 04:23:31 -08:00
|
|
|
EXTERNAL ext_attributes val_ident COLON core_type EQUAL
|
|
|
|
primitive_declaration_body post_item_attributes
|
2015-12-02 07:23:47 -08:00
|
|
|
{ let (ext, attrs) = $2 in
|
|
|
|
Val.mk (mkrhs $3 3) $5 ~prim:$7 ~attrs:(attrs@$8)
|
|
|
|
~loc:(symbol_rloc ()) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
1995-07-25 04:38:42 -07:00
|
|
|
;
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Type declarations */
|
|
|
|
|
|
|
|
type_declarations:
|
2015-05-04 11:44:11 -07:00
|
|
|
type_declaration
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (nonrec_flag, ty, ext) = $1 in (nonrec_flag, [ty], ext) }
|
2015-05-04 11:44:11 -07:00
|
|
|
| type_declarations and_type_declaration
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (nonrec_flag, tys, ext) = $1 in (nonrec_flag, $2 :: tys, ext) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2003-02-27 22:59:19 -08:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
type_declaration:
|
2016-02-16 04:23:31 -08:00
|
|
|
TYPE ext_attributes nonrec_flag optional_type_parameters LIDENT
|
|
|
|
type_kind constraints post_item_attributes
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (kind, priv, manifest) = $6 in
|
|
|
|
let (ext, attrs) = $2 in
|
2015-06-28 06:11:50 -07:00
|
|
|
let ty =
|
2015-12-02 08:57:54 -08:00
|
|
|
Type.mk (mkrhs $5 5) ~params:$4 ~cstrs:(List.rev $7) ~kind
|
|
|
|
~priv ?manifest ~attrs:(attrs@$8)
|
2015-06-28 06:11:50 -07:00
|
|
|
~loc:(symbol_rloc ()) ~docs:(symbol_docs ())
|
|
|
|
in
|
2015-12-02 08:57:54 -08:00
|
|
|
($3, ty, ext) }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
|
|
|
and_type_declaration:
|
2015-12-02 08:57:54 -08:00
|
|
|
AND attributes optional_type_parameters LIDENT type_kind constraints
|
2015-05-04 11:44:11 -07:00
|
|
|
post_item_attributes
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (kind, priv, manifest) = $5 in
|
|
|
|
Type.mk (mkrhs $4 4) ~params:$3 ~cstrs:(List.rev $6)
|
|
|
|
~kind ~priv ?manifest ~attrs:($2@$7) ~loc:(symbol_rloc ())
|
2015-06-28 06:11:50 -07:00
|
|
|
~text:(symbol_text ()) ~docs:(symbol_docs ()) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
1998-06-24 12:22:26 -07:00
|
|
|
constraints:
|
|
|
|
constraints CONSTRAINT constrain { $3 :: $1 }
|
|
|
|
| /* empty */ { [] }
|
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
type_kind:
|
|
|
|
/*empty*/
|
2007-10-09 03:29:37 -07:00
|
|
|
{ (Ptype_abstract, Public, None) }
|
2003-05-23 07:29:47 -07:00
|
|
|
| EQUAL core_type
|
2007-10-09 03:29:37 -07:00
|
|
|
{ (Ptype_abstract, Public, Some $2) }
|
2009-01-25 14:46:15 -08:00
|
|
|
| EQUAL PRIVATE core_type
|
|
|
|
{ (Ptype_abstract, Private, Some $3) }
|
2003-05-23 07:29:47 -07:00
|
|
|
| EQUAL constructor_declarations
|
2007-10-09 03:29:37 -07:00
|
|
|
{ (Ptype_variant(List.rev $2), Public, None) }
|
2003-05-23 07:29:47 -07:00
|
|
|
| EQUAL PRIVATE constructor_declarations
|
2007-10-09 03:29:37 -07:00
|
|
|
{ (Ptype_variant(List.rev $3), Private, None) }
|
2014-05-04 16:08:45 -07:00
|
|
|
| EQUAL DOTDOT
|
|
|
|
{ (Ptype_open, Public, None) }
|
2015-05-04 11:44:11 -07:00
|
|
|
| EQUAL private_flag LBRACE label_declarations RBRACE
|
|
|
|
{ (Ptype_record $4, $2, None) }
|
|
|
|
| EQUAL core_type EQUAL private_flag constructor_declarations
|
|
|
|
{ (Ptype_variant(List.rev $5), $4, Some $2) }
|
2014-05-04 16:08:45 -07:00
|
|
|
| EQUAL core_type EQUAL DOTDOT
|
|
|
|
{ (Ptype_open, Public, Some $2) }
|
2015-05-04 11:44:11 -07:00
|
|
|
| EQUAL core_type EQUAL private_flag LBRACE label_declarations RBRACE
|
|
|
|
{ (Ptype_record $6, $4, Some $2) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2010-09-20 22:30:25 -07:00
|
|
|
optional_type_parameters:
|
|
|
|
/*empty*/ { [] }
|
2014-05-04 16:08:45 -07:00
|
|
|
| optional_type_parameter { [$1] }
|
2010-09-20 22:30:25 -07:00
|
|
|
| LPAREN optional_type_parameter_list RPAREN { List.rev $2 }
|
|
|
|
;
|
|
|
|
optional_type_parameter:
|
2014-05-04 16:08:45 -07:00
|
|
|
type_variance optional_type_variable { $2, $1 }
|
2010-09-20 22:30:25 -07:00
|
|
|
;
|
|
|
|
optional_type_parameter_list:
|
|
|
|
optional_type_parameter { [$1] }
|
|
|
|
| optional_type_parameter_list COMMA optional_type_parameter { $3 :: $1 }
|
|
|
|
;
|
2014-05-04 16:08:45 -07:00
|
|
|
optional_type_variable:
|
|
|
|
QUOTE ident { mktyp(Ptyp_var $2) }
|
|
|
|
| UNDERSCORE { mktyp(Ptyp_any) }
|
|
|
|
;
|
2010-09-20 22:30:25 -07:00
|
|
|
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
type_parameters:
|
|
|
|
/*empty*/ { [] }
|
|
|
|
| type_parameter { [$1] }
|
|
|
|
| LPAREN type_parameter_list RPAREN { List.rev $2 }
|
|
|
|
;
|
|
|
|
type_parameter:
|
2014-05-04 16:08:45 -07:00
|
|
|
type_variance type_variable { $2, $1 }
|
2000-09-07 03:57:32 -07:00
|
|
|
;
|
|
|
|
type_variance:
|
2013-04-02 08:33:35 -07:00
|
|
|
/* empty */ { Invariant }
|
|
|
|
| PLUS { Covariant }
|
|
|
|
| MINUS { Contravariant }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2014-05-04 16:08:45 -07:00
|
|
|
type_variable:
|
|
|
|
QUOTE ident { mktyp(Ptyp_var $2) }
|
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
type_parameter_list:
|
|
|
|
type_parameter { [$1] }
|
|
|
|
| type_parameter_list COMMA type_parameter { $3 :: $1 }
|
|
|
|
;
|
|
|
|
constructor_declarations:
|
2015-05-04 11:44:11 -07:00
|
|
|
constructor_declaration { [$1] }
|
|
|
|
| bar_constructor_declaration { [$1] }
|
|
|
|
| constructor_declarations bar_constructor_declaration { $2 :: $1 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
constructor_declaration:
|
2015-03-11 07:57:20 -07:00
|
|
|
| constr_ident generalized_constructor_arguments attributes
|
2013-03-08 06:59:45 -08:00
|
|
|
{
|
2015-03-11 07:57:20 -07:00
|
|
|
let args,res = $2 in
|
2015-06-28 06:11:50 -07:00
|
|
|
Type.constructor (mkrhs $1 1) ~args ?res ~attrs:$3
|
|
|
|
~loc:(symbol_rloc()) ~info:(symbol_info ())
|
2013-03-08 06:59:45 -08:00
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2015-05-04 11:44:11 -07:00
|
|
|
bar_constructor_declaration:
|
|
|
|
| BAR constr_ident generalized_constructor_arguments attributes
|
2014-05-04 16:08:45 -07:00
|
|
|
{
|
2015-05-04 11:44:11 -07:00
|
|
|
let args,res = $3 in
|
2015-06-28 06:11:50 -07:00
|
|
|
Type.constructor (mkrhs $2 2) ~args ?res ~attrs:$4
|
|
|
|
~loc:(symbol_rloc()) ~info:(symbol_info ())
|
2014-05-04 16:08:45 -07:00
|
|
|
}
|
|
|
|
;
|
2015-05-04 11:44:11 -07:00
|
|
|
str_exception_declaration:
|
|
|
|
| sig_exception_declaration { $1 }
|
2015-12-02 08:57:54 -08:00
|
|
|
| EXCEPTION ext_attributes constr_ident EQUAL constr_longident attributes
|
2015-05-04 11:44:11 -07:00
|
|
|
post_item_attributes
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (ext,attrs) = $2 in
|
2016-03-07 18:41:35 -08:00
|
|
|
Te.rebind (mkrhs $3 3) (mkrhs $5 5) ~attrs:(attrs @ $6 @ $7)
|
2015-12-02 08:57:54 -08:00
|
|
|
~loc:(symbol_rloc()) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
2014-05-04 16:08:45 -07:00
|
|
|
sig_exception_declaration:
|
2016-02-16 04:23:31 -08:00
|
|
|
| EXCEPTION ext_attributes constr_ident generalized_constructor_arguments
|
|
|
|
attributes post_item_attributes
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let args, res = $4 in
|
|
|
|
let (ext,attrs) = $2 in
|
2016-03-07 18:41:35 -08:00
|
|
|
Te.decl (mkrhs $3 3) ~args ?res ~attrs:(attrs @ $5 @ $6)
|
2015-12-02 08:57:54 -08:00
|
|
|
~loc:(symbol_rloc()) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2016-06-29 19:00:06 -07:00
|
|
|
let_exception_declaration:
|
|
|
|
constr_ident generalized_constructor_arguments attributes
|
|
|
|
{ let args, res = $2 in
|
|
|
|
Te.decl (mkrhs $1 1) ~args ?res ~attrs:$3 ~loc:(symbol_rloc()) }
|
|
|
|
;
|
2010-09-12 22:28:30 -07:00
|
|
|
generalized_constructor_arguments:
|
2014-03-28 10:08:53 -07:00
|
|
|
/*empty*/ { (Pcstr_tuple [],None) }
|
|
|
|
| OF constructor_arguments { ($2,None) }
|
2015-07-17 04:51:17 -07:00
|
|
|
| COLON constructor_arguments MINUSGREATER simple_core_type
|
2014-03-28 10:08:53 -07:00
|
|
|
{ ($2,Some $4) }
|
2015-07-17 04:51:17 -07:00
|
|
|
| COLON simple_core_type
|
2014-03-28 10:08:53 -07:00
|
|
|
{ (Pcstr_tuple [],Some $2) }
|
2010-09-12 22:28:30 -07:00
|
|
|
;
|
|
|
|
|
2014-03-28 10:08:53 -07:00
|
|
|
constructor_arguments:
|
2015-07-17 04:51:17 -07:00
|
|
|
| core_type_list { Pcstr_tuple (List.rev $1) }
|
2015-05-04 12:46:51 -07:00
|
|
|
| LBRACE label_declarations RBRACE { Pcstr_record $2 }
|
2014-03-28 10:08:53 -07:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
label_declarations:
|
|
|
|
label_declaration { [$1] }
|
2015-05-04 11:44:11 -07:00
|
|
|
| label_declaration_semi { [$1] }
|
|
|
|
| label_declaration_semi label_declarations { $1 :: $2 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
label_declaration:
|
2015-03-11 07:57:20 -07:00
|
|
|
mutable_flag label COLON poly_type_no_attr attributes
|
2013-03-06 05:51:18 -08:00
|
|
|
{
|
2015-06-28 06:11:50 -07:00
|
|
|
Type.field (mkrhs $2 2) $4 ~mut:$1 ~attrs:$5
|
|
|
|
~loc:(symbol_rloc()) ~info:(symbol_info ())
|
2013-03-06 05:51:18 -08:00
|
|
|
}
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2015-05-04 11:44:11 -07:00
|
|
|
label_declaration_semi:
|
2015-06-28 06:11:50 -07:00
|
|
|
mutable_flag label COLON poly_type_no_attr attributes SEMI attributes
|
2015-05-04 11:44:11 -07:00
|
|
|
{
|
2015-06-28 06:11:50 -07:00
|
|
|
let info =
|
|
|
|
match rhs_info 5 with
|
|
|
|
| Some _ as info_before_semi -> info_before_semi
|
|
|
|
| None -> symbol_info ()
|
|
|
|
in
|
|
|
|
Type.field (mkrhs $2 2) $4 ~mut:$1 ~attrs:($5 @ $7)
|
|
|
|
~loc:(symbol_rloc()) ~info
|
2015-05-04 11:44:11 -07:00
|
|
|
}
|
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2014-05-04 16:08:45 -07:00
|
|
|
/* Type Extensions */
|
|
|
|
|
|
|
|
str_type_extension:
|
2015-12-02 08:57:54 -08:00
|
|
|
TYPE ext_attributes nonrec_flag optional_type_parameters type_longident
|
2015-05-04 11:44:11 -07:00
|
|
|
PLUSEQ private_flag str_extension_constructors post_item_attributes
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (ext, attrs) = $2 in
|
|
|
|
if $3 <> Recursive then not_expecting 3 "nonrec flag";
|
|
|
|
Te.mk (mkrhs $5 5) (List.rev $8) ~params:$4 ~priv:$7
|
|
|
|
~attrs:(attrs@$9) ~docs:(symbol_docs ())
|
|
|
|
, ext }
|
2014-05-04 16:08:45 -07:00
|
|
|
;
|
|
|
|
sig_type_extension:
|
2015-12-02 08:57:54 -08:00
|
|
|
TYPE ext_attributes nonrec_flag optional_type_parameters type_longident
|
2015-05-04 11:44:11 -07:00
|
|
|
PLUSEQ private_flag sig_extension_constructors post_item_attributes
|
2015-12-02 08:57:54 -08:00
|
|
|
{ let (ext, attrs) = $2 in
|
2016-03-07 19:18:07 -08:00
|
|
|
if $3 <> Recursive then not_expecting 3 "nonrec flag";
|
2015-12-02 08:57:54 -08:00
|
|
|
Te.mk (mkrhs $5 5) (List.rev $8) ~params:$4 ~priv:$7
|
2016-03-07 18:41:35 -08:00
|
|
|
~attrs:(attrs @ $9) ~docs:(symbol_docs ())
|
2015-12-02 08:57:54 -08:00
|
|
|
, ext }
|
2014-05-04 16:08:45 -07:00
|
|
|
;
|
|
|
|
str_extension_constructors:
|
|
|
|
extension_constructor_declaration { [$1] }
|
2015-05-04 11:44:11 -07:00
|
|
|
| bar_extension_constructor_declaration { [$1] }
|
2014-05-04 16:08:45 -07:00
|
|
|
| extension_constructor_rebind { [$1] }
|
2015-05-04 11:44:11 -07:00
|
|
|
| bar_extension_constructor_rebind { [$1] }
|
|
|
|
| str_extension_constructors bar_extension_constructor_declaration
|
|
|
|
{ $2 :: $1 }
|
|
|
|
| str_extension_constructors bar_extension_constructor_rebind
|
|
|
|
{ $2 :: $1 }
|
2014-05-04 16:08:45 -07:00
|
|
|
;
|
|
|
|
sig_extension_constructors:
|
|
|
|
extension_constructor_declaration { [$1] }
|
2015-05-04 11:44:11 -07:00
|
|
|
| bar_extension_constructor_declaration { [$1] }
|
|
|
|
| sig_extension_constructors bar_extension_constructor_declaration
|
|
|
|
{ $2 :: $1 }
|
2014-05-04 16:08:45 -07:00
|
|
|
;
|
|
|
|
extension_constructor_declaration:
|
2015-03-11 07:57:20 -07:00
|
|
|
| constr_ident generalized_constructor_arguments attributes
|
|
|
|
{ let args, res = $2 in
|
2015-06-28 06:11:50 -07:00
|
|
|
Te.decl (mkrhs $1 1) ~args ?res ~attrs:$3
|
|
|
|
~loc:(symbol_rloc()) ~info:(symbol_info ()) }
|
2014-05-04 16:08:45 -07:00
|
|
|
;
|
2015-05-04 11:44:11 -07:00
|
|
|
bar_extension_constructor_declaration:
|
|
|
|
| BAR constr_ident generalized_constructor_arguments attributes
|
|
|
|
{ let args, res = $3 in
|
2015-06-28 06:11:50 -07:00
|
|
|
Te.decl (mkrhs $2 2) ~args ?res ~attrs:$4
|
|
|
|
~loc:(symbol_rloc()) ~info:(symbol_info ()) }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
2014-05-04 16:08:45 -07:00
|
|
|
extension_constructor_rebind:
|
2015-03-11 07:57:20 -07:00
|
|
|
| constr_ident EQUAL constr_longident attributes
|
2015-06-28 06:11:50 -07:00
|
|
|
{ Te.rebind (mkrhs $1 1) (mkrhs $3 3) ~attrs:$4
|
|
|
|
~loc:(symbol_rloc()) ~info:(symbol_info ()) }
|
2014-05-04 16:08:45 -07:00
|
|
|
;
|
2015-05-04 11:44:11 -07:00
|
|
|
bar_extension_constructor_rebind:
|
|
|
|
| BAR constr_ident EQUAL constr_longident attributes
|
2015-06-28 06:11:50 -07:00
|
|
|
{ Te.rebind (mkrhs $2 2) (mkrhs $4 4) ~attrs:$5
|
|
|
|
~loc:(symbol_rloc()) ~info:(symbol_info ()) }
|
2015-05-04 11:44:11 -07:00
|
|
|
;
|
2014-05-04 16:08:45 -07:00
|
|
|
|
1995-09-28 03:41:50 -07:00
|
|
|
/* "with" constraints (additional type equations over signature components) */
|
|
|
|
|
|
|
|
with_constraints:
|
|
|
|
with_constraint { [$1] }
|
|
|
|
| with_constraints AND with_constraint { $3 :: $1 }
|
|
|
|
;
|
|
|
|
with_constraint:
|
2015-09-11 04:58:31 -07:00
|
|
|
TYPE type_parameters label_longident with_type_binder core_type_no_attr
|
|
|
|
constraints
|
2013-04-16 03:47:45 -07:00
|
|
|
{ Pwith_type
|
|
|
|
(mkrhs $3 3,
|
2013-03-08 06:59:45 -08:00
|
|
|
(Type.mk (mkrhs (Longident.last $3) 3)
|
2014-05-04 16:08:45 -07:00
|
|
|
~params:$2
|
2013-03-08 06:59:45 -08:00
|
|
|
~cstrs:(List.rev $6)
|
|
|
|
~manifest:$5
|
|
|
|
~priv:$4
|
|
|
|
~loc:(symbol_rloc()))) }
|
1995-09-28 03:41:50 -07:00
|
|
|
/* used label_longident instead of type_longident to disallow
|
|
|
|
functor applications in type path */
|
2015-03-11 07:57:20 -07:00
|
|
|
| TYPE type_parameters label COLONEQUAL core_type_no_attr
|
2013-04-16 03:47:45 -07:00
|
|
|
{ Pwith_typesubst
|
|
|
|
(Type.mk (mkrhs $3 3)
|
2014-05-04 16:08:45 -07:00
|
|
|
~params:$2
|
2013-04-16 03:47:45 -07:00
|
|
|
~manifest:$5
|
|
|
|
~loc:(symbol_rloc())) }
|
1995-10-01 06:39:43 -07:00
|
|
|
| MODULE mod_longident EQUAL mod_ext_longident
|
2013-04-16 03:47:45 -07:00
|
|
|
{ Pwith_module (mkrhs $2 2, mkrhs $4 4) }
|
2013-01-28 16:54:06 -08:00
|
|
|
| MODULE UIDENT COLONEQUAL mod_ext_longident
|
2013-04-16 03:47:45 -07:00
|
|
|
{ Pwith_modsubst (mkrhs $2 2, mkrhs $4 4) }
|
1995-09-28 03:41:50 -07:00
|
|
|
;
|
2005-03-22 19:08:37 -08:00
|
|
|
with_type_binder:
|
2007-10-09 03:29:37 -07:00
|
|
|
EQUAL { Public }
|
|
|
|
| EQUAL PRIVATE { Private }
|
2005-03-22 19:08:37 -08:00
|
|
|
;
|
1995-09-28 03:41:50 -07:00
|
|
|
|
2002-04-18 00:27:47 -07:00
|
|
|
/* Polymorphic types */
|
|
|
|
|
|
|
|
typevar_list:
|
2002-07-23 07:12:03 -07:00
|
|
|
QUOTE ident { [$2] }
|
|
|
|
| typevar_list QUOTE ident { $3 :: $1 }
|
2002-04-18 00:27:47 -07:00
|
|
|
;
|
|
|
|
poly_type:
|
2002-07-23 07:12:03 -07:00
|
|
|
core_type
|
2013-04-09 07:10:54 -07:00
|
|
|
{ $1 }
|
2002-07-23 07:12:03 -07:00
|
|
|
| typevar_list DOT core_type
|
|
|
|
{ mktyp(Ptyp_poly(List.rev $1, $3)) }
|
2002-04-18 00:27:47 -07:00
|
|
|
;
|
2015-03-11 07:57:20 -07:00
|
|
|
poly_type_no_attr:
|
|
|
|
core_type_no_attr
|
|
|
|
{ $1 }
|
|
|
|
| typevar_list DOT core_type_no_attr
|
|
|
|
{ mktyp(Ptyp_poly(List.rev $1, $3)) }
|
|
|
|
;
|
2002-04-18 00:27:47 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Core types */
|
|
|
|
|
|
|
|
core_type:
|
2015-03-11 07:57:20 -07:00
|
|
|
core_type_no_attr
|
|
|
|
{ $1 }
|
|
|
|
| core_type attribute
|
|
|
|
{ Typ.attr $1 $2 }
|
|
|
|
;
|
|
|
|
core_type_no_attr:
|
2015-10-25 09:24:47 -07:00
|
|
|
core_type2 %prec MINUSGREATER
|
1995-05-04 03:15:53 -07:00
|
|
|
{ $1 }
|
2000-09-07 03:57:32 -07:00
|
|
|
| core_type2 AS QUOTE ident
|
|
|
|
{ mktyp(Ptyp_alias($1, $4)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
1999-11-30 08:07:38 -08:00
|
|
|
core_type2:
|
|
|
|
simple_core_type_or_tuple
|
|
|
|
{ $1 }
|
2001-09-25 02:54:18 -07:00
|
|
|
| QUESTION LIDENT COLON core_type2 MINUSGREATER core_type2
|
2016-03-03 05:18:33 -08:00
|
|
|
{ let param = extra_rhs_core_type $4 ~pos:4 in
|
|
|
|
mktyp (Ptyp_arrow(Optional $2 , param, $6)) }
|
2002-02-01 04:26:09 -08:00
|
|
|
| OPTLABEL core_type2 MINUSGREATER core_type2
|
2016-03-03 05:18:33 -08:00
|
|
|
{ let param = extra_rhs_core_type $2 ~pos:2 in
|
|
|
|
mktyp(Ptyp_arrow(Optional $1 , param, $4))
|
|
|
|
}
|
2002-02-01 04:26:09 -08:00
|
|
|
| LIDENT COLON core_type2 MINUSGREATER core_type2
|
2016-03-03 05:18:33 -08:00
|
|
|
{ let param = extra_rhs_core_type $3 ~pos:3 in
|
|
|
|
mktyp(Ptyp_arrow(Labelled $1, param, $5)) }
|
2002-02-01 04:26:09 -08:00
|
|
|
| core_type2 MINUSGREATER core_type2
|
2016-03-03 05:18:33 -08:00
|
|
|
{ let param = extra_rhs_core_type $1 ~pos:1 in
|
|
|
|
mktyp(Ptyp_arrow(Nolabel, param, $3)) }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
1996-04-22 04:15:41 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
simple_core_type:
|
2016-05-03 08:39:45 -07:00
|
|
|
simple_core_type2 %prec below_HASH
|
2001-09-25 02:54:18 -07:00
|
|
|
{ $1 }
|
2016-05-03 08:39:45 -07:00
|
|
|
| LPAREN core_type_comma_list RPAREN %prec below_HASH
|
2001-09-25 02:54:18 -07:00
|
|
|
{ match $2 with [sty] -> sty | _ -> raise Parse_error }
|
|
|
|
;
|
2013-03-04 04:54:57 -08:00
|
|
|
|
2001-09-25 02:54:18 -07:00
|
|
|
simple_core_type2:
|
1995-05-04 03:15:53 -07:00
|
|
|
QUOTE ident
|
|
|
|
{ mktyp(Ptyp_var $2) }
|
1997-02-11 10:24:47 -08:00
|
|
|
| UNDERSCORE
|
|
|
|
{ mktyp(Ptyp_any) }
|
1997-03-07 14:26:29 -08:00
|
|
|
| type_longident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mktyp(Ptyp_constr(mkrhs $1 1, [])) }
|
2002-02-05 09:11:33 -08:00
|
|
|
| simple_core_type2 type_longident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mktyp(Ptyp_constr(mkrhs $2 2, [$1])) }
|
2002-02-05 09:11:33 -08:00
|
|
|
| LPAREN core_type_comma_list RPAREN type_longident
|
2012-05-30 07:52:37 -07:00
|
|
|
{ mktyp(Ptyp_constr(mkrhs $4 4, List.rev $2)) }
|
1997-03-07 14:26:29 -08:00
|
|
|
| LESS meth_list GREATER
|
2013-04-09 06:29:00 -07:00
|
|
|
{ let (f, c) = $2 in mktyp(Ptyp_object (f, c)) }
|
1997-03-07 14:26:29 -08:00
|
|
|
| LESS GREATER
|
2013-04-09 06:29:00 -07:00
|
|
|
{ mktyp(Ptyp_object ([], Closed)) }
|
2016-05-03 08:39:45 -07:00
|
|
|
| HASH class_longident
|
2013-04-16 05:17:17 -07:00
|
|
|
{ mktyp(Ptyp_class(mkrhs $2 2, [])) }
|
2016-05-03 08:39:45 -07:00
|
|
|
| simple_core_type2 HASH class_longident
|
2013-04-16 05:17:17 -07:00
|
|
|
{ mktyp(Ptyp_class(mkrhs $3 3, [$1])) }
|
2016-05-03 08:39:45 -07:00
|
|
|
| LPAREN core_type_comma_list RPAREN HASH class_longident
|
2013-04-16 05:17:17 -07:00
|
|
|
{ mktyp(Ptyp_class(mkrhs $5 5, List.rev $2)) }
|
2001-09-25 02:54:18 -07:00
|
|
|
| LBRACKET tag_field RBRACKET
|
2013-04-12 09:08:52 -07:00
|
|
|
{ mktyp(Ptyp_variant([$2], Closed, None)) }
|
2006-04-16 16:28:22 -07:00
|
|
|
/* PR#3835: this is not LR(1), would need lookahead=2
|
2013-03-18 13:17:14 -07:00
|
|
|
| LBRACKET simple_core_type RBRACKET
|
2013-04-12 09:08:52 -07:00
|
|
|
{ mktyp(Ptyp_variant([$2], Closed, None)) }
|
2006-04-16 16:28:22 -07:00
|
|
|
*/
|
2001-09-25 02:54:18 -07:00
|
|
|
| LBRACKET BAR row_field_list RBRACKET
|
2013-04-12 09:08:52 -07:00
|
|
|
{ mktyp(Ptyp_variant(List.rev $3, Closed, None)) }
|
2001-09-25 02:54:18 -07:00
|
|
|
| LBRACKET row_field BAR row_field_list RBRACKET
|
2013-04-12 09:08:52 -07:00
|
|
|
{ mktyp(Ptyp_variant($2 :: List.rev $4, Closed, None)) }
|
2003-12-18 05:16:22 -08:00
|
|
|
| LBRACKETGREATER opt_bar row_field_list RBRACKET
|
2013-04-12 09:08:52 -07:00
|
|
|
{ mktyp(Ptyp_variant(List.rev $3, Open, None)) }
|
2003-12-18 05:16:22 -08:00
|
|
|
| LBRACKETGREATER RBRACKET
|
2013-04-12 09:08:52 -07:00
|
|
|
{ mktyp(Ptyp_variant([], Open, None)) }
|
2000-06-11 07:34:10 -07:00
|
|
|
| LBRACKETLESS opt_bar row_field_list RBRACKET
|
2013-04-12 09:08:52 -07:00
|
|
|
{ mktyp(Ptyp_variant(List.rev $3, Closed, Some [])) }
|
2000-06-11 07:34:10 -07:00
|
|
|
| LBRACKETLESS opt_bar row_field_list GREATER name_tag_list RBRACKET
|
2013-04-12 09:08:52 -07:00
|
|
|
{ mktyp(Ptyp_variant(List.rev $3, Closed, Some (List.rev $5))) }
|
2016-02-02 07:38:07 -08:00
|
|
|
| LPAREN MODULE ext_attributes package_type RPAREN
|
|
|
|
{ mktyp_attrs (Ptyp_package $4) $3 }
|
2013-03-04 04:58:14 -08:00
|
|
|
| extension
|
|
|
|
{ mktyp (Ptyp_extension $1) }
|
2013-03-01 04:44:04 -08:00
|
|
|
;
|
2009-10-26 03:53:16 -07:00
|
|
|
package_type:
|
2016-01-05 04:10:25 -08:00
|
|
|
module_type { package_type_of_module_type $1 }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
|
|
|
row_field_list:
|
2000-01-07 08:35:15 -08:00
|
|
|
row_field { [$1] }
|
|
|
|
| row_field_list BAR row_field { $3 :: $1 }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
|
|
|
row_field:
|
2001-09-25 02:54:18 -07:00
|
|
|
tag_field { $1 }
|
2013-03-18 13:17:14 -07:00
|
|
|
| simple_core_type { Rinherit $1 }
|
2001-09-25 02:54:18 -07:00
|
|
|
;
|
|
|
|
tag_field:
|
2015-03-11 07:57:20 -07:00
|
|
|
name_tag OF opt_ampersand amper_type_list attributes
|
2016-03-03 05:18:33 -08:00
|
|
|
{ Rtag ($1, add_info_attrs (symbol_info ()) $5, $3, List.rev $4) }
|
2014-04-30 01:19:55 -07:00
|
|
|
| name_tag attributes
|
2016-03-03 05:18:33 -08:00
|
|
|
{ Rtag ($1, add_info_attrs (symbol_info ()) $2, true, []) }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
|
|
|
opt_ampersand:
|
2000-01-07 08:35:15 -08:00
|
|
|
AMPERSAND { true }
|
|
|
|
| /* empty */ { false }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
|
|
|
amper_type_list:
|
2015-03-11 07:57:20 -07:00
|
|
|
core_type_no_attr { [$1] }
|
|
|
|
| amper_type_list AMPERSAND core_type_no_attr { $3 :: $1 }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
|
|
|
name_tag_list:
|
2000-01-07 08:35:15 -08:00
|
|
|
name_tag { [$1] }
|
|
|
|
| name_tag_list name_tag { $2 :: $1 }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
1999-11-30 08:07:38 -08:00
|
|
|
simple_core_type_or_tuple:
|
2015-07-17 04:51:17 -07:00
|
|
|
simple_core_type { $1 }
|
2001-09-25 02:54:18 -07:00
|
|
|
| simple_core_type STAR core_type_list
|
|
|
|
{ mktyp(Ptyp_tuple($1 :: List.rev $3)) }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
core_type_comma_list:
|
2001-09-25 02:54:18 -07:00
|
|
|
core_type { [$1] }
|
1995-05-04 03:15:53 -07:00
|
|
|
| core_type_comma_list COMMA core_type { $3 :: $1 }
|
|
|
|
;
|
|
|
|
core_type_list:
|
2015-07-17 04:51:17 -07:00
|
|
|
simple_core_type { [$1] }
|
1995-05-04 03:15:53 -07:00
|
|
|
| core_type_list STAR simple_core_type { $3 :: $1 }
|
|
|
|
;
|
1996-04-22 04:15:41 -07:00
|
|
|
meth_list:
|
2016-03-03 05:18:33 -08:00
|
|
|
field_semi meth_list { let (f, c) = $2 in ($1 :: f, c) }
|
|
|
|
| field_semi { [$1], Closed }
|
|
|
|
| field { [$1], Closed }
|
2013-04-09 06:29:00 -07:00
|
|
|
| DOTDOT { [], Open }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
|
|
|
field:
|
2016-03-03 05:18:33 -08:00
|
|
|
label COLON poly_type_no_attr attributes
|
|
|
|
{ ($1, add_info_attrs (symbol_info ()) $4, $3) }
|
|
|
|
;
|
|
|
|
|
|
|
|
field_semi:
|
|
|
|
label COLON poly_type_no_attr attributes SEMI attributes
|
|
|
|
{ let info =
|
|
|
|
match rhs_info 4 with
|
|
|
|
| Some _ as info_before_semi -> info_before_semi
|
|
|
|
| None -> symbol_info ()
|
|
|
|
in
|
|
|
|
($1, add_info_attrs info ($4 @ $6), $3) }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
2016-03-03 05:18:33 -08:00
|
|
|
|
1996-04-22 04:15:41 -07:00
|
|
|
label:
|
1997-05-13 07:45:28 -07:00
|
|
|
LIDENT { $1 }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
/* Constants */
|
|
|
|
|
|
|
|
constant:
|
2016-02-16 04:23:31 -08:00
|
|
|
| INT { let (n, m) = $1 in Pconst_integer (n, m) }
|
|
|
|
| CHAR { Pconst_char $1 }
|
|
|
|
| STRING { let (s, d) = $1 in Pconst_string (s, d) }
|
|
|
|
| FLOAT { let (f, m) = $1 in Pconst_float (f, m) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
signed_constant:
|
2016-02-16 04:23:31 -08:00
|
|
|
constant { $1 }
|
|
|
|
| MINUS INT { let (n, m) = $2 in Pconst_integer("-" ^ n, m) }
|
|
|
|
| MINUS FLOAT { let (f, m) = $2 in Pconst_float("-" ^ f, m) }
|
|
|
|
| PLUS INT { let (n, m) = $2 in Pconst_integer (n, m) }
|
|
|
|
| PLUS FLOAT { let (f, m) = $2 in Pconst_float(f, m) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
2009-12-01 01:57:02 -08:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Identifiers and long identifiers */
|
|
|
|
|
|
|
|
ident:
|
|
|
|
UIDENT { $1 }
|
|
|
|
| LIDENT { $1 }
|
|
|
|
;
|
|
|
|
val_ident:
|
|
|
|
LIDENT { $1 }
|
|
|
|
| LPAREN operator RPAREN { $2 }
|
2012-10-16 07:04:33 -07:00
|
|
|
| LPAREN operator error { unclosed "(" 1 ")" 3 }
|
|
|
|
| LPAREN error { expecting 2 "operator" }
|
2013-03-22 11:02:34 -07:00
|
|
|
| LPAREN MODULE error { expecting 3 "module-expr" }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
operator:
|
|
|
|
PREFIXOP { $1 }
|
1996-04-30 07:53:58 -07:00
|
|
|
| INFIXOP0 { $1 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| INFIXOP1 { $1 }
|
|
|
|
| INFIXOP2 { $1 }
|
|
|
|
| INFIXOP3 { $1 }
|
|
|
|
| INFIXOP4 { $1 }
|
2016-05-03 08:39:45 -07:00
|
|
|
| HASHOP { $1 }
|
2010-04-07 20:58:41 -07:00
|
|
|
| BANG { "!" }
|
2000-09-07 03:57:32 -07:00
|
|
|
| PLUS { "+" }
|
2009-12-07 08:40:39 -08:00
|
|
|
| PLUSDOT { "+." }
|
2000-09-07 03:57:32 -07:00
|
|
|
| MINUS { "-" }
|
|
|
|
| MINUSDOT { "-." }
|
1995-05-04 03:15:53 -07:00
|
|
|
| STAR { "*" }
|
|
|
|
| EQUAL { "=" }
|
1996-04-30 07:53:58 -07:00
|
|
|
| LESS { "<" }
|
|
|
|
| GREATER { ">" }
|
1995-05-04 03:15:53 -07:00
|
|
|
| OR { "or" }
|
1995-12-15 02:20:24 -08:00
|
|
|
| BARBAR { "||" }
|
1995-05-04 03:15:53 -07:00
|
|
|
| AMPERSAND { "&" }
|
1995-12-15 02:20:24 -08:00
|
|
|
| AMPERAMPER { "&&" }
|
1995-05-04 03:15:53 -07:00
|
|
|
| COLONEQUAL { ":=" }
|
2014-05-04 16:08:45 -07:00
|
|
|
| PLUSEQ { "+=" }
|
2013-03-08 01:17:30 -08:00
|
|
|
| PERCENT { "%" }
|
Add a special syntax for index operators
This commit introduces a new syntax for index operators.
Six core parenthesis operator are added:
.(), .[], .{}, .{,}, .{,,}, .{,..,}.
The .{,}/.{,,}/.{,,,} operators are defined for compatibility with the Bigarray syntax extension.
Each core index operator is available in a access/assignement versions. For instance, .() is declined in
* .() : index operator
* .()<- : indexed assignment operator
The general syntax for these index operators as implemented in the parser is index_operator::= index_operator_core [<-]
From: octachron <octa@polychoron.fr>
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15660 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-12-13 14:13:32 -08:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
constr_ident:
|
|
|
|
UIDENT { $1 }
|
2015-08-28 20:42:50 -07:00
|
|
|
| LBRACKET RBRACKET { "[]" }
|
1995-05-04 03:15:53 -07:00
|
|
|
| LPAREN RPAREN { "()" }
|
2015-10-08 13:37:25 -07:00
|
|
|
/* | COLONCOLON { "::" } */
|
2015-09-24 08:34:41 -07:00
|
|
|
| LPAREN COLONCOLON RPAREN { "::" }
|
1995-05-04 03:15:53 -07:00
|
|
|
| FALSE { "false" }
|
|
|
|
| TRUE { "true" }
|
|
|
|
;
|
2000-01-07 08:35:15 -08:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
val_longident:
|
|
|
|
val_ident { Lident $1 }
|
|
|
|
| mod_longident DOT val_ident { Ldot($1, $3) }
|
|
|
|
;
|
|
|
|
constr_longident:
|
2002-02-05 09:11:33 -08:00
|
|
|
mod_longident %prec below_DOT { $1 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| LBRACKET RBRACKET { Lident "[]" }
|
|
|
|
| LPAREN RPAREN { Lident "()" }
|
|
|
|
| FALSE { Lident "false" }
|
|
|
|
| TRUE { Lident "true" }
|
|
|
|
;
|
|
|
|
label_longident:
|
|
|
|
LIDENT { Lident $1 }
|
|
|
|
| mod_longident DOT LIDENT { Ldot($1, $3) }
|
|
|
|
;
|
|
|
|
type_longident:
|
|
|
|
LIDENT { Lident $1 }
|
1995-08-23 04:55:54 -07:00
|
|
|
| mod_ext_longident DOT LIDENT { Ldot($1, $3) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
mod_longident:
|
|
|
|
UIDENT { Lident $1 }
|
|
|
|
| mod_longident DOT UIDENT { Ldot($1, $3) }
|
|
|
|
;
|
1995-08-23 04:55:54 -07:00
|
|
|
mod_ext_longident:
|
|
|
|
UIDENT { Lident $1 }
|
|
|
|
| mod_ext_longident DOT UIDENT { Ldot($1, $3) }
|
2009-07-15 07:06:37 -07:00
|
|
|
| mod_ext_longident LPAREN mod_ext_longident RPAREN { lapply $1 $3 }
|
1995-08-23 04:55:54 -07:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
mty_longident:
|
|
|
|
ident { Lident $1 }
|
1995-08-23 04:55:54 -07:00
|
|
|
| mod_ext_longident DOT ident { Ldot($1, $3) }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
1998-06-24 12:22:26 -07:00
|
|
|
clty_longident:
|
|
|
|
LIDENT { Lident $1 }
|
|
|
|
| mod_ext_longident DOT LIDENT { Ldot($1, $3) }
|
|
|
|
;
|
1996-04-22 04:15:41 -07:00
|
|
|
class_longident:
|
|
|
|
LIDENT { Lident $1 }
|
1997-05-11 14:48:21 -07:00
|
|
|
| mod_longident DOT LIDENT { Ldot($1, $3) }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1995-11-01 10:12:24 -08:00
|
|
|
/* Toplevel directives */
|
|
|
|
|
|
|
|
toplevel_directive:
|
2016-05-03 08:39:45 -07:00
|
|
|
HASH ident { Ptop_dir($2, Pdir_none) }
|
|
|
|
| HASH ident STRING { Ptop_dir($2, Pdir_string (fst $3)) }
|
|
|
|
| HASH ident INT { let (n, m) = $3 in
|
2016-02-16 04:23:31 -08:00
|
|
|
Ptop_dir($2, Pdir_int (n ,m)) }
|
2016-05-03 08:39:45 -07:00
|
|
|
| HASH ident val_longident { Ptop_dir($2, Pdir_ident $3) }
|
|
|
|
| HASH ident mod_longident { Ptop_dir($2, Pdir_ident $3) }
|
|
|
|
| HASH ident FALSE { Ptop_dir($2, Pdir_bool false) }
|
|
|
|
| HASH ident TRUE { Ptop_dir($2, Pdir_bool true) }
|
1995-11-01 10:12:24 -08:00
|
|
|
;
|
2014-04-28 01:04:43 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Miscellaneous */
|
|
|
|
|
1999-11-30 08:07:38 -08:00
|
|
|
name_tag:
|
2000-01-07 08:35:15 -08:00
|
|
|
BACKQUOTE ident { $2 }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
rec_flag:
|
|
|
|
/* empty */ { Nonrecursive }
|
|
|
|
| REC { Recursive }
|
|
|
|
;
|
2015-03-13 04:07:57 -07:00
|
|
|
nonrec_flag:
|
|
|
|
/* empty */ { Recursive }
|
|
|
|
| NONREC { Nonrecursive }
|
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
direction_flag:
|
|
|
|
TO { Upto }
|
|
|
|
| DOWNTO { Downto }
|
|
|
|
;
|
1996-04-22 04:15:41 -07:00
|
|
|
private_flag:
|
1997-05-11 14:48:21 -07:00
|
|
|
/* empty */ { Public }
|
|
|
|
| PRIVATE { Private }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
mutable_flag:
|
|
|
|
/* empty */ { Immutable }
|
|
|
|
| MUTABLE { Mutable }
|
|
|
|
;
|
1996-04-22 04:15:41 -07:00
|
|
|
virtual_flag:
|
1997-05-11 14:48:21 -07:00
|
|
|
/* empty */ { Concrete }
|
|
|
|
| VIRTUAL { Virtual }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
2013-04-10 04:17:41 -07:00
|
|
|
private_virtual_flags:
|
|
|
|
/* empty */ { Public, Concrete }
|
|
|
|
| PRIVATE { Private, Concrete }
|
|
|
|
| VIRTUAL { Public, Virtual }
|
|
|
|
| PRIVATE VIRTUAL { Private, Virtual }
|
|
|
|
| VIRTUAL PRIVATE { Private, Virtual }
|
|
|
|
;
|
2010-04-07 20:58:41 -07:00
|
|
|
override_flag:
|
|
|
|
/* empty */ { Fresh }
|
|
|
|
| BANG { Override }
|
|
|
|
;
|
1995-10-18 08:32:39 -07:00
|
|
|
opt_bar:
|
1997-05-11 14:48:21 -07:00
|
|
|
/* empty */ { () }
|
|
|
|
| BAR { () }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
1997-05-12 08:10:03 -07:00
|
|
|
opt_semi:
|
|
|
|
| /* empty */ { () }
|
|
|
|
| SEMI { () }
|
|
|
|
;
|
2000-09-07 03:57:32 -07:00
|
|
|
subtractive:
|
2001-07-12 05:54:24 -07:00
|
|
|
| MINUS { "-" }
|
2000-09-07 03:57:32 -07:00
|
|
|
| MINUSDOT { "-." }
|
|
|
|
;
|
2009-12-07 08:40:39 -08:00
|
|
|
additive:
|
|
|
|
| PLUS { "+" }
|
|
|
|
| PLUSDOT { "+." }
|
|
|
|
;
|
2013-03-04 04:54:57 -08:00
|
|
|
|
2013-03-05 03:46:25 -08:00
|
|
|
/* Attributes and extensions */
|
2013-03-04 04:54:57 -08:00
|
|
|
|
2014-04-28 01:04:43 -07:00
|
|
|
single_attr_id:
|
|
|
|
LIDENT { $1 }
|
|
|
|
| UIDENT { $1 }
|
2013-04-03 09:28:36 -07:00
|
|
|
| AND { "and" }
|
|
|
|
| AS { "as" }
|
|
|
|
| ASSERT { "assert" }
|
|
|
|
| BEGIN { "begin" }
|
|
|
|
| CLASS { "class" }
|
|
|
|
| CONSTRAINT { "constraint" }
|
|
|
|
| DO { "do" }
|
|
|
|
| DONE { "done" }
|
|
|
|
| DOWNTO { "downto" }
|
|
|
|
| ELSE { "else" }
|
|
|
|
| END { "end" }
|
|
|
|
| EXCEPTION { "exception" }
|
|
|
|
| EXTERNAL { "external" }
|
|
|
|
| FALSE { "false" }
|
|
|
|
| FOR { "for" }
|
|
|
|
| FUN { "fun" }
|
|
|
|
| FUNCTION { "function" }
|
|
|
|
| FUNCTOR { "functor" }
|
|
|
|
| IF { "if" }
|
|
|
|
| IN { "in" }
|
|
|
|
| INCLUDE { "include" }
|
|
|
|
| INHERIT { "inherit" }
|
|
|
|
| INITIALIZER { "initializer" }
|
|
|
|
| LAZY { "lazy" }
|
|
|
|
| LET { "let" }
|
|
|
|
| MATCH { "match" }
|
|
|
|
| METHOD { "method" }
|
|
|
|
| MODULE { "module" }
|
|
|
|
| MUTABLE { "mutable" }
|
|
|
|
| NEW { "new" }
|
2015-06-24 03:15:08 -07:00
|
|
|
| NONREC { "nonrec" }
|
2013-04-03 09:28:36 -07:00
|
|
|
| OBJECT { "object" }
|
|
|
|
| OF { "of" }
|
|
|
|
| OPEN { "open" }
|
|
|
|
| OR { "or" }
|
|
|
|
| PRIVATE { "private" }
|
|
|
|
| REC { "rec" }
|
|
|
|
| SIG { "sig" }
|
|
|
|
| STRUCT { "struct" }
|
|
|
|
| THEN { "then" }
|
|
|
|
| TO { "to" }
|
|
|
|
| TRUE { "true" }
|
|
|
|
| TRY { "try" }
|
|
|
|
| TYPE { "type" }
|
|
|
|
| VAL { "val" }
|
|
|
|
| VIRTUAL { "virtual" }
|
|
|
|
| WHEN { "when" }
|
|
|
|
| WHILE { "while" }
|
|
|
|
| WITH { "with" }
|
2013-04-10 02:17:22 -07:00
|
|
|
/* mod/land/lor/lxor/lsl/lsr/asr are not supported for now */
|
2013-03-07 07:29:11 -08:00
|
|
|
;
|
|
|
|
|
2013-04-10 02:22:54 -07:00
|
|
|
attr_id:
|
2013-04-19 00:40:57 -07:00
|
|
|
single_attr_id { mkloc $1 (symbol_rloc()) }
|
|
|
|
| single_attr_id DOT attr_id { mkloc ($1 ^ "." ^ $3.txt) (symbol_rloc())}
|
2013-04-10 02:22:54 -07:00
|
|
|
;
|
2013-03-04 04:54:57 -08:00
|
|
|
attribute:
|
2013-07-22 07:58:15 -07:00
|
|
|
LBRACKETAT attr_id payload RBRACKET { ($2, $3) }
|
2013-03-04 04:54:57 -08:00
|
|
|
;
|
2013-03-07 05:46:44 -08:00
|
|
|
post_item_attribute:
|
2013-07-22 07:58:15 -07:00
|
|
|
LBRACKETATAT attr_id payload RBRACKET { ($2, $3) }
|
2013-03-07 05:46:44 -08:00
|
|
|
;
|
2014-04-14 07:42:41 -07:00
|
|
|
floating_attribute:
|
|
|
|
LBRACKETATATAT attr_id payload RBRACKET { ($2, $3) }
|
|
|
|
;
|
2013-03-04 09:39:07 -08:00
|
|
|
post_item_attributes:
|
2013-03-07 05:46:44 -08:00
|
|
|
/* empty */ { [] }
|
|
|
|
| post_item_attribute post_item_attributes { $1 :: $2 }
|
2013-03-04 04:54:57 -08:00
|
|
|
;
|
2013-03-04 07:35:47 -08:00
|
|
|
attributes:
|
2013-03-07 05:46:44 -08:00
|
|
|
/* empty */{ [] }
|
2013-03-04 07:35:47 -08:00
|
|
|
| attribute attributes { $1 :: $2 }
|
|
|
|
;
|
2013-03-08 01:17:30 -08:00
|
|
|
ext_attributes:
|
|
|
|
/* empty */ { None, [] }
|
|
|
|
| attribute attributes { None, $1 :: $2 }
|
|
|
|
| PERCENT attr_id attributes { Some $2, $3 }
|
|
|
|
;
|
2013-03-04 04:54:57 -08:00
|
|
|
extension:
|
2013-07-22 07:58:15 -07:00
|
|
|
LBRACKETPERCENT attr_id payload RBRACKET { ($2, $3) }
|
2013-03-04 04:54:57 -08:00
|
|
|
;
|
2013-03-05 03:46:25 -08:00
|
|
|
item_extension:
|
2013-07-22 07:58:15 -07:00
|
|
|
LBRACKETPERCENTPERCENT attr_id payload RBRACKET { ($2, $3) }
|
2013-03-05 03:46:25 -08:00
|
|
|
;
|
2013-07-22 07:58:15 -07:00
|
|
|
payload:
|
|
|
|
structure { PStr $1 }
|
2015-12-02 06:20:26 -08:00
|
|
|
| COLON signature { PSig $2 }
|
2013-07-22 08:15:07 -07:00
|
|
|
| COLON core_type { PTyp $2 }
|
|
|
|
| QUESTION pattern { PPat ($2, None) }
|
|
|
|
| QUESTION pattern WHEN seq_expr { PPat ($2, Some $4) }
|
2013-03-04 05:52:23 -08:00
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
%%
|