1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
|
|
|
/* under the terms of the Q Public License version 1.0. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* The parser definition */
|
|
|
|
|
|
|
|
%{
|
|
|
|
open Location
|
|
|
|
open Asttypes
|
|
|
|
open Longident
|
|
|
|
open Parsetree
|
|
|
|
|
|
|
|
let mktyp d =
|
1999-09-08 10:42:36 -07:00
|
|
|
{ ptyp_desc = d; ptyp_loc = symbol_rloc() }
|
1995-05-04 03:15:53 -07:00
|
|
|
let mkpat d =
|
1999-09-08 10:42:36 -07:00
|
|
|
{ ppat_desc = d; ppat_loc = symbol_rloc() }
|
1995-05-04 03:15:53 -07:00
|
|
|
let mkexp d =
|
1999-09-08 10:42:36 -07:00
|
|
|
{ pexp_desc = d; pexp_loc = symbol_rloc() }
|
1995-05-04 03:15:53 -07:00
|
|
|
let mkmty d =
|
1999-09-08 10:42:36 -07:00
|
|
|
{ pmty_desc = d; pmty_loc = symbol_rloc() }
|
1995-10-05 08:18:49 -07:00
|
|
|
let mksig d =
|
1999-09-08 10:42:36 -07:00
|
|
|
{ psig_desc = d; psig_loc = symbol_rloc() }
|
1995-05-04 03:15:53 -07:00
|
|
|
let mkmod d =
|
1999-09-08 10:42:36 -07:00
|
|
|
{ pmod_desc = d; pmod_loc = symbol_rloc() }
|
1995-10-05 08:18:49 -07:00
|
|
|
let mkstr d =
|
1999-09-08 10:42:36 -07:00
|
|
|
{ pstr_desc = d; pstr_loc = symbol_rloc() }
|
1996-04-22 04:15:41 -07:00
|
|
|
let mkfield d =
|
1999-09-08 10:42:36 -07:00
|
|
|
{ pfield_desc = d; pfield_loc = symbol_rloc() }
|
1998-06-24 12:22:26 -07:00
|
|
|
let mkclass d =
|
1999-09-08 10:42:36 -07:00
|
|
|
{ pcl_desc = d; pcl_loc = symbol_rloc() }
|
1998-06-24 12:22:26 -07:00
|
|
|
let mkcty d =
|
1999-09-08 10:42:36 -07:00
|
|
|
{ pcty_desc = d; pcty_loc = symbol_rloc() }
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
let mkoperator name pos =
|
|
|
|
{ pexp_desc = Pexp_ident(Lident name); pexp_loc = rhs_loc pos }
|
|
|
|
|
1998-05-23 07:10:59 -07:00
|
|
|
(* Ghost expressions and patterns:
|
|
|
|
expressions and patterns added by the parser;
|
1999-09-08 10:42:36 -07:00
|
|
|
they have the loc_ghost flag set to true to tell the profiler
|
|
|
|
not to instrument them.
|
|
|
|
|
1999-09-14 10:20:03 -07:00
|
|
|
Every grammar rule that generates an element with a location must
|
|
|
|
make exaclty one non-ghost element, the topmost one.
|
1998-05-23 07:10:59 -07:00
|
|
|
*)
|
1999-09-08 10:42:36 -07:00
|
|
|
let ghexp d = { pexp_desc = d; pexp_loc = symbol_gloc () };;
|
|
|
|
let ghpat d = { ppat_desc = d; ppat_loc = symbol_gloc () };;
|
|
|
|
let ghtyp d = { ptyp_desc = d; ptyp_loc = symbol_gloc () };;
|
1998-05-23 07:10:59 -07:00
|
|
|
|
1997-05-13 11:28:25 -07:00
|
|
|
let mkassert e =
|
|
|
|
match e with
|
2000-12-04 07:37:05 -08:00
|
|
|
| {pexp_desc = Pexp_construct (Lident "false", None, false) } ->
|
|
|
|
mkexp (Pexp_assertfalse)
|
|
|
|
| _ -> mkexp (Pexp_assert (e))
|
1997-05-13 11:28:25 -07:00
|
|
|
;;
|
|
|
|
|
1997-10-14 06:17:48 -07:00
|
|
|
let mklazy e =
|
1999-09-08 10:42:36 -07:00
|
|
|
let void_pat = ghpat (Ppat_construct (Lident "()", None, false)) in
|
1999-11-30 08:07:38 -08:00
|
|
|
let f = ghexp (Pexp_function ("", None, [void_pat, e])) in
|
1997-10-22 06:26:05 -07:00
|
|
|
let delayed = Ldot (Lident "Lazy", "Delayed") in
|
1999-09-08 10:42:36 -07:00
|
|
|
let df = ghexp (Pexp_construct (delayed, Some f, false)) in
|
|
|
|
let r = ghexp (Pexp_ident (Ldot (Lident "Pervasives", "ref"))) in
|
1999-11-30 08:07:38 -08:00
|
|
|
ghexp (Pexp_apply (r, ["", df]))
|
1997-10-14 06:17:48 -07:00
|
|
|
;;
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
let mkinfix arg1 name arg2 =
|
1999-11-30 08:07:38 -08:00
|
|
|
mkexp(Pexp_apply(mkoperator name 2, ["", arg1; "", arg2]))
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1999-10-19 09:43:49 -07:00
|
|
|
let neg_float_string f =
|
|
|
|
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 =
|
|
|
|
match arg.pexp_desc with
|
|
|
|
Pexp_constant(Const_int n) ->
|
|
|
|
mkexp(Pexp_constant(Const_int(-n)))
|
|
|
|
| Pexp_constant(Const_float f) ->
|
1999-10-19 09:43:49 -07:00
|
|
|
mkexp(Pexp_constant(Const_float(neg_float_string f)))
|
1995-05-04 03:15:53 -07:00
|
|
|
| _ ->
|
1999-11-30 08:07:38 -08:00
|
|
|
mkexp(Pexp_apply(mkoperator ("~" ^ name) 1, ["", arg]))
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1999-09-08 10:42:36 -07:00
|
|
|
let rec mktailexp = function
|
1995-05-04 03:15:53 -07:00
|
|
|
[] ->
|
1999-09-08 10:42:36 -07:00
|
|
|
ghexp(Pexp_construct(Lident "[]", None, false))
|
1995-05-04 03:15:53 -07:00
|
|
|
| e1 :: el ->
|
1999-09-08 10:42:36 -07:00
|
|
|
let exp_el = mktailexp el in
|
1998-05-23 07:10:59 -07:00
|
|
|
let l = {loc_start = e1.pexp_loc.loc_start;
|
1999-09-08 10:42:36 -07:00
|
|
|
loc_end = exp_el.pexp_loc.loc_end;
|
|
|
|
loc_ghost = false}
|
1998-05-23 07:10:59 -07:00
|
|
|
in
|
1999-09-08 10:42:36 -07:00
|
|
|
let arg = {pexp_desc = Pexp_tuple [e1; exp_el];
|
|
|
|
pexp_loc = {l with loc_ghost = true} } in
|
1998-05-23 07:10:59 -07:00
|
|
|
{pexp_desc = Pexp_construct(Lident "::", Some arg, false); pexp_loc = l}
|
|
|
|
|
1999-09-08 10:42:36 -07:00
|
|
|
let rec mktailpat = function
|
1995-05-04 03:15:53 -07:00
|
|
|
[] ->
|
1999-09-08 10:42:36 -07:00
|
|
|
ghpat(Ppat_construct(Lident "[]", None, false))
|
1995-05-04 03:15:53 -07:00
|
|
|
| p1 :: pl ->
|
1999-09-08 10:42:36 -07:00
|
|
|
let pat_pl = mktailpat pl in
|
1998-05-23 07:10:59 -07:00
|
|
|
let l = {loc_start = p1.ppat_loc.loc_start;
|
1999-09-08 10:42:36 -07:00
|
|
|
loc_end = pat_pl.ppat_loc.loc_end;
|
|
|
|
loc_ghost = false}
|
1998-05-23 07:10:59 -07:00
|
|
|
in
|
1999-09-08 10:42:36 -07:00
|
|
|
let arg = {ppat_desc = Ppat_tuple [p1; pat_pl];
|
|
|
|
ppat_loc = {l with loc_ghost = true} } in
|
1998-05-23 07:10:59 -07:00
|
|
|
{ppat_desc = Ppat_construct(Lident "::", Some arg, false); ppat_loc = l}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
1995-10-05 08:18:49 -07:00
|
|
|
let mkstrexp e =
|
1999-09-08 10:42:36 -07:00
|
|
|
{ pstr_desc = Pstr_eval e; pstr_loc = {e.pexp_loc with loc_ghost = true} }
|
1995-10-05 08:18:49 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
let array_function str name =
|
|
|
|
Ldot(Lident str, (if !Clflags.fast then "unsafe_" ^ name else name))
|
|
|
|
|
|
|
|
let rec mkrangepat c1 c2 =
|
|
|
|
if c1 > c2 then mkrangepat c2 c1 else
|
1999-09-08 10:42:36 -07:00
|
|
|
if c1 = c2 then ghpat(Ppat_constant(Const_char c1)) else
|
|
|
|
ghpat(Ppat_or(ghpat(Ppat_constant(Const_char c1)),
|
1995-05-04 03:15:53 -07:00
|
|
|
mkrangepat (Char.chr(Char.code c1 + 1)) c2))
|
1996-04-22 04:15:41 -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)))
|
|
|
|
|
2000-02-24 09:42:32 -08:00
|
|
|
let bigarray_function str name =
|
|
|
|
Ldot(Ldot(Lident "Bigarray", str), name)
|
|
|
|
|
|
|
|
let bigarray_untuplify = function
|
|
|
|
{ pexp_desc = Pexp_tuple explist} -> explist
|
|
|
|
| exp -> [exp]
|
|
|
|
|
|
|
|
let bigarray_get arr arg =
|
|
|
|
match bigarray_untuplify arg with
|
|
|
|
[c1] ->
|
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array1" "get")),
|
|
|
|
["", arr; "", c1]))
|
|
|
|
| [c1;c2] ->
|
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array2" "get")),
|
|
|
|
["", arr; "", c1; "", c2]))
|
|
|
|
| [c1;c2;c3] ->
|
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array3" "get")),
|
|
|
|
["", arr; "", c1; "", c2; "", c3]))
|
|
|
|
| coords ->
|
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Genarray" "get")),
|
|
|
|
["", arr; "", ghexp(Pexp_array coords)]))
|
|
|
|
|
|
|
|
let bigarray_set arr arg newval =
|
|
|
|
match bigarray_untuplify arg with
|
|
|
|
[c1] ->
|
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array1" "set")),
|
|
|
|
["", arr; "", c1; "", newval]))
|
|
|
|
| [c1;c2] ->
|
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array2" "set")),
|
|
|
|
["", arr; "", c1; "", c2; "", newval]))
|
|
|
|
| [c1;c2;c3] ->
|
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Array3" "set")),
|
|
|
|
["", arr; "", c1; "", c2; "", c3; "", newval]))
|
|
|
|
| coords ->
|
|
|
|
mkexp(Pexp_apply(ghexp(Pexp_ident(bigarray_function "Genarray" "set")),
|
|
|
|
["", arr;
|
|
|
|
"", ghexp(Pexp_array coords);
|
|
|
|
"", newval]))
|
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
|
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
|
|
|
|
%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
|
|
|
|
%token <string> FLOAT
|
|
|
|
%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
|
1995-05-04 03:15:53 -07:00
|
|
|
%token <int> 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
|
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
|
|
|
|
%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
|
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
|
2000-09-07 03:57:32 -07:00
|
|
|
%token PLUS
|
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
|
|
|
|
%token SHARP
|
|
|
|
%token SIG
|
|
|
|
%token STAR
|
|
|
|
%token <string> STRING
|
|
|
|
%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
|
|
|
|
|
|
|
|
/* Precedences and associativities. Lower precedences come first. */
|
|
|
|
|
|
|
|
%right prec_let /* let ... in ... */
|
1995-09-27 03:47:51 -07:00
|
|
|
%right prec_type_def /* = in type definitions */
|
1995-05-04 03:15:53 -07:00
|
|
|
%right SEMI /* e1; e2 (sequence) */
|
|
|
|
%right prec_fun prec_match prec_try /* match ... with ... */
|
|
|
|
%right prec_list /* e1; e2 (list, array, record) */
|
|
|
|
%right prec_if /* if ... then ... else ... */
|
|
|
|
%right COLONEQUAL LESSMINUS /* assignments */
|
|
|
|
%left AS /* as in patterns */
|
|
|
|
%left BAR /* | in patterns */
|
|
|
|
%left COMMA /* , in expressions, patterns, types */
|
|
|
|
%right prec_type_arrow /* -> in type expressions */
|
1995-12-15 02:20:24 -08:00
|
|
|
%right OR BARBAR /* or */
|
|
|
|
%right AMPERSAND AMPERAMPER /* & */
|
1996-04-30 07:53:58 -07:00
|
|
|
%left INFIXOP0 EQUAL LESS GREATER /* = < > etc */
|
|
|
|
%right INFIXOP1 /* @ ^ etc */
|
1995-05-04 03:15:53 -07:00
|
|
|
%right COLONCOLON /* :: */
|
2000-09-07 03:57:32 -07:00
|
|
|
%left INFIXOP2 PLUS MINUS MINUSDOT /* + - */
|
1995-05-04 03:15:53 -07:00
|
|
|
%left INFIXOP3 STAR /* * / */
|
|
|
|
%right INFIXOP4 /* ** */
|
|
|
|
%right prec_unary_minus /* - unary */
|
|
|
|
%left prec_appl /* function application */
|
|
|
|
%right prec_constr_appl /* constructor application */
|
1997-05-11 14:48:21 -07:00
|
|
|
%left SHARP /* method call */
|
1997-06-13 08:53:14 -07:00
|
|
|
%left DOT /* record access, array access */
|
1995-05-04 03:15:53 -07:00
|
|
|
%right PREFIXOP /* ! */
|
|
|
|
|
|
|
|
/* 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
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
/* Entry points */
|
|
|
|
|
|
|
|
implementation:
|
1995-09-20 06:34:08 -07:00
|
|
|
structure EOF { $1 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
interface:
|
|
|
|
signature EOF { List.rev $1 }
|
|
|
|
;
|
|
|
|
toplevel_phrase:
|
1997-03-04 02:21:07 -08:00
|
|
|
top_structure SEMISEMI { Ptop_def $1 }
|
1997-05-12 08:10:03 -07:00
|
|
|
| seq_expr SEMISEMI { Ptop_def[mkstrexp $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:
|
|
|
|
structure_item { [$1] }
|
|
|
|
| structure_item top_structure { $1 :: $2 }
|
|
|
|
;
|
1995-11-01 10:12:24 -08:00
|
|
|
use_file:
|
|
|
|
use_file_tail { $1 }
|
1997-05-12 08:10:03 -07:00
|
|
|
| seq_expr use_file_tail { Ptop_def[mkstrexp $1] :: $2 }
|
1995-11-01 10:12:24 -08:00
|
|
|
;
|
|
|
|
use_file_tail:
|
|
|
|
EOF { [] }
|
|
|
|
| SEMISEMI EOF { [] }
|
1997-05-12 08:10:03 -07:00
|
|
|
| SEMISEMI seq_expr use_file_tail { Ptop_def[mkstrexp $2] :: $3 }
|
1995-11-01 10:12:24 -08:00
|
|
|
| SEMISEMI structure_item use_file_tail { Ptop_def[$2] :: $3 }
|
|
|
|
| SEMISEMI toplevel_directive use_file_tail { $2 :: $3 }
|
|
|
|
| structure_item use_file_tail { Ptop_def[$1] :: $2 }
|
|
|
|
| toplevel_directive use_file_tail { $1 :: $2 }
|
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
/* Module expressions */
|
|
|
|
|
|
|
|
module_expr:
|
|
|
|
mod_longident
|
|
|
|
{ mkmod(Pmod_ident $1) }
|
|
|
|
| STRUCT structure END
|
1995-09-20 06:34:08 -07:00
|
|
|
{ mkmod(Pmod_structure($2)) }
|
1997-08-22 01:55:41 -07:00
|
|
|
| STRUCT structure error
|
|
|
|
{ unclosed "struct" 1 "end" 3 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| FUNCTOR LPAREN UIDENT COLON module_type RPAREN MINUSGREATER module_expr
|
|
|
|
%prec prec_fun
|
|
|
|
{ mkmod(Pmod_functor($3, $5, $8)) }
|
1995-08-23 04:55:54 -07:00
|
|
|
| module_expr LPAREN module_expr RPAREN
|
|
|
|
{ mkmod(Pmod_apply($1, $3)) }
|
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 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
structure:
|
1995-09-20 06:34:08 -07:00
|
|
|
structure_tail { $1 }
|
1997-05-12 08:10:03 -07:00
|
|
|
| seq_expr structure_tail { mkstrexp $1 :: $2 }
|
1995-09-20 06:34:08 -07:00
|
|
|
;
|
|
|
|
structure_tail:
|
1995-05-04 03:15:53 -07:00
|
|
|
/* empty */ { [] }
|
1995-09-20 06:34:08 -07:00
|
|
|
| SEMISEMI { [] }
|
1997-05-12 08:10:03 -07:00
|
|
|
| SEMISEMI seq_expr structure_tail { mkstrexp $2 :: $3 }
|
1995-09-20 06:34:08 -07:00
|
|
|
| SEMISEMI structure_item structure_tail { $2 :: $3 }
|
|
|
|
| structure_item structure_tail { $1 :: $2 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
structure_item:
|
1996-04-04 07:56:46 -08:00
|
|
|
LET rec_flag let_bindings
|
|
|
|
{ match $3 with
|
|
|
|
[{ppat_desc = Ppat_any}, exp] -> mkstr(Pstr_eval exp)
|
|
|
|
| _ -> mkstr(Pstr_value($2, List.rev $3)) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| EXTERNAL val_ident_colon core_type EQUAL primitive_declaration
|
|
|
|
{ mkstr(Pstr_primitive($2, {pval_type = $3; pval_prim = $5})) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| TYPE type_declarations
|
1995-10-05 08:18:49 -07:00
|
|
|
{ mkstr(Pstr_type(List.rev $2)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| EXCEPTION UIDENT constructor_arguments
|
1995-10-05 08:18:49 -07:00
|
|
|
{ mkstr(Pstr_exception($2, $3)) }
|
2000-03-12 05:10:29 -08:00
|
|
|
| EXCEPTION UIDENT EQUAL constr_longident
|
|
|
|
{ mkstr(Pstr_exn_rebind($2, $4)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| MODULE UIDENT module_binding
|
1995-10-05 08:18:49 -07:00
|
|
|
{ mkstr(Pstr_module($2, $3)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| MODULE TYPE ident EQUAL module_type
|
1995-10-05 08:18:49 -07:00
|
|
|
{ mkstr(Pstr_modtype($3, $5)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| OPEN mod_longident
|
1995-10-05 08:18:49 -07:00
|
|
|
{ mkstr(Pstr_open $2) }
|
1998-06-24 12:22:26 -07:00
|
|
|
| CLASS class_declarations
|
1996-04-22 04:15:41 -07:00
|
|
|
{ mkstr(Pstr_class (List.rev $2)) }
|
1998-06-24 12:22:26 -07:00
|
|
|
| CLASS TYPE class_type_declarations
|
|
|
|
{ mkstr(Pstr_class_type (List.rev $3)) }
|
2000-12-01 01:35:00 -08:00
|
|
|
| INCLUDE module_expr
|
|
|
|
{ mkstr(Pstr_include $2) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
module_binding:
|
|
|
|
EQUAL module_expr
|
|
|
|
{ $2 }
|
|
|
|
| COLON module_type EQUAL module_expr
|
|
|
|
{ mkmod(Pmod_constraint($4, $2)) }
|
|
|
|
| LPAREN UIDENT COLON module_type RPAREN module_binding
|
|
|
|
{ mkmod(Pmod_functor($2, $4, $6)) }
|
|
|
|
;
|
|
|
|
|
|
|
|
/* Module types */
|
|
|
|
|
|
|
|
module_type:
|
|
|
|
mty_longident
|
|
|
|
{ mkmty(Pmty_ident $1) }
|
|
|
|
| SIG signature END
|
|
|
|
{ mkmty(Pmty_signature(List.rev $2)) }
|
1997-08-22 01:55:41 -07:00
|
|
|
| SIG signature error
|
|
|
|
{ unclosed "sig" 1 "end" 3 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| FUNCTOR LPAREN UIDENT COLON module_type RPAREN MINUSGREATER module_type
|
1995-10-03 07:06:01 -07:00
|
|
|
%prec prec_fun
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkmty(Pmty_functor($3, $5, $8)) }
|
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)) }
|
|
|
|
| LPAREN module_type RPAREN
|
|
|
|
{ $2 }
|
1997-08-22 01:55:41 -07:00
|
|
|
| LPAREN module_type error
|
|
|
|
{ unclosed "(" 1 ")" 3 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
signature:
|
|
|
|
/* empty */ { [] }
|
|
|
|
| signature signature_item { $2 :: $1 }
|
1995-09-20 06:34:08 -07:00
|
|
|
| signature signature_item SEMISEMI { $2 :: $1 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
signature_item:
|
1999-11-30 08:07:38 -08:00
|
|
|
VAL val_ident_colon core_type
|
|
|
|
{ mksig(Psig_value($2, {pval_type = $3; pval_prim = []})) }
|
|
|
|
| EXTERNAL val_ident_colon core_type EQUAL primitive_declaration
|
|
|
|
{ mksig(Psig_value($2, {pval_type = $3; pval_prim = $5})) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| TYPE type_declarations
|
1995-10-05 08:18:49 -07:00
|
|
|
{ mksig(Psig_type(List.rev $2)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| EXCEPTION UIDENT constructor_arguments
|
1995-10-05 08:18:49 -07:00
|
|
|
{ mksig(Psig_exception($2, $3)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| MODULE UIDENT module_declaration
|
1995-10-05 08:18:49 -07:00
|
|
|
{ mksig(Psig_module($2, $3)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| MODULE TYPE ident
|
1995-10-05 08:18:49 -07:00
|
|
|
{ mksig(Psig_modtype($3, Pmodtype_abstract)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| MODULE TYPE ident EQUAL module_type
|
1995-10-05 08:18:49 -07:00
|
|
|
{ mksig(Psig_modtype($3, Pmodtype_manifest $5)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| OPEN mod_longident
|
1995-10-05 08:18:49 -07:00
|
|
|
{ mksig(Psig_open $2) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| INCLUDE module_type
|
1995-10-05 08:18:49 -07:00
|
|
|
{ mksig(Psig_include $2) }
|
1998-06-24 12:22:26 -07:00
|
|
|
| CLASS class_descriptions
|
1996-04-22 04:15:41 -07:00
|
|
|
{ mksig(Psig_class (List.rev $2)) }
|
1998-06-24 12:22:26 -07:00
|
|
|
| CLASS TYPE class_type_declarations
|
|
|
|
{ mksig(Psig_class_type (List.rev $3)) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
module_declaration:
|
|
|
|
COLON module_type
|
|
|
|
{ $2 }
|
|
|
|
| LPAREN UIDENT COLON module_type RPAREN module_declaration
|
|
|
|
{ mkmty(Pmty_functor($2, $4, $6)) }
|
|
|
|
;
|
|
|
|
|
1998-06-24 12:22:26 -07:00
|
|
|
/* Class expressions */
|
|
|
|
|
|
|
|
class_declarations:
|
|
|
|
class_declarations AND class_declaration { $3 :: $1 }
|
|
|
|
| class_declaration { [$1] }
|
|
|
|
;
|
|
|
|
class_declaration:
|
|
|
|
virtual_flag class_type_parameters LIDENT class_fun_binding
|
2000-09-07 03:57:32 -07:00
|
|
|
{ let params, variance = List.split (fst $2) in
|
|
|
|
{pci_virt = $1; pci_params = params, snd $2;
|
|
|
|
pci_name = $3; pci_expr = $4; pci_variance = variance;
|
1999-09-08 10:42:36 -07:00
|
|
|
pci_loc = symbol_rloc ()} }
|
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:
|
1999-09-08 10:42:36 -07:00
|
|
|
/*empty*/ { [], symbol_rloc () }
|
|
|
|
| LBRACKET type_parameter_list RBRACKET { List.rev $2, symbol_rloc () }
|
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:
|
|
|
|
class_simple_expr
|
|
|
|
{ $1 }
|
|
|
|
| FUN class_fun_def
|
|
|
|
{ $2 }
|
1999-11-30 08:07:38 -08:00
|
|
|
| class_simple_expr simple_labeled_expr_list
|
1998-06-24 12:22:26 -07:00
|
|
|
{ mkclass(Pcl_apply($1, List.rev $2)) }
|
|
|
|
| LET rec_flag let_bindings IN class_expr
|
|
|
|
{ mkclass(Pcl_let ($2, List.rev $3, $5)) }
|
|
|
|
;
|
|
|
|
class_simple_expr:
|
|
|
|
LBRACKET core_type_comma_list RBRACKET class_longident
|
|
|
|
{ mkclass(Pcl_constr($4, List.rev $2)) }
|
|
|
|
| class_longident
|
|
|
|
{ mkclass(Pcl_constr($1, [])) }
|
|
|
|
| OBJECT class_structure END
|
|
|
|
{ mkclass(Pcl_structure($2)) }
|
|
|
|
| OBJECT class_structure error
|
|
|
|
{ unclosed "class" 1 "end" 3 }
|
|
|
|
| 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:
|
|
|
|
class_self_pattern class_fields
|
|
|
|
{ $1, List.rev $2 }
|
|
|
|
;
|
|
|
|
class_self_pattern:
|
|
|
|
LPAREN pattern RPAREN
|
1998-11-29 09:34:05 -08:00
|
|
|
{ $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 */
|
1998-11-29 09:34:05 -08:00
|
|
|
{ mkpat(Ppat_any) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_fields:
|
|
|
|
/* empty */
|
|
|
|
{ [] }
|
|
|
|
| class_fields INHERIT class_expr parent_binder
|
|
|
|
{ Pcf_inher ($3, $4) :: $1 }
|
|
|
|
| class_fields VAL value
|
|
|
|
{ Pcf_val $3 :: $1 }
|
|
|
|
| class_fields virtual_method
|
|
|
|
{ Pcf_virt $2 :: $1 }
|
|
|
|
| class_fields concrete_method
|
|
|
|
{ Pcf_meth $2 :: $1 }
|
|
|
|
| class_fields CONSTRAINT constrain
|
|
|
|
{ Pcf_cstr $3 :: $1 }
|
|
|
|
/*
|
|
|
|
| class_fields LET rec_flag class_let_bindings IN
|
|
|
|
{ let (bindings, loc) = $4 in
|
|
|
|
Pcf_let ($3, List.rev bindings, loc) :: $1 }
|
|
|
|
*/
|
|
|
|
| class_fields INITIALIZER seq_expr
|
1998-11-29 09:34:05 -08:00
|
|
|
{ Pcf_init $3 :: $1 }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
/*
|
|
|
|
class_let_bindings: let_bindings
|
1999-09-08 10:42:36 -07:00
|
|
|
{ $1, symbol_rloc () }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
*/
|
|
|
|
parent_binder:
|
|
|
|
AS LIDENT
|
|
|
|
{ Some $2 }
|
|
|
|
| /* empty */
|
|
|
|
{None}
|
|
|
|
;
|
|
|
|
value:
|
|
|
|
mutable_flag label EQUAL seq_expr
|
1999-09-08 10:42:36 -07:00
|
|
|
{ $2, $1, $4, symbol_rloc () }
|
1998-06-24 12:22:26 -07:00
|
|
|
| mutable_flag label type_constraint EQUAL seq_expr
|
1999-09-08 10:42:36 -07:00
|
|
|
{ $2, $1, (let (t, t') = $3 in ghexp(Pexp_constraint($5, t, t'))),
|
|
|
|
symbol_rloc () }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
virtual_method:
|
2000-04-11 20:43:25 -07:00
|
|
|
METHOD PRIVATE VIRTUAL label COLON core_type
|
|
|
|
{ $4, Private, $6, symbol_rloc () }
|
|
|
|
| METHOD VIRTUAL private_flag label COLON core_type
|
|
|
|
{ $4, $3, $6, symbol_rloc () }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
concrete_method :
|
|
|
|
METHOD private_flag label fun_binding
|
1999-09-08 10:42:36 -07:00
|
|
|
{ $3, $2, $4, symbol_rloc () }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
|
|
|
|
/* Class types */
|
|
|
|
|
|
|
|
class_type:
|
|
|
|
class_signature
|
|
|
|
{ $1 }
|
2000-04-11 20:43:25 -07:00
|
|
|
| QUESTION LIDENT COLON simple_core_type_or_tuple MINUSGREATER class_type
|
1999-11-30 08:07:38 -08:00
|
|
|
{ mkcty(Pcty_fun("?" ^ $2 ,
|
2000-04-11 20:43:25 -07:00
|
|
|
{ptyp_desc = Ptyp_constr(Lident "option", [$4]);
|
|
|
|
ptyp_loc = $4.ptyp_loc},
|
|
|
|
$6)) }
|
|
|
|
| OPTLABEL simple_core_type_or_tuple MINUSGREATER class_type
|
|
|
|
{ mkcty(Pcty_fun("?" ^ $1 ,
|
|
|
|
{ptyp_desc = Ptyp_constr(Lident "option", [$2]);
|
|
|
|
ptyp_loc = $2.ptyp_loc},
|
|
|
|
$4)) }
|
|
|
|
| LIDENT COLON simple_core_type_or_tuple MINUSGREATER class_type
|
|
|
|
{ mkcty(Pcty_fun($1, $3, $5)) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| simple_core_type_or_tuple MINUSGREATER class_type
|
|
|
|
{ mkcty(Pcty_fun("", $1, $3)) }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_signature:
|
|
|
|
LBRACKET core_type_comma_list RBRACKET clty_longident
|
1998-10-10 10:52:23 -07:00
|
|
|
{ mkcty(Pcty_constr ($4, List.rev $2)) }
|
1998-06-24 12:22:26 -07:00
|
|
|
| clty_longident
|
|
|
|
{ mkcty(Pcty_constr ($1, [])) }
|
|
|
|
| OBJECT class_sig_body END
|
|
|
|
{ mkcty(Pcty_signature $2) }
|
|
|
|
| OBJECT class_sig_body error
|
|
|
|
{ unclosed "sig" 1 "end" 3 }
|
|
|
|
;
|
|
|
|
class_sig_body:
|
|
|
|
class_self_type class_sig_fields
|
|
|
|
{ $1, List.rev $2 }
|
|
|
|
;
|
|
|
|
class_self_type:
|
|
|
|
LPAREN core_type RPAREN
|
|
|
|
{ $2 }
|
|
|
|
| /* empty */
|
|
|
|
{ mktyp(Ptyp_any) }
|
|
|
|
;
|
|
|
|
class_sig_fields:
|
|
|
|
/* empty */ { [] }
|
|
|
|
| class_sig_fields INHERIT class_signature { Pctf_inher $3 :: $1 }
|
|
|
|
| class_sig_fields VAL value_type { Pctf_val $3 :: $1 }
|
|
|
|
| class_sig_fields virtual_method { Pctf_virt $2 :: $1 }
|
|
|
|
| class_sig_fields method_type { Pctf_meth $2 :: $1 }
|
|
|
|
| class_sig_fields CONSTRAINT constrain { Pctf_cstr $3 :: $1 }
|
|
|
|
;
|
|
|
|
value_type:
|
2000-04-11 20:43:25 -07:00
|
|
|
mutable_flag label COLON core_type
|
|
|
|
{ $2, $1, Some $4, symbol_rloc () }
|
1998-06-24 12:22:26 -07:00
|
|
|
/*
|
|
|
|
XXX Should be removed
|
|
|
|
| mutable_flag label
|
1999-09-08 10:42:36 -07:00
|
|
|
{ $2, $1, None, symbol_rloc () }
|
1998-06-24 12:22:26 -07:00
|
|
|
*/
|
|
|
|
;
|
|
|
|
method_type:
|
2000-04-11 20:43:25 -07:00
|
|
|
METHOD private_flag label COLON core_type
|
|
|
|
{ $3, $2, $5, symbol_rloc () }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
constrain:
|
1999-09-08 10:42:36 -07:00
|
|
|
core_type EQUAL core_type { $1, $3, symbol_rloc () }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_descriptions:
|
|
|
|
class_descriptions AND class_description { $3 :: $1 }
|
|
|
|
| class_description { [$1] }
|
|
|
|
;
|
|
|
|
class_description:
|
2000-04-11 20:43:25 -07:00
|
|
|
virtual_flag class_type_parameters LIDENT COLON class_type
|
2000-09-07 03:57:32 -07:00
|
|
|
{ let params, variance = List.split (fst $2) in
|
|
|
|
{pci_virt = $1; pci_params = params, snd $2;
|
|
|
|
pci_name = $3; pci_expr = $5; pci_variance = variance;
|
1999-09-08 10:42:36 -07:00
|
|
|
pci_loc = symbol_rloc ()} }
|
1998-06-24 12:22:26 -07:00
|
|
|
;
|
|
|
|
class_type_declarations:
|
|
|
|
class_type_declarations AND class_type_declaration { $3 :: $1 }
|
|
|
|
| class_type_declaration { [$1] }
|
|
|
|
;
|
|
|
|
class_type_declaration:
|
|
|
|
virtual_flag class_type_parameters LIDENT EQUAL class_signature
|
2000-09-07 03:57:32 -07:00
|
|
|
{ let params, variance = List.split (fst $2) in
|
|
|
|
{pci_virt = $1; pci_params = params, snd $2;
|
|
|
|
pci_name = $3; pci_expr = $5; pci_variance = variance;
|
1999-09-08 10:42:36 -07:00
|
|
|
pci_loc = symbol_rloc ()} }
|
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:
|
2000-01-07 08:40:34 -08:00
|
|
|
| expr %prec SEMI { $1 }
|
1997-05-12 08:10:03 -07:00
|
|
|
| expr SEMI { $1 }
|
|
|
|
| expr SEMI seq_expr { mkexp(Pexp_sequence($1, $3)) }
|
|
|
|
;
|
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
|
|
|
|
{ ("?" ^ fst $3, $4, snd $3) }
|
2000-04-11 20:43:25 -07:00
|
|
|
| QUESTION label_var
|
1999-11-30 08:07:38 -08:00
|
|
|
{ ("?" ^ fst $2, None, snd $2) }
|
2000-04-11 20:43:25 -07:00
|
|
|
| OPTLABEL LPAREN let_pattern opt_default RPAREN
|
|
|
|
{ ("?" ^ $1, $4, $3) }
|
|
|
|
| OPTLABEL pattern_var
|
|
|
|
{ ("?" ^ $1, None, $2) }
|
|
|
|
| TILDE LPAREN label_let_pattern RPAREN
|
|
|
|
{ (fst $3, None, snd $3) }
|
|
|
|
| TILDE label_var
|
|
|
|
{ (fst $2, None, snd $2) }
|
|
|
|
| LABEL simple_pattern
|
|
|
|
{ ($1, None, $2) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| simple_pattern
|
|
|
|
{ ("", None, $1) }
|
|
|
|
;
|
2000-04-11 20:43:25 -07:00
|
|
|
pattern_var:
|
|
|
|
LIDENT { mkpat(Ppat_var $1) }
|
|
|
|
;
|
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:
|
|
|
|
LIDENT { ($1, mkpat(Ppat_var $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:
|
2000-01-24 08:21:07 -08:00
|
|
|
simple_expr
|
1995-05-04 03:15:53 -07:00
|
|
|
{ $1 }
|
1999-11-30 08:07:38 -08:00
|
|
|
| simple_expr simple_labeled_expr_list %prec prec_appl
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkexp(Pexp_apply($1, List.rev $2)) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| LET rec_flag let_bindings IN seq_expr %prec prec_let
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkexp(Pexp_let($2, List.rev $3, $5)) }
|
1998-02-26 04:54:44 -08:00
|
|
|
| LET MODULE UIDENT module_binding IN seq_expr %prec prec_let
|
|
|
|
{ mkexp(Pexp_letmodule($3, $4, $6)) }
|
1995-10-18 08:32:39 -07:00
|
|
|
| FUNCTION opt_bar match_cases %prec prec_fun
|
1999-11-30 08:07:38 -08:00
|
|
|
{ mkexp(Pexp_function("", None, List.rev $3)) }
|
|
|
|
| FUN labeled_simple_pattern fun_def %prec prec_fun
|
|
|
|
{ let (l,o,p) = $2 in mkexp(Pexp_function(l, o, [p, $3])) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| MATCH seq_expr WITH opt_bar match_cases %prec prec_match
|
1995-10-18 08:32:39 -07:00
|
|
|
{ mkexp(Pexp_match($2, List.rev $5)) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| TRY seq_expr WITH opt_bar match_cases %prec prec_try
|
1995-10-18 08:32:39 -07:00
|
|
|
{ mkexp(Pexp_try($2, List.rev $5)) }
|
1997-11-12 04:32:53 -08:00
|
|
|
| TRY seq_expr WITH error %prec prec_try
|
|
|
|
{ syntax_error() }
|
2000-01-24 08:21:07 -08:00
|
|
|
| expr_comma_list
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkexp(Pexp_tuple(List.rev $1)) }
|
|
|
|
| constr_longident simple_expr %prec prec_constr_appl
|
1997-06-16 11:10:35 -07:00
|
|
|
{ mkexp(Pexp_construct($1, Some $2, false)) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| name_tag simple_expr %prec prec_constr_appl
|
|
|
|
{ mkexp(Pexp_variant($1, Some $2)) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| IF seq_expr THEN expr ELSE expr %prec prec_if
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkexp(Pexp_ifthenelse($2, $4, Some $6)) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| IF seq_expr THEN expr %prec prec_if
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkexp(Pexp_ifthenelse($2, $4, None)) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| WHILE seq_expr DO seq_expr DONE
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkexp(Pexp_while($2, $4)) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| FOR val_ident EQUAL seq_expr direction_flag seq_expr DO seq_expr DONE
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkexp(Pexp_for($2, $4, $6, $5, $8)) }
|
|
|
|
| expr COLONCOLON expr
|
1999-09-08 10:42:36 -07:00
|
|
|
{ mkexp(Pexp_construct(Lident "::",
|
|
|
|
Some(ghexp(Pexp_tuple[$1;$3])),
|
|
|
|
false)) }
|
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 }
|
|
|
|
| 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 }
|
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
|
2000-01-07 08:35:15 -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 }
|
|
|
|
| simple_expr DOT label_longident LESSMINUS expr
|
|
|
|
{ mkexp(Pexp_setfield($1, $3, $5)) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| simple_expr DOT LPAREN seq_expr RPAREN LESSMINUS expr
|
1999-09-08 10:42:36 -07:00
|
|
|
{ mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "Array" "set")),
|
1999-11-30 08:07:38 -08:00
|
|
|
["",$1; "",$4; "",$7])) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| simple_expr DOT LBRACKET seq_expr RBRACKET LESSMINUS expr
|
1999-09-08 10:42:36 -07:00
|
|
|
{ mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "String" "set")),
|
1999-11-30 08:07:38 -08:00
|
|
|
["",$1; "",$4; "",$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
|
|
|
|
{ mkexp(Pexp_setinstvar($1, $3)) }
|
1998-06-24 12:22:26 -07:00
|
|
|
/*
|
|
|
|
| expr SHARP label
|
|
|
|
{ mkexp(Pexp_send($1, $3)) }
|
|
|
|
| expr SHARP label simple_expr_list
|
|
|
|
{ mkexp(Pexp_apply({ pexp_desc = Pexp_send($1, $3);
|
|
|
|
pexp_loc = { loc_start = Parsing.symbol_start ();
|
1999-09-08 10:42:36 -07:00
|
|
|
loc_end = Parsing.rhs_end 3;
|
|
|
|
loc_ghost = false } },
|
1998-06-24 12:22:26 -07:00
|
|
|
List.rev $4)) }
|
|
|
|
*/
|
1997-05-13 11:28:25 -07:00
|
|
|
| ASSERT simple_expr %prec prec_appl
|
|
|
|
{ mkassert $2 }
|
1997-10-14 06:17:48 -07:00
|
|
|
| LAZY simple_expr %prec prec_appl
|
|
|
|
{ mklazy $2 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
simple_expr:
|
|
|
|
val_longident
|
|
|
|
{ mkexp(Pexp_ident $1) }
|
|
|
|
| constant
|
|
|
|
{ mkexp(Pexp_constant $1) }
|
|
|
|
| constr_longident
|
1997-06-16 11:10:35 -07:00
|
|
|
{ mkexp(Pexp_construct($1, None, false)) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| name_tag
|
|
|
|
{ mkexp(Pexp_variant($1, None)) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| LPAREN seq_expr RPAREN
|
1995-05-04 03:15:53 -07:00
|
|
|
{ $2 }
|
1997-08-22 01:55:41 -07:00
|
|
|
| LPAREN seq_expr error
|
|
|
|
{ unclosed "(" 1 ")" 3 }
|
1997-05-12 08:10:03 -07:00
|
|
|
| BEGIN seq_expr END
|
1995-05-04 03:15:53 -07:00
|
|
|
{ $2 }
|
2000-01-21 11:01:39 -08:00
|
|
|
| BEGIN END
|
2000-09-06 07:18:32 -07:00
|
|
|
{ mkexp (Pexp_construct (Lident "()", None, false)) }
|
1997-08-22 01:55:41 -07:00
|
|
|
| BEGIN seq_expr error
|
|
|
|
{ unclosed "begin" 1 "end" 3 }
|
1997-05-12 08:10:03 -07:00
|
|
|
| LPAREN seq_expr type_constraint RPAREN
|
1996-04-22 04:15:41 -07:00
|
|
|
{ let (t, t') = $3 in mkexp(Pexp_constraint($2, t, t')) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| simple_expr DOT label_longident
|
|
|
|
{ mkexp(Pexp_field($1, $3)) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| simple_expr DOT LPAREN seq_expr RPAREN
|
1999-09-08 10:42:36 -07:00
|
|
|
{ mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "Array" "get")),
|
1999-11-30 08:07:38 -08:00
|
|
|
["",$1; "",$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
|
1999-09-08 10:42:36 -07:00
|
|
|
{ mkexp(Pexp_apply(ghexp(Pexp_ident(array_function "String" "get")),
|
1999-11-30 08:07:38 -08:00
|
|
|
["",$1; "",$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 }
|
1998-04-27 08:17:11 -07:00
|
|
|
| LBRACE record_expr RBRACE
|
|
|
|
{ let (exten, fields) = $2 in mkexp(Pexp_record(fields, exten)) }
|
|
|
|
| LBRACE record_expr error
|
|
|
|
{ unclosed "{" 1 "}" 5 }
|
1997-05-13 07:45:28 -07:00
|
|
|
| LBRACKETBAR expr_semi_list opt_semi BARRBRACKET
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkexp(Pexp_array(List.rev $2)) }
|
1997-08-22 01:55:41 -07:00
|
|
|
| LBRACKETBAR expr_semi_list opt_semi error
|
|
|
|
{ unclosed "[|" 1 "|]" 4 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| LBRACKETBAR BARRBRACKET
|
|
|
|
{ mkexp(Pexp_array []) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| LBRACKET expr_semi_list opt_semi RBRACKET
|
1999-09-08 10:42:36 -07:00
|
|
|
{ mkexp (mktailexp (List.rev $2)).pexp_desc }
|
1997-08-22 01:55:41 -07:00
|
|
|
| LBRACKET expr_semi_list opt_semi error
|
|
|
|
{ unclosed "[" 1 "]" 4 }
|
1995-05-04 03:15:53 -07:00
|
|
|
| PREFIXOP simple_expr
|
1999-11-30 08:07:38 -08:00
|
|
|
{ mkexp(Pexp_apply(mkoperator $1 1, ["",$2])) }
|
1996-04-22 04:15:41 -07:00
|
|
|
| NEW class_longident
|
|
|
|
{ mkexp(Pexp_new($2)) }
|
1998-04-27 08:17:11 -07:00
|
|
|
| LBRACELESS field_expr_list opt_semi GREATERRBRACE
|
1996-04-22 04:15:41 -07:00
|
|
|
{ mkexp(Pexp_override(List.rev $2)) }
|
1998-04-27 08:17:11 -07:00
|
|
|
| LBRACELESS field_expr_list opt_semi error
|
1997-08-22 01:55:41 -07:00
|
|
|
{ unclosed "{<" 1 ">}" 4 }
|
1996-04-22 04:15:41 -07:00
|
|
|
| LBRACELESS GREATERRBRACE
|
|
|
|
{ mkexp(Pexp_override []) }
|
1998-06-24 12:22:26 -07:00
|
|
|
| simple_expr SHARP label
|
|
|
|
{ mkexp(Pexp_send($1, $3)) }
|
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:
|
|
|
|
simple_expr
|
|
|
|
{ ("", $1) }
|
|
|
|
| label_expr
|
|
|
|
{ $1 }
|
|
|
|
;
|
|
|
|
label_expr:
|
|
|
|
LABEL simple_expr
|
|
|
|
{ ($1, $2) }
|
2000-04-11 20:43:25 -07:00
|
|
|
| TILDE label_ident
|
|
|
|
{ $2 }
|
|
|
|
| QUESTION label_ident
|
|
|
|
{ ("?" ^ fst $2, snd $2) }
|
|
|
|
| OPTLABEL simple_expr
|
|
|
|
{ ("?" ^ $1, $2) }
|
|
|
|
;
|
|
|
|
label_ident:
|
|
|
|
LIDENT { ($1, mkexp(Pexp_ident(Lident $1))) }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
|
|
|
/*
|
1995-05-04 03:15:53 -07:00
|
|
|
simple_expr_list:
|
|
|
|
simple_expr
|
|
|
|
{ [$1] }
|
|
|
|
| simple_expr_list simple_expr
|
|
|
|
{ $2 :: $1 }
|
|
|
|
;
|
1999-11-30 08:07:38 -08:00
|
|
|
*/
|
1995-05-04 03:15:53 -07:00
|
|
|
let_bindings:
|
|
|
|
let_binding { [$1] }
|
|
|
|
| let_bindings AND let_binding { $3 :: $1 }
|
|
|
|
;
|
|
|
|
let_binding:
|
|
|
|
val_ident fun_binding
|
|
|
|
{ ({ppat_desc = Ppat_var $1; ppat_loc = rhs_loc 1}, $2) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| pattern EQUAL seq_expr %prec prec_let
|
1995-05-05 03:05:18 -07:00
|
|
|
{ ($1, $3) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
fun_binding:
|
1997-05-12 08:10:03 -07:00
|
|
|
EQUAL seq_expr %prec prec_let
|
1995-05-04 03:15:53 -07:00
|
|
|
{ $2 }
|
1997-05-12 08:10:03 -07:00
|
|
|
| type_constraint EQUAL seq_expr %prec prec_let
|
1996-04-22 04:15:41 -07:00
|
|
|
{ let (t, t') = $1 in mkexp(Pexp_constraint($3, t, t')) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| labeled_simple_pattern fun_binding
|
|
|
|
{ let (l, o, p) = $1 in mkexp(Pexp_function(l, o, [p, $2])) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
match_cases:
|
|
|
|
pattern match_action { [$1, $2] }
|
|
|
|
| match_cases BAR pattern match_action { ($3, $4) :: $1 }
|
|
|
|
;
|
|
|
|
fun_def:
|
2000-01-07 08:35:15 -08:00
|
|
|
match_action { $1 }
|
1999-11-30 08:07:38 -08:00
|
|
|
| labeled_simple_pattern fun_def
|
|
|
|
{ let (l,o,p) = $1 in mkexp(Pexp_function(l, o, [p, $2])) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
match_action:
|
1997-05-12 08:10:03 -07:00
|
|
|
MINUSGREATER seq_expr { $2 }
|
|
|
|
| WHEN seq_expr MINUSGREATER seq_expr { mkexp(Pexp_when($2, $4)) }
|
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:
|
|
|
|
simple_expr WITH lbl_expr_list opt_semi { (Some $1, List.rev $3) }
|
|
|
|
| lbl_expr_list opt_semi { (None, List.rev $1) }
|
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
lbl_expr_list:
|
|
|
|
label_longident EQUAL expr %prec prec_list
|
|
|
|
{ [$1,$3] }
|
|
|
|
| lbl_expr_list SEMI label_longident EQUAL expr %prec prec_list
|
|
|
|
{ ($3, $5) :: $1 }
|
|
|
|
;
|
1998-04-27 08:17:11 -07:00
|
|
|
field_expr_list:
|
1996-04-22 04:15:41 -07:00
|
|
|
label EQUAL expr %prec prec_list
|
|
|
|
{ [$1,$3] }
|
1998-04-27 08:17:11 -07:00
|
|
|
| field_expr_list SEMI label EQUAL expr %prec prec_list
|
1996-04-22 04:15:41 -07:00
|
|
|
{ ($3, $5) :: $1 }
|
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
expr_semi_list:
|
|
|
|
expr %prec prec_list { [$1] }
|
|
|
|
| expr_semi_list SEMI expr %prec prec_list { $3 :: $1 }
|
|
|
|
;
|
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
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
/* Patterns */
|
|
|
|
|
|
|
|
pattern:
|
1995-09-11 01:09:22 -07:00
|
|
|
simple_pattern
|
|
|
|
{ $1 }
|
|
|
|
| pattern AS val_ident
|
|
|
|
{ mkpat(Ppat_alias($1, $3)) }
|
|
|
|
| pattern_comma_list
|
|
|
|
{ mkpat(Ppat_tuple(List.rev $1)) }
|
|
|
|
| constr_longident pattern %prec prec_constr_appl
|
1997-06-16 11:10:35 -07:00
|
|
|
{ mkpat(Ppat_construct($1, Some $2, false)) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| name_tag pattern %prec prec_constr_appl
|
|
|
|
{ mkpat(Ppat_variant($1, Some $2)) }
|
1995-09-11 01:09:22 -07:00
|
|
|
| pattern COLONCOLON pattern
|
1999-09-08 10:42:36 -07:00
|
|
|
{ mkpat(Ppat_construct(Lident "::", Some(ghpat(Ppat_tuple[$1;$3])),
|
1997-06-16 11:10:35 -07:00
|
|
|
false)) }
|
1995-09-11 01:09:22 -07:00
|
|
|
| pattern BAR pattern
|
|
|
|
{ mkpat(Ppat_or($1, $3)) }
|
|
|
|
;
|
|
|
|
simple_pattern:
|
1995-05-04 03:15:53 -07:00
|
|
|
val_ident
|
|
|
|
{ mkpat(Ppat_var $1) }
|
|
|
|
| UNDERSCORE
|
|
|
|
{ mkpat(Ppat_any) }
|
|
|
|
| signed_constant
|
|
|
|
{ mkpat(Ppat_constant $1) }
|
|
|
|
| CHAR DOTDOT CHAR
|
|
|
|
{ mkrangepat $1 $3 }
|
|
|
|
| constr_longident
|
1997-06-16 11:10:35 -07:00
|
|
|
{ mkpat(Ppat_construct($1, None, false)) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| name_tag
|
|
|
|
{ mkpat(Ppat_variant($1, None)) }
|
2000-02-21 19:08:08 -08:00
|
|
|
| SHARP type_longident
|
|
|
|
{ mkpat(Ppat_type $2) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| LBRACE lbl_pattern_list opt_semi RBRACE
|
1995-05-04 03:15:53 -07:00
|
|
|
{ mkpat(Ppat_record(List.rev $2)) }
|
1997-08-22 01:55:41 -07:00
|
|
|
| LBRACE lbl_pattern_list opt_semi error
|
|
|
|
{ unclosed "{" 1 "}" 4 }
|
1997-05-12 08:10:03 -07:00
|
|
|
| LBRACKET pattern_semi_list opt_semi RBRACKET
|
1999-09-08 10:42:36 -07:00
|
|
|
{ mkpat (mktailpat (List.rev $2)).ppat_desc }
|
1997-08-22 01:55:41 -07:00
|
|
|
| LBRACKET pattern_semi_list opt_semi error
|
1998-04-06 02:16:54 -07:00
|
|
|
{ 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-05-04 03:15:53 -07:00
|
|
|
| LPAREN pattern RPAREN
|
|
|
|
{ $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 }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
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] }
|
|
|
|
;
|
|
|
|
pattern_semi_list:
|
|
|
|
pattern { [$1] }
|
|
|
|
| pattern_semi_list SEMI pattern { $3 :: $1 }
|
|
|
|
;
|
|
|
|
lbl_pattern_list:
|
|
|
|
label_longident EQUAL pattern { [($1, $3)] }
|
|
|
|
| lbl_pattern_list SEMI label_longident EQUAL pattern { ($3, $5) :: $1 }
|
|
|
|
;
|
|
|
|
|
1995-07-25 04:38:42 -07:00
|
|
|
/* Primitive declarations */
|
|
|
|
|
|
|
|
primitive_declaration:
|
|
|
|
STRING { [$1] }
|
|
|
|
| STRING primitive_declaration { $1 :: $2 }
|
|
|
|
;
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Type declarations */
|
|
|
|
|
|
|
|
type_declarations:
|
|
|
|
type_declaration { [$1] }
|
|
|
|
| type_declarations AND type_declaration { $3 :: $1 }
|
|
|
|
;
|
|
|
|
type_declaration:
|
1997-02-20 12:39:02 -08:00
|
|
|
type_parameters LIDENT type_kind constraints
|
2000-09-07 03:57:32 -07:00
|
|
|
{ let (params, variance) = List.split $1 in
|
|
|
|
let (kind, manifest) = $3 in
|
|
|
|
($2, {ptype_params = params;
|
1997-02-20 12:39:02 -08:00
|
|
|
ptype_cstrs = List.rev $4;
|
1995-09-26 13:23:29 -07:00
|
|
|
ptype_kind = kind;
|
|
|
|
ptype_manifest = manifest;
|
2000-09-07 03:57:32 -07:00
|
|
|
ptype_variance = variance;
|
1999-09-08 10:42:36 -07:00
|
|
|
ptype_loc = symbol_rloc()}) }
|
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*/
|
2000-09-07 03:57:32 -07:00
|
|
|
{ (Ptype_abstract, None) }
|
1995-09-27 03:47:51 -07:00
|
|
|
| EQUAL core_type %prec prec_type_def
|
2000-09-07 03:57:32 -07:00
|
|
|
{ (Ptype_abstract, Some $2) }
|
1995-05-04 03:15:53 -07:00
|
|
|
| EQUAL constructor_declarations
|
1995-09-26 13:23:29 -07:00
|
|
|
{ (Ptype_variant(List.rev $2), None) }
|
1995-10-18 08:32:39 -07:00
|
|
|
| EQUAL BAR constructor_declarations
|
|
|
|
{ (Ptype_variant(List.rev $3), None) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| EQUAL LBRACE label_declarations opt_semi RBRACE
|
1995-09-26 13:23:29 -07:00
|
|
|
{ (Ptype_record(List.rev $3), None) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| EQUAL core_type EQUAL opt_bar constructor_declarations %prec prec_type_def
|
1995-10-18 08:32:39 -07:00
|
|
|
{ (Ptype_variant(List.rev $5), Some $2) }
|
1997-05-12 08:10:03 -07:00
|
|
|
| EQUAL core_type EQUAL LBRACE label_declarations opt_semi RBRACE
|
|
|
|
%prec prec_type_def
|
1995-09-26 13:23:29 -07:00
|
|
|
{ (Ptype_record(List.rev $5), Some $2) }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
type_parameters:
|
|
|
|
/*empty*/ { [] }
|
|
|
|
| type_parameter { [$1] }
|
|
|
|
| LPAREN type_parameter_list RPAREN { List.rev $2 }
|
|
|
|
;
|
|
|
|
type_parameter:
|
2000-09-07 03:57:32 -07:00
|
|
|
type_variance QUOTE ident { $3, $1 }
|
|
|
|
;
|
|
|
|
type_variance:
|
|
|
|
/* empty */ { false, false }
|
|
|
|
| PLUS { true, false }
|
|
|
|
| MINUS { false, true }
|
1995-05-04 03:15:53 -07:00
|
|
|
;
|
|
|
|
type_parameter_list:
|
|
|
|
type_parameter { [$1] }
|
|
|
|
| type_parameter_list COMMA type_parameter { $3 :: $1 }
|
|
|
|
;
|
|
|
|
constructor_declarations:
|
|
|
|
constructor_declaration { [$1] }
|
|
|
|
| constructor_declarations BAR constructor_declaration { $3 :: $1 }
|
|
|
|
;
|
|
|
|
constructor_declaration:
|
|
|
|
constr_ident constructor_arguments { ($1, $2) }
|
|
|
|
;
|
|
|
|
constructor_arguments:
|
|
|
|
/*empty*/ { [] }
|
|
|
|
| OF core_type_list { List.rev $2 }
|
|
|
|
;
|
|
|
|
label_declarations:
|
|
|
|
label_declaration { [$1] }
|
|
|
|
| label_declarations SEMI label_declaration { $3 :: $1 }
|
|
|
|
;
|
|
|
|
label_declaration:
|
2000-04-11 20:43:25 -07:00
|
|
|
mutable_flag label COLON core_type { ($2, $1, $4) }
|
1995-05-04 03:15:53 -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:
|
1997-02-20 12:39:02 -08:00
|
|
|
TYPE type_parameters label_longident EQUAL core_type constraints
|
2000-09-07 03:57:32 -07:00
|
|
|
{ let params, variance = List.split $2 in
|
|
|
|
($3, Pwith_type {ptype_params = params;
|
1997-02-20 12:39:02 -08:00
|
|
|
ptype_cstrs = List.rev $6;
|
2000-09-07 03:57:32 -07:00
|
|
|
ptype_kind = Ptype_abstract;
|
1995-10-01 06:39:43 -07:00
|
|
|
ptype_manifest = Some $5;
|
2000-09-07 03:57:32 -07:00
|
|
|
ptype_variance = variance;
|
1999-09-08 10:42:36 -07:00
|
|
|
ptype_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 */
|
1995-10-01 06:39:43 -07:00
|
|
|
| MODULE mod_longident EQUAL mod_ext_longident
|
|
|
|
{ ($2, Pwith_module $4) }
|
1995-09-28 03:41:50 -07:00
|
|
|
;
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Core types */
|
|
|
|
|
|
|
|
core_type:
|
1999-11-30 08:07:38 -08:00
|
|
|
core_type2
|
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
|
|
|
|
%prec prec_type_arrow
|
1999-11-30 08:07:38 -08:00
|
|
|
{ mktyp(Ptyp_arrow("?" ^ $2 ,
|
2000-04-11 20:43:25 -07:00
|
|
|
{ptyp_desc = Ptyp_constr(Lident "option", [$4]);
|
|
|
|
ptyp_loc = $4.ptyp_loc}, $6)) }
|
|
|
|
| OPTLABEL core_type2 MINUSGREATER core_type2 %prec prec_type_arrow
|
|
|
|
{ mktyp(Ptyp_arrow("?" ^ $1 ,
|
|
|
|
{ptyp_desc = Ptyp_constr(Lident "option", [$2]);
|
|
|
|
ptyp_loc = $2.ptyp_loc}, $4)) }
|
|
|
|
| LIDENT COLON core_type2 MINUSGREATER core_type2 %prec prec_type_arrow
|
|
|
|
{ mktyp(Ptyp_arrow($1, $3, $5)) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| core_type2 MINUSGREATER core_type2 %prec prec_type_arrow
|
|
|
|
{ mktyp(Ptyp_arrow("", $1, $3)) }
|
|
|
|
;
|
1996-04-22 04:15:41 -07:00
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
simple_core_type:
|
2001-09-25 02:54:18 -07:00
|
|
|
simple_core_type2
|
|
|
|
{ $1 }
|
|
|
|
| LPAREN core_type_comma_list RPAREN
|
|
|
|
{ match $2 with [sty] -> sty | _ -> raise Parse_error }
|
|
|
|
;
|
|
|
|
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
|
|
|
|
{ mktyp(Ptyp_constr($1, [])) }
|
2001-09-25 02:54:18 -07:00
|
|
|
| simple_core_type2 type_longident %prec prec_constr_appl
|
1997-03-07 14:26:29 -08:00
|
|
|
{ mktyp(Ptyp_constr($2, [$1])) }
|
2001-09-25 02:54:18 -07:00
|
|
|
| LPAREN core_type_comma_list RPAREN type_longident %prec prec_constr_appl
|
1997-03-07 14:26:29 -08:00
|
|
|
{ mktyp(Ptyp_constr($4, List.rev $2)) }
|
|
|
|
| LESS meth_list GREATER
|
|
|
|
{ mktyp(Ptyp_object $2) }
|
|
|
|
| LESS GREATER
|
|
|
|
{ mktyp(Ptyp_object []) }
|
1999-11-30 08:07:38 -08:00
|
|
|
| SHARP class_longident opt_present
|
|
|
|
{ mktyp(Ptyp_class($2, [], $3)) }
|
2001-09-25 02:54:18 -07:00
|
|
|
| simple_core_type2 SHARP class_longident opt_present %prec prec_constr_appl
|
1999-11-30 08:07:38 -08:00
|
|
|
{ mktyp(Ptyp_class($3, [$1], $4)) }
|
|
|
|
| LPAREN core_type_comma_list RPAREN SHARP class_longident opt_present
|
1996-04-22 04:15:41 -07:00
|
|
|
%prec prec_constr_appl
|
1999-11-30 08:07:38 -08:00
|
|
|
{ mktyp(Ptyp_class($5, List.rev $2, $6)) }
|
2001-09-25 02:54:18 -07:00
|
|
|
| LBRACKET tag_field RBRACKET
|
|
|
|
{ mktyp(Ptyp_variant([$2], true, None)) }
|
|
|
|
| LBRACKET BAR row_field_list RBRACKET
|
|
|
|
{ mktyp(Ptyp_variant(List.rev $3, true, None)) }
|
|
|
|
| LBRACKETBAR row_field_list RBRACKET
|
|
|
|
{ mktyp(Ptyp_variant(List.rev $2, true, None)) }
|
|
|
|
| LBRACKET row_field BAR row_field_list RBRACKET
|
|
|
|
{ mktyp(Ptyp_variant($2 :: List.rev $4, true, None)) }
|
2000-01-07 08:40:34 -08:00
|
|
|
| LBRACKET GREATER opt_bar row_field_list RBRACKET
|
2001-09-25 02:54:18 -07:00
|
|
|
{ mktyp(Ptyp_variant(List.rev $4, false, None)) }
|
2000-06-11 07:34:10 -07:00
|
|
|
| LBRACKETLESS opt_bar row_field_list RBRACKET
|
2001-09-25 02:54:18 -07:00
|
|
|
{ mktyp(Ptyp_variant(List.rev $3, true, Some [])) }
|
2000-06-11 07:34:10 -07:00
|
|
|
| LBRACKETLESS opt_bar row_field_list GREATER name_tag_list RBRACKET
|
2001-09-25 02:54:18 -07:00
|
|
|
{ mktyp(Ptyp_variant(List.rev $3, true, Some (List.rev $5))) }
|
2000-06-11 07:34:10 -07:00
|
|
|
| LBRACKET GREATER RBRACKET
|
2001-09-25 02:54:18 -07:00
|
|
|
{ mktyp(Ptyp_variant([], false, None)) }
|
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 }
|
|
|
|
| simple_core_type2 { Rinherit $1 }
|
|
|
|
;
|
|
|
|
tag_field:
|
|
|
|
name_tag OF opt_ampersand amper_type_list
|
|
|
|
{ Rtag ($1, $3, List.rev $4) }
|
|
|
|
| name_tag
|
|
|
|
{ Rtag ($1, 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:
|
2000-01-07 08:35:15 -08:00
|
|
|
core_type { [$1] }
|
|
|
|
| amper_type_list AMPERSAND core_type { $3 :: $1 }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
|
|
|
opt_present:
|
|
|
|
LBRACKET GREATER name_tag_list RBRACKET { List.rev $3 }
|
2000-01-07 08:35:15 -08:00
|
|
|
| /* empty */ { [] }
|
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:
|
2001-09-25 02:54:18 -07:00
|
|
|
simple_core_type { $1 }
|
|
|
|
| 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:
|
|
|
|
simple_core_type { [$1] }
|
|
|
|
| core_type_list STAR simple_core_type { $3 :: $1 }
|
|
|
|
;
|
1996-04-22 04:15:41 -07:00
|
|
|
meth_list:
|
1997-05-13 07:45:28 -07:00
|
|
|
field SEMI meth_list { $1 :: $3 }
|
|
|
|
| field opt_semi { [$1] }
|
|
|
|
| DOTDOT { [mkfield Pfield_var] }
|
1996-04-22 04:15:41 -07:00
|
|
|
;
|
|
|
|
field:
|
2000-04-11 20:43:25 -07:00
|
|
|
label COLON core_type { mkfield(Pfield($1, $3)) }
|
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:
|
|
|
|
INT { Const_int $1 }
|
|
|
|
| CHAR { Const_char $1 }
|
|
|
|
| STRING { Const_string $1 }
|
|
|
|
| FLOAT { Const_float $1 }
|
|
|
|
;
|
|
|
|
signed_constant:
|
|
|
|
constant { $1 }
|
2000-09-07 03:57:32 -07:00
|
|
|
| MINUS INT { Const_int(- $2) }
|
|
|
|
| subtractive FLOAT { Const_float("-" ^ $2) }
|
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 }
|
|
|
|
;
|
1999-11-30 08:07:38 -08:00
|
|
|
val_ident_colon:
|
|
|
|
LIDENT COLON { $1 }
|
|
|
|
| LPAREN operator RPAREN COLON { $2 }
|
2000-01-07 08:35:15 -08:00
|
|
|
| LABEL { $1 }
|
1999-11-30 08:07:38 -08:00
|
|
|
;
|
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 }
|
2000-09-07 03:57:32 -07:00
|
|
|
| PLUS { "+" }
|
|
|
|
| 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 { ":=" }
|
|
|
|
;
|
|
|
|
constr_ident:
|
|
|
|
UIDENT { $1 }
|
1999-12-06 09:16:59 -08:00
|
|
|
/* | LBRACKET RBRACKET { "[]" } */
|
1995-05-04 03:15:53 -07:00
|
|
|
| LPAREN RPAREN { "()" }
|
|
|
|
| COLONCOLON { "::" }
|
|
|
|
| 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:
|
2000-01-24 08:21:07 -08:00
|
|
|
mod_longident { $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) }
|
|
|
|
| mod_ext_longident LPAREN mod_ext_longident RPAREN { Lapply($1, $3) }
|
|
|
|
;
|
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:
|
|
|
|
SHARP ident { Ptop_dir($2, Pdir_none) }
|
|
|
|
| SHARP ident STRING { Ptop_dir($2, Pdir_string $3) }
|
|
|
|
| SHARP ident INT { Ptop_dir($2, Pdir_int $3) }
|
|
|
|
| SHARP ident val_longident { Ptop_dir($2, Pdir_ident $3) }
|
1999-12-03 02:26:08 -08:00
|
|
|
| SHARP ident FALSE { Ptop_dir($2, Pdir_bool false) }
|
|
|
|
| SHARP ident TRUE { Ptop_dir($2, Pdir_bool true) }
|
1995-11-01 10:12:24 -08: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 }
|
|
|
|
;
|
|
|
|
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
|
|
|
;
|
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 { "-." }
|
|
|
|
;
|
1995-05-04 03:15:53 -07:00
|
|
|
%%
|