1
# Copyright (C) 2008-2009 Sun Microsystems, Inc. All rights reserved.
2
# Use is subject to license terms.
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; version 2 of the License.
8
# This program is distributed in the hope that it will be useful, but
9
# WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
# General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18
package GenTest::Grammar::Rule;
23
use constant RULE_NAME => 0;
24
use constant RULE_COMPONENTS => 1;
28
'components' => RULE_COMPONENTS
33
my $rule = bless ([], $class);
35
my $max_arg = (scalar(@_) / 2) - 1;
37
foreach my $i (0..$max_arg) {
38
if (exists $args{$_[$i * 2]}) {
39
$rule->[$args{$_[$i * 2]}] = $_[$i * 2 + 1];
41
warn("Unkown argument '$_[$i * 2]' to ".$class.'->new()');
48
return $_[0]->[RULE_NAME];
52
return $_[0]->[RULE_COMPONENTS];
56
$_[0]->[RULE_COMPONENTS] = $_[1];
61
my $components = $rule->components();
62
return $rule->name().":\n\t".join(" |\n\t", map { join('', @$_) } @$components).";";