home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / Vars.pm < prev    next >
Encoding:
Perl POD Document  |  2002-12-31  |  2.1 KB  |  127 lines

  1. package PHP::Include::Vars;
  2. use warnings;
  3. use strict;
  4. use Filter::Simple;
  5. use Parse::RecDescent;
  6. use Data::Dumper;
  7.  
  8. our $perl = '';
  9. our $lvalue = '';
  10. our $rvalue = '';
  11. my $grammar = 
  12.  
  13. <<'GRAMMAR';
  14.  
  15. php_vars:    php_start assignment(s) php_end
  16.  
  17. php_start:    /<\?php\s*/
  18.  
  19. php_end:    /\?>/
  20.  
  21. assignment:    variable | constant
  22.  
  23. variable:    lvalue /=/ rvalue /;/
  24.         { 
  25.             $PHP::Include::Vars::perl .= 
  26.             "my $PHP::Include::Vars::lvalue = " .
  27.             "$PHP::Include::Vars::rvalue;\n"; 
  28.         }
  29.  
  30. constant:    /define\s*\(/ rvalue /,/ rvalue /\)/ /;/
  31.         { 
  32.             $PHP::Include::Vars::perl .= 
  33.             "use constant $item[2] => $item[4];\n";
  34.         }
  35.  
  36. lvalue:        /\$[a-zA-Z_][0-9a-zA-Z]*/ 
  37.         { 
  38.             $PHP::Include::Vars::lvalue = $item[1]; 
  39.         }
  40.  
  41. rvalue:        number | string | list | bareword
  42.  
  43. number:        /-?[0-9.]+/
  44.         { 
  45.             $PHP::Include::Vars::rvalue = $item[1]; 
  46.         }
  47.  
  48. string:        double_quoted | single_quoted
  49.         { 
  50.             $PHP::Include::Vars::rvalue = $item[1]; 
  51.         }
  52.  
  53. double_quoted:    /".*?"/
  54.  
  55. single_quoted:    /'.*?'/
  56.  
  57. list:        /Array\s*\(/ element(s /,/) /\s*\)/
  58.         { 
  59.             $PHP::Include::Vars::rvalue = "(" .
  60.             join( ',', @{$item[2]} ) . ")"; 
  61.         }
  62.  
  63. element:    ( associative | indexed )
  64.  
  65. associative:    rvalue /=>/ rvalue        
  66.         { 
  67.             $PHP::Include::Vars::lvalue =~ s/^\$/\%/; 
  68.             "$item[1]=>$item[3]";
  69.         }
  70.  
  71. indexed:    rvalue
  72.         { 
  73.             $PHP::Include::Vars::lvalue =~ s/^\$/\@/; 
  74.             "$item[1]";
  75.         }
  76.  
  77. bareword:    /[0-9a-zA-Z_]+/
  78.             
  79.  
  80. GRAMMAR
  81.  
  82. my $parser = Parse::RecDescent->new( $grammar );
  83.  
  84. FILTER {
  85.     $perl = '';
  86.     $parser->php_vars( $_ );
  87.     print STDERR "\n\nGENERATED PERL:\n\n", $perl, "\n\n"
  88.     if $PHP::Include::DEBUG; 
  89.     $_ = $perl;
  90. }
  91.  
  92. =head1 NAME
  93.  
  94. PHP::Include::Vars
  95.  
  96. =head1 SYNOPSIS
  97.  
  98.     use PHP::Include::Vars;
  99.     <?php
  100.     $x = Array( 1,2,3 );
  101.     ?>
  102.     no PHP::Include::Vars;
  103.  
  104. =head1 DESCRIPTION
  105.  
  106. Please see PHP::Include for details. PHP::Include::Vars is an implementation 
  107. for the include_php_vars() macro.
  108.  
  109. =head1 SEE ALSO
  110.  
  111. =over 4 
  112.  
  113. =item * PHP::Include
  114.  
  115. =item * Filter::Simple
  116.  
  117. =item * Parse::RecDescent
  118.  
  119. =head1 AUTHORS
  120.  
  121. =over 4
  122.  
  123. =item * Ed Summers <ehs@pobox.com>
  124.  
  125. =cut
  126.  
  127.