gio-unix-2.0: Add DesktopAppInfo.launch_uris_as_manager_with_fds()
[vala-gnome.git] / libvaladoc / parser / manyrule.vala
blob00d928ae00ad9ad7666a4b7fc969d101d6eb03e2
1 /* manyrule.vala
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
19 * Author:
20 * Didier 'Ptitjes Villevalois <ptitjes@free.fr>
24 internal class Valadoc.ManyRule : Rule {
26 public ManyRule (Object scheme) {
27 _scheme = 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)) {
43 return true;
45 return false;
48 public override bool accept_token (Token token, ParserCallback parser, Rule.Forward forward)
49 throws ParserError
51 var state = parser.get_rule_state () as State;
52 if (state == null) {
53 state = new State ();
54 parser.set_rule_state (state);
57 if (!state.started) {
58 do_start (parser);
59 state.started = true;
62 if (state.done_one && parser.would_parent_accept_token (token)) {
63 do_reduce (parser);
64 return false;
66 if (parser.would_parent_reduce_to_rule (token, this)) {
67 do_reduce (parser);
68 return false;
71 bool handled;
72 if (try_to_apply (_scheme, token, parser, out handled)) {
73 state.done_one = true;
74 return handled;
76 if (parser.would_parent_accept_token (token)) {
77 do_reduce (parser);
78 return false;
81 if (_scheme is TokenType) {
82 parser.error (null, "expected %s".printf (((TokenType) _scheme).to_pretty_string ()));
83 } else {
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)) {
91 return true;
93 return false;
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;
103 if (state == null) {
104 state = new State ();
106 return "%-15s%-15s(started=%s;done_one=%s)".printf (name != null ? name : " ",
107 "[many]",
108 state.started.to_string (),
109 state.done_one.to_string ());