line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pistachio::Token::Constructor::Perl5; |
2
|
|
|
|
|
|
|
# ABSTRACT: provides text_to_tokens(), which turns source code text into an array of Pistachio::Tokens |
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
2049
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
102
|
|
5
|
3
|
|
|
3
|
|
16
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
125
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.10'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
1918
|
use Pistachio::Keywords::Perl5 'is_keyword'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
245
|
|
9
|
3
|
|
|
3
|
|
1612
|
use Pistachio::Token; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
82
|
|
10
|
3
|
|
|
3
|
|
8886
|
use PPI::Tokenizer; |
|
3
|
|
|
|
|
342790
|
|
|
3
|
|
|
|
|
139
|
|
11
|
|
|
|
|
|
|
|
12
|
3
|
|
|
3
|
|
34
|
use Exporter 'import'; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
687
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = 'text_to_tokens'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# @param scalarref reference to text |
16
|
|
|
|
|
|
|
# @return arrayref Pistachio::Token array |
17
|
|
|
|
|
|
|
sub text_to_tokens { |
18
|
4
|
|
|
4
|
0
|
27
|
my $ppi = PPI::Tokenizer->new(shift); |
19
|
|
|
|
|
|
|
|
20
|
4
|
|
|
|
|
345
|
my @tokens; |
21
|
4
|
|
|
|
|
18
|
while (my $token = $ppi->get_token) { |
22
|
30
|
|
|
|
|
5701
|
(my $type = ref $token) =~ s/PPI::Token:://o; |
23
|
30
|
|
|
|
|
57
|
my $val = $token->{content}; |
24
|
|
|
|
|
|
|
|
25
|
30
|
100
|
|
|
|
79
|
$type eq 'Word' and do { |
26
|
6
|
|
|
|
|
26
|
my $is = is_keyword $val; |
27
|
6
|
100
|
|
|
|
25
|
$type .= '::' . ($is ? 'Reserved' : 'Defined'); |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
30
|
|
|
|
|
113
|
push @tokens, Pistachio::Token->new($type, $val); |
31
|
|
|
|
|
|
|
} |
32
|
4
|
|
|
|
|
200
|
\@tokens; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
1; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
__END__ |