####################################################################
#
#    This file was generated using Parse::Yapp version 1.05.
#
#        Don't edit this file, use source file instead.
#
#             ANY CHANGE MADE HERE WILL BE LOST !
#
####################################################################
package objects;
use vars qw ( @ISA );
use strict;

@ISA= qw ( Parse::Yapp::Driver );
use Parse::Yapp::Driver;

#line 31 "dist/pica-0.4.1/objects.yp"

use Data::Dumper;
my %attributes;
my %alarmattributes;
my @currentgroup;
my (%vars, %groupvars);

use vars qw($objref $currentline);

*objref = *main::objref;
$currentline = 1;

my @objectattrs = ('uid', 'gid', 'perms', 'verbatim', 'path', 'source', 'priority');


sub new {
        my($class)=shift;
        ref($class)
    and $class=ref($class);

    my($self)=$class->SUPER::new( yyversion => '1.05',
                                  yystates =>
[
	{#State 0
		ACTIONS => {
			"file" => 2,
			"alarm" => 1,
			"defaults" => 4,
			"group" => 10
		},
		GOTOS => {
			'statements' => 3,
			'group' => 5,
			'statement' => 6,
			'object' => 7,
			'alarm' => 8,
			'defaults' => 9,
			'config_file' => 11,
			'file' => 12
		}
	},
	{#State 1
		ACTIONS => {
			'DQUOTED' => 13,
			'WORD' => 14,
			'SQUOTED' => 15
		},
		GOTOS => {
			'literal' => 16
		}
	},
	{#State 2
		ACTIONS => {
			'DQUOTED' => 13,
			'WORD' => 14,
			'SQUOTED' => 15
		},
		GOTOS => {
			'literal' => 17
		}
	},
	{#State 3
		ACTIONS => {
			"file" => 2,
			"alarm" => 1,
			"defaults" => 4,
			"group" => 10
		},
		DEFAULT => -1,
		GOTOS => {
			'object' => 7,
			'defaults' => 9,
			'alarm' => 8,
			'group' => 5,
			'statement' => 18,
			'file' => 12
		}
	},
	{#State 4
		ACTIONS => {
			"{" => 19
		}
	},
	{#State 5
		DEFAULT => -6
	},
	{#State 6
		DEFAULT => -2
	},
	{#State 7
		DEFAULT => -5
	},
	{#State 8
		DEFAULT => -27
	},
	{#State 9
		DEFAULT => -4
	},
	{#State 10
		ACTIONS => {
			'DQUOTED' => 13,
			'WORD' => 14,
			'SQUOTED' => 15
		},
		GOTOS => {
			'literal' => 20
		}
	},
	{#State 11
		ACTIONS => {
			'' => 21
		}
	},
	{#State 12
		DEFAULT => -26
	},
	{#State 13
		DEFAULT => -38
	},
	{#State 14
		DEFAULT => -36
	},
	{#State 15
		DEFAULT => -37
	},
	{#State 16
		DEFAULT => -9,
		GOTOS => {
			'@1-2' => 22
		}
	},
	{#State 17
		ACTIONS => {
			"{" => 23
		}
	},
	{#State 18
		DEFAULT => -3
	},
	{#State 19
		DEFAULT => -28,
		GOTOS => {
			'attributes' => 24
		}
	},
	{#State 20
		DEFAULT => -20,
		GOTOS => {
			'@4-2' => 25
		}
	},
	{#State 21
		DEFAULT => -0
	},
	{#State 22
		ACTIONS => {
			"{" => 26
		}
	},
	{#State 23
		DEFAULT => -28,
		GOTOS => {
			'attributes' => 27
		}
	},
	{#State 24
		ACTIONS => {
			'WORD' => 29,
			"}" => 31,
			"vars" => 32
		},
		GOTOS => {
			'attribute' => 28,
			'vars_env' => 30
		}
	},
	{#State 25
		ACTIONS => {
			"{" => 33
		}
	},
	{#State 26
		DEFAULT => -11,
		GOTOS => {
			'alarm_attributes' => 34
		}
	},
	{#State 27
		ACTIONS => {
			'WORD' => 29,
			"}" => 35,
			"vars" => 32
		},
		GOTOS => {
			'attribute' => 28,
			'vars_env' => 30
		}
	},
	{#State 28
		DEFAULT => -30
	},
	{#State 29
		ACTIONS => {
			"=" => 36
		}
	},
	{#State 30
		DEFAULT => -29
	},
	{#State 31
		DEFAULT => -7
	},
	{#State 32
		ACTIONS => {
			"{" => 37
		}
	},
	{#State 33
		DEFAULT => -22,
		GOTOS => {
			'group_attributes' => 38
		}
	},
	{#State 34
		ACTIONS => {
			'WORD' => 29,
			"uses" => 42,
			"}" => 43,
			"vars" => 32
		},
		GOTOS => {
			'attribute' => 39,
			'vars_env' => 41,
			'uses_env' => 40
		}
	},
	{#State 35
		DEFAULT => -8
	},
	{#State 36
		ACTIONS => {
			'DQUOTED' => 13,
			'WORD' => 14,
			'SQUOTED' => 15
		},
		GOTOS => {
			'literal' => 44
		}
	},
	{#State 37
		DEFAULT => -33,
		GOTOS => {
			'vars' => 45
		}
	},
	{#State 38
		ACTIONS => {
			"file" => 2,
			"alarm" => 1,
			'WORD' => 29,
			"}" => 49,
			"vars" => 32
		},
		GOTOS => {
			'object' => 47,
			'attribute' => 46,
			'alarm' => 8,
			'vars_env' => 48,
			'file' => 12
		}
	},
	{#State 39
		DEFAULT => -12
	},
	{#State 40
		DEFAULT => -14
	},
	{#State 41
		DEFAULT => -13
	},
	{#State 42
		ACTIONS => {
			"{" => 50
		}
	},
	{#State 43
		DEFAULT => -10
	},
	{#State 44
		ACTIONS => {
			";" => 51
		}
	},
	{#State 45
		ACTIONS => {
			'WORD' => 53,
			"}" => 54
		},
		GOTOS => {
			'var' => 52
		}
	},
	{#State 46
		DEFAULT => -24
	},
	{#State 47
		DEFAULT => -23
	},
	{#State 48
		DEFAULT => -25
	},
	{#State 49
		DEFAULT => -21
	},
	{#State 50
		DEFAULT => -15,
		GOTOS => {
			'@2-2' => 55
		}
	},
	{#State 51
		DEFAULT => -31
	},
	{#State 52
		DEFAULT => -34
	},
	{#State 53
		ACTIONS => {
			"=" => 56
		}
	},
	{#State 54
		DEFAULT => -32
	},
	{#State 55
		DEFAULT => -18,
		GOTOS => {
			'deps' => 57
		}
	},
	{#State 56
		ACTIONS => {
			'DQUOTED' => 13,
			'WORD' => 14,
			'SQUOTED' => 15
		},
		GOTOS => {
			'literal' => 58
		}
	},
	{#State 57
		ACTIONS => {
			"file" => 2
		},
		DEFAULT => -16,
		GOTOS => {
			'@3-4' => 60,
			'file' => 59
		}
	},
	{#State 58
		ACTIONS => {
			";" => 61
		}
	},
	{#State 59
		DEFAULT => -19
	},
	{#State 60
		ACTIONS => {
			"}" => 62
		}
	},
	{#State 61
		DEFAULT => -35
	},
	{#State 62
		DEFAULT => -17
	}
],
                                  yyrules  =>
[
	[#Rule 0
		 '$start', 2, undef
	],
	[#Rule 1
		 'config_file', 1,
sub
#line 49 "dist/pica-0.4.1/objects.yp"
{
         return 'ok';
      }
	],
	[#Rule 2
		 'statements', 1, undef
	],
	[#Rule 3
		 'statements', 2, undef
	],
	[#Rule 4
		 'statement', 1, undef
	],
	[#Rule 5
		 'statement', 1, undef
	],
	[#Rule 6
		 'statement', 1, undef
	],
	[#Rule 7
		 'defaults', 4,
sub
#line 64 "dist/pica-0.4.1/objects.yp"
{
         $objref->{'defaults'} = { %attributes };
         %attributes = ();
      }
	],
	[#Rule 8
		 'file', 5,
sub
#line 74 "dist/pica-0.4.1/objects.yp"
{
         $attributes{'type'} = 'file';
         if (scalar @currentgroup) {
            push @{$currentgroup[0]}, $_[2];
            $attributes{'group'} = ${$currentgroup[0]}[0];
         }
         # Check if already exists!
         die "Duplicated object '$_[2]' in line ", $currentline, "\n"
               if exists $objref->{$_[2]};
         $objref->{$_[2]} = { %attributes };
         %attributes = ();
      }
	],
	[#Rule 9
		 '@1-2', 0,
sub
#line 91 "dist/pica-0.4.1/objects.yp"
{ unshift @currentgroup, [ ($_[2]) ]; }
	],
	[#Rule 10
		 'alarm', 6,
sub
#line 93 "dist/pica-0.4.1/objects.yp"
{
         $attributes{'type'} = 'alarm';
         # Add all the members to the 'members' attribute and delete the
         # temporary list
         $attributes{'members'} = [ @{$currentgroup[0]}[1 .. 
	                            $#{$currentgroup[0]}] ];
         shift @currentgroup;
         # Add ourselves to the current group, if any
         if (scalar @currentgroup) {
            push @{$currentgroup[0]}, $_[2];
            $attributes{'group'} = ${$currentgroup[0]}[0];
         }
         # Check if already exists!
         die "Duplicated alarm '$_[2]' in line ", $currentline, "\n"
               if exists $objref->{$_[2]};
         # Add the alarm entry to $objref
         $objref->{$_[2]} = { %attributes };
         %attributes = ();
      }
	],
	[#Rule 11
		 'alarm_attributes', 0, undef
	],
	[#Rule 12
		 'alarm_attributes', 2, undef
	],
	[#Rule 13
		 'alarm_attributes', 2, undef
	],
	[#Rule 14
		 'alarm_attributes', 2, undef
	],
	[#Rule 15
		 '@2-2', 0,
sub
#line 121 "dist/pica-0.4.1/objects.yp"
{ %alarmattributes = %attributes;
                             %attributes = (); }
	],
	[#Rule 16
		 '@3-4', 0,
sub
#line 123 "dist/pica-0.4.1/objects.yp"
{ %attributes = %alarmattributes;
                             %alarmattributes = (); }
	],
	[#Rule 17
		 'uses_env', 6, undef
	],
	[#Rule 18
		 'deps', 0, undef
	],
	[#Rule 19
		 'deps', 2, undef
	],
	[#Rule 20
		 '@4-2', 0,
sub
#line 135 "dist/pica-0.4.1/objects.yp"
{ unshift @currentgroup, [ ($_[2]) ]; }
	],
	[#Rule 21
		 'group', 6,
sub
#line 137 "dist/pica-0.4.1/objects.yp"
{
         $attributes{'vars'} = { %groupvars };
         $attributes{'type'} = 'group';
         # The group is ended. Store all the members (the second to last
         # elements, first is the group name) in the attribute 'members', and
         # delete the members list
         $attributes{'members'} = [ @{$currentgroup[0]}[1 .. 
	                            $#{$currentgroup[0]}] ];
         shift @currentgroup;
         # If there is any group out there, add ourselves to its member list
         if (scalar @currentgroup) {
            push @{$currentgroup[0]}, $_[2];
            $attributes{'group'} = ${$currentgroup[0]}[0];
         }
         # Check if already exists!
         die "Duplicated group '$_[2]' in line ", $currentline, "\n"
               if exists $objref->{$_[2]};
         # Add group entry to $objref
         $objref->{$_[2]} = { %attributes };
         %attributes = ();
         %groupvars = ();
      }
	],
	[#Rule 22
		 'group_attributes', 0, undef
	],
	[#Rule 23
		 'group_attributes', 2, undef
	],
	[#Rule 24
		 'group_attributes', 2, undef
	],
	[#Rule 25
		 'group_attributes', 2,
sub
#line 165 "dist/pica-0.4.1/objects.yp"
{
         %groupvars = %{ $attributes{'vars'} };
         delete $attributes{'vars'};
      }
	],
	[#Rule 26
		 'object', 1, undef
	],
	[#Rule 27
		 'object', 1, undef
	],
	[#Rule 28
		 'attributes', 0, undef
	],
	[#Rule 29
		 'attributes', 2, undef
	],
	[#Rule 30
		 'attributes', 2, undef
	],
	[#Rule 31
		 'attribute', 4,
sub
#line 181 "dist/pica-0.4.1/objects.yp"
{
         grep /^$_[1]$/, @objectattrs or die "Unkown object property $_[1]\n";
         $attributes{$_[1]} = $_[3];
      }
	],
	[#Rule 32
		 'vars_env', 4,
sub
#line 188 "dist/pica-0.4.1/objects.yp"
{
         # print 'variables ', $_[1], "\n";
	 $attributes{'vars'} = { %vars };
	 %vars = ();
      }
	],
	[#Rule 33
		 'vars', 0, undef
	],
	[#Rule 34
		 'vars', 2, undef
	],
	[#Rule 35
		 'var', 4,
sub
#line 200 "dist/pica-0.4.1/objects.yp"
{
         $vars{$_[1]} = $_[3];
      }
	],
	[#Rule 36
		 'literal', 1, undef
	],
	[#Rule 37
		 'literal', 1, undef
	],
	[#Rule 38
		 'literal', 1, undef
	]
],
                                  @_);
    bless($self,$class);
}

#line 210 "dist/pica-0.4.1/objects.yp"


use vars   qw($inputfile);

sub _Error {
        exists $_[0]->YYData->{ERRMSG}
    and do {
        print $_[0]->YYData->{ERRMSG};
        delete $_[0]->YYData->{ERRMSG};
        die;
    };
    print STDERR "Syntax error reading objects file at line ", $currentline, ": expecting ";
    # Expected tokens
    my @exptoks;
    foreach my $i ($_[0]->YYExpect) {
       push @exptoks, tokname($i);
    }
    if (scalar @exptoks > 1) {
       print STDERR "one of ", join (',', @exptoks), ", ";
    } else {
       print STDERR $exptoks[0], ', ';
    }
    # Found token
    print STDERR "found ", tokname($_[0]->YYCurtok), ".\n";
}

sub tokname {
   my $token = shift ;

   if ($token eq 'SQUOTED') {
      return 'single quote';
   } elsif ($token eq 'DQUOTED') {
      return 'double quote';
   } elsif ($token eq 'WORD') {
      return 'word';
   }

   return "'$token'";
}

sub _Lexer {
   my $parser = shift;

   if (! $parser->YYData->{INPUT}) {
      if ($inputfile) {
         open F, $inputfile or die "Can't open config file $inputfile";
         $inputfile = "";
      }

      $parser->YYData->{INPUT} or $parser->YYData->{INPUT} = join '', <F>
         or return ('', undef);
   }

   while ($parser->YYData->{INPUT} =~ /^[ \t\n]+/ or
		   $parser->YYData->{INPUT} =~ /^#.*/) {
	   $parser->YYData->{INPUT} =~ s/^(\n+)//;
	   $currentline += length ($1);
	   $parser->YYData->{INPUT} =~ s/^[ \t]+//;
	   $parser->YYData->{INPUT} =~ s/^#.*//;
   }

   for ($parser->YYData->{INPUT}) {
      if (s:^((\w|/|\.|-)+)::) {
         ($1 eq 'defaults') and return ('defaults', 'defaults');
         ($1 eq 'file') and return ('file', 'file');
         ($1 eq 'alarm') and return ('alarm', 'alarm');
         ($1 eq 'group') and return ('group', 'group');
         ($1 eq 'vars') and return ('vars', 'vars');
         ($1 eq 'uses') and return ('uses', 'uses');
         return ('WORD', $1);
      }
      s/^"(([^"]|\\")*)"//
         and return ('DQUOTED', $1);
      s/^'(([^']|\\')*)'//
         and return ('SQUOTED', $1);
      s/^(.)//
         and return($1,$1);
   }
}

sub fillObjRef {
   my $self;
   ($self, $inputfile) = (shift, shift);

   return ($self->YYParse (yylex => \&_Lexer, yyerror => \&_Error))?1:0;
}

1;
