1 /**************************************************************************/
5 /* François Pottier, INRIA Rocquencourt */
6 /* Yann Régis-Gianas, PPS, Université Paris Diderot */
8 /* Copyright 2005-2008 Institut National de Recherche en Informatique */
9 /* et en Automatique. All rights reserved. This file is distributed */
10 /* under the terms of the GNU Library General Public License, with the */
11 /* special exception on linking described in file LICENSE. */
13 /**************************************************************************/
15 (* This is menhir's standard library. It offers a number of
16 parameterized nonterminal definitions, such as options and lists,
17 that should be useful in a number of circumstances. *)
21 (* ------------------------------------------------------------------------- *)
24 (* [option(X)] recognizes either nothing or [X]. It produces a value
25 of type ['a option] if [X] produces a value of type ['a]. *)
33 (* [ioption(X)] is identical to [option(X)], except its definition is
34 inlined. This has the effect of duplicating the production that
35 refers to it, possibly eliminating an LR(1) conflict. *)
37 %public %inline ioption(X):
43 (* [boption(X)] recognizes either nothing or [X]. It produces a value
52 (* [loption(X)] recognizes either nothing or [X]. It produces a value
53 of type ['a list] if [X] produces a value of type ['a list]. *)
61 (* ------------------------------------------------------------------------- *)
64 (* [pair(X, Y)] recognizes the sequence [X Y]. It produces a value of
65 type ['a * 'b] if [X] and [Y] produce values of type ['a] and ['b],
68 %public %inline pair(X, Y):
72 (* [separated_pair(X, sep, Y)] recognizes the sequence [X sep Y]. It
73 produces a value of type ['a * 'b] if [X] and [Y] produce values of
74 type ['a] and ['b], respectively. *)
76 %public %inline separated_pair(X, sep, Y):
80 (* [preceded(opening, X)] recognizes the sequence [opening X]. It
81 passes on the value produced by [X], so that it produces a value of
82 type ['a] if [X] produces a value of type ['a]. *)
84 %public %inline preceded(opening, X):
88 (* [terminated(X, closing)] recognizes the sequence [X closing]. It
89 passes on the value produced by [X], so that it produces a value of
90 type ['a] if [X] produces a value of type ['a]. *)
92 %public %inline terminated(X, closing):
96 (* [delimited(opening, X, closing)] recognizes the sequence [opening X
97 closing]. It passes on the value produced by [X], so that it
98 produces a value of type ['a] if [X] produces a value of type
101 %public %inline delimited(opening, X, closing):
102 opening; x = X; closing
105 (* ------------------------------------------------------------------------- *)
108 (* [list(X)] recognizes a possibly empty list of [X]'s. It produces a
109 value of type ['a list] if [X] produces a value of type ['a]. The
110 front element of the list is the first element that was parsed. *)
115 | x = X; xs = list(X)
118 (* [nonempty_list(X)] recognizes a nonempty list of [X]'s. It produces
119 a value of type ['a list] if [X] produces a value of type ['a]. The
120 front element of the list is the first element that was parsed. *)
122 %public nonempty_list(X):
125 | x = X; xs = nonempty_list(X)
128 (* [separated_list(separator, X)] recognizes a possibly empty list of
129 [X]'s, separated with [separator]'s. It produces a value of type
130 ['a list] if [X] produces a value of type ['a]. The front element
131 of the list is the first element that was parsed. *)
133 %public %inline separated_list(separator, X):
134 xs = loption(separated_nonempty_list(separator, X))
137 (* [separated_nonempty_list(separator, X)] recognizes a nonempty list
138 of [X]'s, separated with [separator]'s. It produces a value of type
139 ['a list] if [X] produces a value of type ['a]. The front element
140 of the list is the first element that was parsed. *)
142 %public separated_nonempty_list(separator, X):
145 | x = X; separator; xs = separated_nonempty_list(separator, X)