line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Pistachio::Token::Transformer::Perl5; |
2
|
|
|
|
|
|
|
# ABSTRACT: provides transform_rules(), which returns an array of Pistachio::Token::Transformer::Rules |
3
|
|
|
|
|
|
|
|
4
|
3
|
|
|
3
|
|
2524
|
use strict; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
108
|
|
5
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
139
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.10'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
1895
|
use Pistachio::Token::Transformer::Rule; |
|
3
|
|
|
|
|
43
|
|
|
3
|
|
|
|
|
105
|
|
9
|
3
|
|
|
3
|
|
21
|
use Exporter 'import'; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
5182
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = 'transform_rules'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# @return arrayref Pistachio::Token::Transformer::Rules |
13
|
|
|
|
|
|
|
sub transform_rules { |
14
|
23
|
|
|
23
|
0
|
27
|
my @rules; |
15
|
|
|
|
|
|
|
|
16
|
23
|
|
|
|
|
141
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
17
|
|
|
|
|
|
|
type => 'Word', |
18
|
|
|
|
|
|
|
prec => [['Word::Reserved', 'package']], |
19
|
|
|
|
|
|
|
succ => [['Structure', ';']], |
20
|
|
|
|
|
|
|
into => 'Word::Package', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
23
|
|
|
|
|
131
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
24
|
|
|
|
|
|
|
type => 'Word', |
25
|
|
|
|
|
|
|
prec => [['Word::Reserved', 'use']], |
26
|
|
|
|
|
|
|
succ => [['Structure', ';']], |
27
|
|
|
|
|
|
|
into => 'Word::Use', |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
23
|
|
|
|
|
130
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
31
|
|
|
|
|
|
|
type => 'Word', |
32
|
|
|
|
|
|
|
prec => [['Word::Reserved', 'require']], |
33
|
|
|
|
|
|
|
succ => [['Structure', ';']], |
34
|
|
|
|
|
|
|
into => 'Word::Require', |
35
|
|
|
|
|
|
|
); |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
38
|
|
|
|
|
|
|
type => 'Word::Reserved', |
39
|
|
|
|
|
|
|
val => sub { |
40
|
4
|
|
|
4
|
|
9
|
my $keyword = '^(use|require|sub|my|our|new|last|' |
41
|
|
|
|
|
|
|
. 'next|redo|if|else|elsif|do|unless)$'; |
42
|
4
|
|
|
|
|
142
|
shift =~ /$keyword/o |
43
|
|
|
|
|
|
|
}, |
44
|
23
|
|
|
|
|
126
|
into => 'Word::Reserved::Keyword', |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
48
|
|
|
|
|
|
|
type => 'Word::Reserved', |
49
|
|
|
|
|
|
|
val => sub { |
50
|
4
|
|
|
4
|
|
7
|
my $speclit = '^__(FILE|LINE|PACKAGE|SUB|DATA|END)__$'; |
51
|
4
|
|
|
|
|
78
|
shift =~ /$speclit/o |
52
|
|
|
|
|
|
|
}, |
53
|
23
|
|
|
|
|
115
|
into => 'Word::Special::Literal', |
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
|
56
|
23
|
|
|
|
|
104
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
57
|
|
|
|
|
|
|
type => 'Word', |
58
|
|
|
|
|
|
|
prec => [['Word::Reserved', 'sub']], |
59
|
|
|
|
|
|
|
into => 'Word::Sub::Define', |
60
|
|
|
|
|
|
|
); |
61
|
|
|
|
|
|
|
|
62
|
23
|
|
|
|
|
105
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
63
|
|
|
|
|
|
|
type => 'Word::Defined', |
64
|
|
|
|
|
|
|
succ => [['Structure', '(']], |
65
|
|
|
|
|
|
|
into => 'Word::Sub::Invoke', |
66
|
|
|
|
|
|
|
); |
67
|
|
|
|
|
|
|
|
68
|
23
|
|
|
|
|
124
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
69
|
|
|
|
|
|
|
type => 'Word', |
70
|
|
|
|
|
|
|
prec => [['Operator::Dereference', '->']], |
71
|
|
|
|
|
|
|
succ => [['Structure', '(']], |
72
|
|
|
|
|
|
|
into => 'Word::Coderef::Invoke', |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
23
|
|
|
|
|
107
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
76
|
|
|
|
|
|
|
type => 'Word::Defined', |
77
|
|
|
|
|
|
|
succ => [['Operator', '=>']], |
78
|
|
|
|
|
|
|
into => 'Word::Hashkey', |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
23
|
|
|
|
|
156
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
82
|
|
|
|
|
|
|
type => 'Word::Defined', |
83
|
|
|
|
|
|
|
prec => [['Word::Reserved::Keyword', 'use'], |
84
|
|
|
|
|
|
|
['Word::Defined', 'constant']], |
85
|
|
|
|
|
|
|
succ => [['Operator', '=>']], |
86
|
|
|
|
|
|
|
into => 'Word::Constant', |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
2
|
|
14
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
90
|
|
|
|
|
|
|
type => 'Word::Defined', |
91
|
|
|
|
|
|
|
val => sub {shift eq 'lib'}, |
92
|
23
|
|
|
|
|
117
|
into => 'Word::Reserved', |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
0
|
|
0
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
96
|
|
|
|
|
|
|
type => 'Magic', |
97
|
|
|
|
|
|
|
val => sub {shift eq '@_'}, |
98
|
23
|
|
|
|
|
112
|
into => 'Magic::These', |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
0
|
|
0
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
102
|
|
|
|
|
|
|
type => 'Magic', |
103
|
|
|
|
|
|
|
val => sub {shift eq '$_'}, |
104
|
23
|
|
|
|
|
106
|
into => 'Magic::This', |
105
|
|
|
|
|
|
|
); |
106
|
|
|
|
|
|
|
|
107
|
2
|
|
|
2
|
|
14
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
108
|
|
|
|
|
|
|
type => 'Operator', |
109
|
|
|
|
|
|
|
val => sub {shift eq '->'}, |
110
|
23
|
|
|
|
|
110
|
into => 'Operator::Dereference', |
111
|
|
|
|
|
|
|
); |
112
|
|
|
|
|
|
|
|
113
|
2
|
|
|
2
|
|
18
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
114
|
|
|
|
|
|
|
type => 'Operator', |
115
|
|
|
|
|
|
|
val => sub {shift =~ /^[\w\-]+$/}, |
116
|
23
|
|
|
|
|
108
|
into => 'Operator::Wordish', |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
0
|
|
0
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
120
|
|
|
|
|
|
|
type => 'Cast', |
121
|
|
|
|
|
|
|
val => sub {shift eq '\\'}, |
122
|
23
|
|
|
|
|
106
|
into => 'Cast::Reference', |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
|
125
|
2
|
|
|
2
|
|
17
|
push @rules, Pistachio::Token::Transformer::Rule->new( |
126
|
|
|
|
|
|
|
type => 'Symbol', |
127
|
|
|
|
|
|
|
val => sub {shift =~ /^&/}, |
128
|
23
|
|
|
|
|
107
|
into => 'Symbol::Sub' |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
|
131
|
23
|
|
|
|
|
94
|
\@rules; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
__END__ |