14 |
For integration with php application there is simple php config |
For integration with php application there is simple php config |
15 |
parser based on L<PHP::Include::Vars> |
parser based on L<PHP::Include::Vars> |
16 |
|
|
17 |
|
It currently ignores C<include> PHP function. |
18 |
|
|
19 |
=head1 METHODS |
=head1 METHODS |
20 |
|
|
21 |
=cut |
=cut |
22 |
|
|
23 |
my $debug = 0; |
our $debug = 0; |
24 |
|
|
25 |
our $perl = ''; |
our $perl = ''; |
26 |
our $data; |
our $data; |
34 |
|
|
35 |
php_end: /\s*\?>\s*/ |
php_end: /\s*\?>\s*/ |
36 |
|
|
37 |
statement: comment | assignment |
statement: comment | assignment | function |
38 |
|
|
39 |
|
comment: /\s*(\#|\/\/).*/ |
40 |
|
|
41 |
comment: /\s*(\#|\/\/).*/ |
function: /(include)\(.*?\)\s*;/ |
42 |
|
{ |
43 |
|
$return = "## ignored $1\n"; |
44 |
|
} |
45 |
|
|
46 |
assignment: ( var_assign | hash_assign | array_assign | constant ) /;/ |
assignment: ( var_assign | hash_assign | array_assign | constant ) /;/ |
47 |
{ |
{ |
48 |
$A3C::PHP::perl .= $item[1]; |
$A3C::PHP::perl .= $item[1]; |
49 |
} |
} |
50 |
|
|
51 |
var_assign: variable /=/ scalar |
var_assign: variable /=/ scalar |
52 |
{ |
{ |
53 |
$item[1] =~ s/^\$//; |
$item[1] =~ s/^\$//; |
54 |
$return = "\$data->{ $item[1] } = $item[3]; # scalar\n"; |
$return = "\$data->{ $item[1] } = $item[3]; # scalar\n"; |
55 |
} |
} |
56 |
|
|
57 |
hash_assign: variable /=/ /Array\s*\(/i pair(s /,/) /\s*(,\s*)?\)/ |
hash_assign: variable /=/ /Array\s*\(/i pair(s /,/) /\s*(,\s*)?\)/ |
58 |
{ |
{ |
59 |
$item[1] =~ s/^\$//; |
$item[1] =~ s/^\$//; |
60 |
$return = "\$data->{ $item[1] } = $item[4]; # hash\n"; |
$return = "\$data->{ $item[1] } = $item[4]; # hash\n"; |
61 |
$return = "\%{\$data->{ $item[1] }} =(" . join( ',', @{$item[4]} ) . ");\t# hash\n"; |
$return = "\%{\$data->{ $item[1] }} =(" . join( ',', @{$item[4]} ) . ");\t# hash\n"; |
62 |
} |
} |
63 |
|
|
64 |
array_assign: variable /=/ /Array\s*\(/i element(s /,/) /\s*(,\s*)?\)/ |
array_assign: variable /=/ /Array\s*\(/i element(s /,/) /\s*(,\s*)?\)/ |
65 |
{ |
{ |
66 |
$item[1] =~ s/^\$//; |
$item[1] =~ s/^\$//; |
67 |
$return = "\@{\$data->{ $item[1] }}=(" . join( ',', @{$item[4]} ) . ");\t# array\n" |
$return = "\@{\$data->{ $item[1] }}=(" . join( ',', @{$item[4]} ) . ");\t# array\n" |
68 |
} |
} |
69 |
|
|
70 |
scalar: string | number |
scalar: string | number | constant |
71 |
|
|
72 |
|
constant: true | false |
73 |
|
|
74 |
|
true: 'true' |
75 |
|
{ |
76 |
|
$return = '1'; |
77 |
|
} |
78 |
|
false: 'false' |
79 |
|
{ |
80 |
|
$return = '0'; |
81 |
|
} |
82 |
|
|
83 |
variable: /\$[a-zA-Z_][0-9a-zA-Z_]*/ |
variable: /\$[a-zA-Z_][0-9a-zA-Z_]*/ |
84 |
|
|
87 |
string: double_quoted | single_quoted |
string: double_quoted | single_quoted |
88 |
|
|
89 |
double_quoted: /".*?"/ |
double_quoted: /".*?"/ |
90 |
|
{ |
91 |
|
$item[1] =~ s/\@/\\\@/g; |
92 |
|
$return = $item[1]; |
93 |
|
} |
94 |
|
|
95 |
single_quoted: /'.*?'/ |
single_quoted: /'.*?'/ |
96 |
|
|
98 |
|
|
99 |
pair: scalar /=>/ ( scalar | bareword ) |
pair: scalar /=>/ ( scalar | bareword ) |
100 |
{ |
{ |
101 |
$return = $item[1] . '=>' . $item[3]; |
$return = $item[1] . '=>' . $item[3]; |
102 |
} |
} |
103 |
|
|
104 |
bareword: /[0-9a-zA-Z_]+/ |
bareword: /[0-9a-zA-Z_]+/ |
105 |
|
|
106 |
constant: /define\s*\(/ string /,/ scalar /\)/ |
constant: /define\s*\(/ string /,/ scalar /\)/ |
107 |
{ |
{ |
108 |
$return = "use constant $item[2] => $item[4];\n"; |
$return = "use constant $item[2] => $item[4];\n"; |
109 |
} |
} |
110 |
|
|
111 |
comments: /^#.*$/ |
comments: /^#.*$/ |
123 |
sub parse { |
sub parse { |
124 |
my $self = shift; |
my $self = shift; |
125 |
my $php = shift or die "no php?"; |
my $php = shift or die "no php?"; |
126 |
$perl = ''; |
$perl = ''; |
127 |
$::RD_TRACE = 1 if $debug; |
if ( $debug ) { |
128 |
|
$::RD_TRACE = 1; |
129 |
|
warn "PHP: $php\n"; |
130 |
|
} |
131 |
my $parser = Parse::RecDescent->new( $grammar ); |
my $parser = Parse::RecDescent->new( $grammar ); |
132 |
warn dump( $parser->php_vars( $php ) ); |
$parser->php_vars( $php ); |
133 |
print STDERR "\n\nGENERATED PERL:\n\n", $perl, "\n\n" if $debug; |
warn "## GENERATED PERL:\n\n", $perl, "\n\n" if $debug; |
134 |
my $data; |
my $data; |
135 |
eval $perl; |
eval $perl; |
136 |
die "$@" if $@; |
die "$@" if $@; |