| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Language::P; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
|
4
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Language::P - parsing/compiling Perl5 code using Perl5 |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSYS |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
my $p = Language::P->new_from_argv |
|
10
|
|
|
|
|
|
|
( \@ARGV, |
|
11
|
|
|
|
|
|
|
{ runtime => $runtime, |
|
12
|
|
|
|
|
|
|
generator => $generator, |
|
13
|
|
|
|
|
|
|
} ); |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
$p->run; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
An experiment: a Perl 5 parser written in Perl 5, which might in time |
|
20
|
|
|
|
|
|
|
have multiple backends. For now it only has a partial parser |
|
21
|
|
|
|
|
|
|
implementation and a toy runtime written in Perl 5. |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Time permitting it will acquire a Parrot (and Java and .Net and ... runtime). |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 METHODS |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=cut |
|
28
|
|
|
|
|
|
|
|
|
29
|
15
|
|
|
15
|
|
94
|
use strict; |
|
|
15
|
|
|
|
|
31
|
|
|
|
15
|
|
|
|
|
690
|
|
|
30
|
15
|
|
|
15
|
|
90
|
use warnings; |
|
|
15
|
|
|
|
|
29
|
|
|
|
15
|
|
|
|
|
656
|
|
|
31
|
15
|
|
|
15
|
|
83
|
use base qw(Class::Accessor::Fast); |
|
|
15
|
|
|
|
|
30
|
|
|
|
15
|
|
|
|
|
2262
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors( qw(runtime parser generator) ); |
|
34
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( qw(program program_arguments) ); |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
our $VERSION = '0.01_03'; |
|
37
|
|
|
|
|
|
|
|
|
38
|
15
|
|
|
15
|
|
11447
|
use Language::P::Parser; |
|
|
15
|
|
|
|
|
53
|
|
|
|
15
|
|
|
|
|
149
|
|
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new_from_argv |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$p = Language::P->new_from_argv( \@ARGV, |
|
43
|
|
|
|
|
|
|
{ generator => $code_generator, |
|
44
|
|
|
|
|
|
|
runtime => $runtime, |
|
45
|
|
|
|
|
|
|
} ); |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Constructs a C object, initializes it calling |
|
48
|
|
|
|
|
|
|
C passing the second argument, processes command-line |
|
49
|
|
|
|
|
|
|
arguments ten uses anything remaining in the command line as a program |
|
50
|
|
|
|
|
|
|
name and its arguments. |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub new_from_argv { |
|
55
|
15
|
|
|
15
|
1
|
49
|
my( $class, $argv, $args ) = @_; |
|
56
|
15
|
|
|
|
|
125
|
my $self = $class->SUPER::new; |
|
57
|
|
|
|
|
|
|
|
|
58
|
15
|
|
|
|
|
176
|
$self->initialize( $args ); |
|
59
|
|
|
|
|
|
|
|
|
60
|
15
|
50
|
|
|
|
106
|
if( @$argv ) { |
|
61
|
15
|
50
|
|
|
|
95
|
if( $argv->[0] =~ /^-/ ) { |
|
62
|
0
|
|
|
|
|
0
|
$argv = $self->process_command_line( $argv ); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
15
|
|
|
|
|
99
|
$self->program( $argv->[0] ); |
|
66
|
15
|
|
|
|
|
207
|
$self->program_arguments( [ @$argv[1 .. $#$argv] ] ); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
15
|
|
|
|
|
111
|
return $self; |
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub initialize { |
|
73
|
15
|
|
|
15
|
0
|
38
|
my( $self, $args ) = @_; |
|
74
|
|
|
|
|
|
|
|
|
75
|
15
|
|
|
|
|
196
|
my $parser = Language::P::Parser->new( { generator => $args->{generator}, |
|
76
|
|
|
|
|
|
|
runtime => $args->{runtime}, |
|
77
|
|
|
|
|
|
|
} ); |
|
78
|
|
|
|
|
|
|
|
|
79
|
15
|
|
|
|
|
135
|
$self->{runtime} = $args->{runtime}; |
|
80
|
15
|
|
|
|
|
51
|
$self->{generator} = $args->{generator}; |
|
81
|
15
|
|
|
|
|
69
|
$self->{parser} = $parser; |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub process_command_line { |
|
85
|
0
|
|
|
0
|
0
|
0
|
my( $self, $argv ) = @_; |
|
86
|
0
|
|
|
|
|
0
|
my @remaining; |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
0
|
for( my $i = 0; $i <= $#$argv; ++$i ) { |
|
89
|
0
|
|
|
|
|
0
|
my $arg = $argv->[$i]; |
|
90
|
|
|
|
|
|
|
|
|
91
|
0
|
0
|
|
|
|
0
|
$arg eq '--' and do { |
|
92
|
0
|
|
|
|
|
0
|
push @remaining, @{$argv}[$i + 1 .. $#$argv]; |
|
|
0
|
|
|
|
|
0
|
|
|
93
|
0
|
|
|
|
|
0
|
last; |
|
94
|
|
|
|
|
|
|
}; |
|
95
|
0
|
0
|
|
|
|
0
|
$arg =~ /^-f(\S+)/ and do { |
|
96
|
0
|
|
|
|
|
0
|
$self->parser->set_option( $1 ); |
|
97
|
0
|
|
|
|
|
0
|
$self->generator->set_option( $1 ); |
|
98
|
0
|
|
|
|
|
0
|
$self->runtime->set_option( $1 ); |
|
99
|
0
|
|
|
|
|
0
|
next; |
|
100
|
|
|
|
|
|
|
}; |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# pass through |
|
103
|
0
|
|
|
|
|
0
|
push @remaining, $arg; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
return \@remaining; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub run { |
|
110
|
15
|
|
|
15
|
0
|
38
|
my( $self ) = @_; |
|
111
|
|
|
|
|
|
|
|
|
112
|
15
|
|
|
|
|
106
|
my $code = $self->parser->parse_file( $self->program ); |
|
113
|
15
|
|
|
|
|
130
|
$self->runtime->run_last_file( $code ); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 AUTHOR |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
Mattia Barbon |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 LICENSE |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or |
|
123
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SOURCES |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
The latest sources can be found on GitHub at |
|
128
|
|
|
|
|
|
|
L |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |