#!/usr/bin/perl5.12
####################################################################
#
#    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 Navegante;
use vars qw ( @ISA );
use strict;

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



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

    my($self)=$class->SUPER::new( yyversion => '1.05',
                                  yystates =>
[
	{#State 0
		DEFAULT => -19,
		GOTOS => {
			'actions' => 1,
			'f' => 2
		}
	},
	{#State 1
		ACTIONS => {
			"proc" => 3,
			"feedback" => 5,
			"protect" => 4,
			"save" => 6,
			"formtitle" => 7,
			"desc" => 9,
			"livefeedback" => 10,
			"proctags" => 11,
			"iform" => 12,
			"init" => 14,
			"mail" => 13,
			"annotate" => 15,
			"quit" => 16,
			'FIM' => 17,
			"iframe" => 18,
			"filename" => 19
		},
		DEFAULT => -3,
		GOTOS => {
			'fop' => 8
		}
	},
	{#State 2
		ACTIONS => {
			'' => 20
		}
	},
	{#State 3
		ACTIONS => {
			'STRING' => 21
		}
	},
	{#State 4
		ACTIONS => {
			'STRING' => 22
		}
	},
	{#State 5
		ACTIONS => {
			'STRING' => 23
		}
	},
	{#State 6
		ACTIONS => {
			'STRING' => 24
		},
		GOTOS => {
			'actarg' => 25
		}
	},
	{#State 7
		ACTIONS => {
			'STRING' => 26
		}
	},
	{#State 8
		DEFAULT => -1
	},
	{#State 9
		ACTIONS => {
			'STRING' => 27
		}
	},
	{#State 10
		ACTIONS => {
			'STRING' => 28
		}
	},
	{#State 11
		ACTIONS => {
			'STRING' => 29
		}
	},
	{#State 12
		ACTIONS => {
			'STRING' => 30
		}
	},
	{#State 13
		ACTIONS => {
			'STRING' => 24
		},
		GOTOS => {
			'actarg' => 31
		}
	},
	{#State 14
		ACTIONS => {
			'STRING' => 32
		}
	},
	{#State 15
		ACTIONS => {
			'STRING' => 33
		}
	},
	{#State 16
		ACTIONS => {
			'STRING' => 34
		}
	},
	{#State 17
		DEFAULT => -2
	},
	{#State 18
		ACTIONS => {
			'STRING' => 35
		}
	},
	{#State 19
		ACTIONS => {
			'STRING' => 36
		}
	},
	{#State 20
		DEFAULT => 0
	},
	{#State 21
		DEFAULT => -8
	},
	{#State 22
		DEFAULT => -18
	},
	{#State 23
		DEFAULT => -11
	},
	{#State 24
		ACTIONS => {
			":" => 37
		},
		DEFAULT => -20
	},
	{#State 25
		DEFAULT => -4
	},
	{#State 26
		DEFAULT => -16
	},
	{#State 27
		DEFAULT => -7
	},
	{#State 28
		DEFAULT => -10
	},
	{#State 29
		DEFAULT => -9
	},
	{#State 30
		DEFAULT => -13
	},
	{#State 31
		DEFAULT => -5
	},
	{#State 32
		DEFAULT => -6
	},
	{#State 33
		DEFAULT => -12
	},
	{#State 34
		DEFAULT => -15
	},
	{#State 35
		DEFAULT => -14
	},
	{#State 36
		DEFAULT => -17
	},
	{#State 37
		ACTIONS => {
			'ID' => 38
		}
	},
	{#State 38
		DEFAULT => -21
	}
],
                                  yyrules  =>
[
	[#Rule 0
		 '$start', 2, undef
	],
	[#Rule 1
		 'f', 2,
sub
#line 2 "lib/App/Navegante.yp"
{+{ action=>$_[1], %{$_[2]}}}
	],
	[#Rule 2
		 'fop', 1,
sub
#line 4 "lib/App/Navegante.yp"
{+{perl => $_[1]}}
	],
	[#Rule 3
		 'fop', 0,
sub
#line 4 "lib/App/Navegante.yp"
{+{}}
	],
	[#Rule 4
		 'actions', 3,
sub
#line 6 "lib/App/Navegante.yp"
{+{ %{$_[1]}, save => $_[3]}}
	],
	[#Rule 5
		 'actions', 3,
sub
#line 7 "lib/App/Navegante.yp"
{+{ %{$_[1]}, mail => $_[3]}}
	],
	[#Rule 6
		 'actions', 3,
sub
#line 8 "lib/App/Navegante.yp"
{+{ %{$_[1]}, init => $_[3]}}
	],
	[#Rule 7
		 'actions', 3,
sub
#line 9 "lib/App/Navegante.yp"
{+{ %{$_[1]}, desc => $_[3]}}
	],
	[#Rule 8
		 'actions', 3,
sub
#line 10 "lib/App/Navegante.yp"
{+{ %{$_[1]}, proc => $_[3]}}
	],
	[#Rule 9
		 'actions', 3,
sub
#line 11 "lib/App/Navegante.yp"
{+{ %{$_[1]}, proctags => $_[3]}}
	],
	[#Rule 10
		 'actions', 3,
sub
#line 12 "lib/App/Navegante.yp"
{+{ %{$_[1]}, livefeedback => $_[3]}}
	],
	[#Rule 11
		 'actions', 3,
sub
#line 13 "lib/App/Navegante.yp"
{+{ %{$_[1]}, feedback => $_[3]}}
	],
	[#Rule 12
		 'actions', 3,
sub
#line 14 "lib/App/Navegante.yp"
{+{ %{$_[1]}, annotate => $_[3]}}
	],
	[#Rule 13
		 'actions', 3,
sub
#line 15 "lib/App/Navegante.yp"
{+{ %{$_[1]}, iform => $_[3]}}
	],
	[#Rule 14
		 'actions', 3,
sub
#line 16 "lib/App/Navegante.yp"
{+{ %{$_[1]}, iframe => $_[3]}}
	],
	[#Rule 15
		 'actions', 3,
sub
#line 17 "lib/App/Navegante.yp"
{+{ %{$_[1]}, quit => $_[3]}}
	],
	[#Rule 16
		 'actions', 3,
sub
#line 18 "lib/App/Navegante.yp"
{+{ %{$_[1]}, formtitle => $_[3]}}
	],
	[#Rule 17
		 'actions', 3,
sub
#line 19 "lib/App/Navegante.yp"
{+{ %{$_[1]}, filename => $_[3]}}
	],
	[#Rule 18
		 'actions', 3,
sub
#line 20 "lib/App/Navegante.yp"
{+{ %{$_[1]}, protect => $_[3]}}
	],
	[#Rule 19
		 'actions', 0,
sub
#line 21 "lib/App/Navegante.yp"
{+{}}
	],
	[#Rule 20
		 'actarg', 1,
sub
#line 24 "lib/App/Navegante.yp"
{ +{arg=>$_[1]}}
	],
	[#Rule 21
		 'actarg', 3,
sub
#line 25 "lib/App/Navegante.yp"
{ +{arg=>$_[1], feedback => $_[3] }}
	]
],
                                  @_);
    bless($self,$class);
}

#line 28 "lib/App/Navegante.yp"


package App::Navegante;
use lib './lib/';
use CGI qw( :all :nodebug);
use Data::Dumper;
use App::Navegante::CGI;

my $File;
my $t = parseFile();

preparafiles($t->{action}) if $t->{action};
geraCgi($t);

sub preparafiles{
  my $a= shift;
  if($a->{save} && !-e $a->{save}{arg}){
      open(F,">$a->{save}{arg}") or die ("cant create $a->{save}{arg}\n");
      print F "##Created by FormLang\n";
      close F;
      chmod (0666,$a->{save}{arg})
  }
}

sub geraCgi{
    my %args = (%{$_[0]{action}}, PERL=>$_[0]{perl});
    my $t = App::Navegante::CGI->new(%args);

    if( defined $_[0]{action}{filename}) {
        open(F,">$_[0]{action}{filename}") or die ("cant create $_[0]{action}{filename}");
        print F $t->createCGI();
        close(F);
        chmod(0755,$_[0]{action}{filename});
    }
    else {
        print $t->createCGI();
    }
}

sub yyerror {
  if ($_[0]->YYCurtok) {
      printf STDERR ('Error: a "%s" (%s) was fond where %s was expected'."\n",
         $_[0]->YYCurtok, $_[0]->YYCurval, $_[0]->YYExpect)
  }
  else { print  STDERR "Expecting one of ",join(", ",$_[0]->YYExpect),"\n";
  }
}

sub parseFile {
  my $p = new Navegante();
  init_lex();
  $p->YYParse(
      yylex   => \&lex,
      yyerror => \&yyerror
  );
}

sub init_lex{
 local $/;
 undef $/;
 $File = <>
}


sub lex{
 for($File){
   s!^\s+!!;
   if($_ eq "")             {    return ("","") }
   s!^\(([^)]+)\)!!          and return("STRING",$1);
   s!^([\{\}\[\];+*/,:])!!   and return($1,$1);
   s!^\((.*?)\)!!            and return("ARG",$1);
   s!^##(.*)$!!s             and return("FIM",$1);
   s!^(init|desc|formtitle|save|mail|filename|feedback|proc|proctags|livefeedback|annotate|iform|iframe|quit|protect)\b!!
                             and return($1,$1);
   s!^(\w+)!!                and return("ID",$1);

   print STDERR "Simbolos desconhecidos '$File'\n" ;
 }
}

1;
