~drizzle-trunk/drizzle/development

« back to all changes in this revision

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

initial import from internal tree

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package GenTest::Grammar::Rule;
 
2
use strict;
 
3
 
 
4
1;
 
5
 
 
6
use constant RULE_NAME          => 0;
 
7
use constant RULE_COMPONENTS    => 1;
 
8
 
 
9
my %args = (
 
10
        'name'          => RULE_NAME,
 
11
        'components'    => RULE_COMPONENTS
 
12
);
 
13
 
 
14
sub new {
 
15
        my $class = shift;
 
16
        my $rule = bless ([], $class);
 
17
 
 
18
        my $max_arg = (scalar(@_) / 2) - 1;
 
19
 
 
20
        foreach my $i (0..$max_arg) {
 
21
                if (exists $args{$_[$i * 2]}) {
 
22
                        $rule->[$args{$_[$i * 2]}] = $_[$i * 2 + 1];
 
23
                } else {
 
24
                        warn("Unkown argument '$_[$i * 2]' to ".$class.'->new()');
 
25
                }
 
26
        }
 
27
        return $rule;
 
28
}
 
29
 
 
30
sub name {
 
31
        return $_[0]->[RULE_NAME];
 
32
}
 
33
 
 
34
sub components {
 
35
        return $_[0]->[RULE_COMPONENTS];
 
36
}
 
37
 
 
38
sub setComponents {
 
39
        $_[0]->[RULE_COMPONENTS] = $_[1];
 
40
}
 
41
 
 
42
sub toString {
 
43
        my $rule = shift;
 
44
        my $components = $rule->components();
 
45
        return $rule->name().":\n\t".join(" |\n\t", map { join('', @$_) } @$components).";";
 
46
}
 
47
 
 
48
 
 
49
1;