3 * Copyright (C) 2008-2009 Florian Brosch, Didier Villevalois
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Didier 'Ptitjes Villevalois <ptitjes@free.fr>
24 internal class Valadoc
.ManyRule
: Rule
{
26 public ManyRule (Object scheme
) {
30 private Object _scheme
;
32 private class State
: Object
{
33 public bool started
= false;
34 public bool done_one
= false;
37 public override bool is_optional () {
38 return is_optional_rule (_scheme
);
41 public override bool starts_with_token (Token token
) {
42 if (has_start_token (_scheme
, token
)) {
48 public override bool accept_token (Token token
, ParserCallback parser
, Rule
.Forward forward
)
51 var state
= parser
.get_rule_state () as State
;
54 parser
.set_rule_state (state
);
62 if (state
.done_one
&& parser
.would_parent_accept_token (token
)) {
66 if (parser
.would_parent_reduce_to_rule (token
, this
)) {
72 if (try_to_apply (_scheme
, token
, parser
, out handled
)) {
73 state
.done_one
= true;
76 if (parser
.would_parent_accept_token (token
)) {
81 if (_scheme is TokenType
) {
82 parser
.error (null, "expected %s".printf (((TokenType
) _scheme
).to_pretty_string ()));
84 parser
.error (token
, "unexpected token");
86 assert_not_reached ();
89 public override bool would_accept_token (Token token
, Object? state
) {
90 if (has_start_token (_scheme
, token
)) {
96 public override bool would_reduce (Token token
, Object? rule_state
) {
97 var state
= rule_state as State
;
98 return state
.done_one
|| is_optional_rule (_scheme
);
101 public override string to_string (Object? rule_state
) {
102 var state
= rule_state as State
;
104 state
= new
State ();
106 return "%-15s%-15s(started=%s;done_one=%s)".printf (name
!= null ? name
: " ",
108 state
.started
.to_string (),
109 state
.done_one
.to_string ());