~ubuntu-branches/ubuntu/saucy/drizzle/saucy-proposed

« back to all changes in this revision

Viewing changes to tests/randgen/lib/GenTest/Grammar/Rule.pm

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008-2009 Sun Microsystems, Inc. All rights reserved.
 
2
# Use is subject to license terms.
 
3
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
# USA
 
17
 
 
18
package GenTest::Grammar::Rule;
 
19
use strict;
 
20
 
 
21
1;
 
22
 
 
23
use constant RULE_NAME          => 0;
 
24
use constant RULE_COMPONENTS    => 1;
 
25
 
 
26
my %args = (
 
27
        'name'          => RULE_NAME,
 
28
        'components'    => RULE_COMPONENTS
 
29
);
 
30
 
 
31
sub new {
 
32
        my $class = shift;
 
33
        my $rule = bless ([], $class);
 
34
 
 
35
        my $max_arg = (scalar(@_) / 2) - 1;
 
36
 
 
37
        foreach my $i (0..$max_arg) {
 
38
                if (exists $args{$_[$i * 2]}) {
 
39
                        $rule->[$args{$_[$i * 2]}] = $_[$i * 2 + 1];
 
40
                } else {
 
41
                        warn("Unkown argument '$_[$i * 2]' to ".$class.'->new()');
 
42
                }
 
43
        }
 
44
        return $rule;
 
45
}
 
46
 
 
47
sub name {
 
48
        return $_[0]->[RULE_NAME];
 
49
}
 
50
 
 
51
sub components {
 
52
        return $_[0]->[RULE_COMPONENTS];
 
53
}
 
54
 
 
55
sub setComponents {
 
56
        $_[0]->[RULE_COMPONENTS] = $_[1];
 
57
}
 
58
 
 
59
sub toString {
 
60
        my $rule = shift;
 
61
        my $components = $rule->components();
 
62
        return $rule->name().":\n\t".join(" |\n\t", map { join('', @$_) } @$components).";";
 
63
}
 
64
 
 
65
 
 
66
1;