line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Devel::Declare::Lexer::Factory; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1651
|
use Devel::Declare::Lexer::Stream; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
4
|
2
|
|
|
2
|
|
1241
|
use Devel::Declare::Lexer::Tokens; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
65
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
31
|
use v5; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
176
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our (@ISA, @EXPORT_OK, %EXPORT_TAGS); |
9
|
|
|
|
|
|
|
BEGIN { |
10
|
2
|
|
|
2
|
|
12
|
use Exporter; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
190
|
|
11
|
2
|
|
|
2
|
|
35
|
@ISA = qw(Exporter); |
12
|
2
|
|
|
|
|
8
|
@EXPORT_OK = qw( _stream _statement _reference _variable _string _var_assign _list _keypair _if _return _bareword _block _sub _whitespace _operator ); |
13
|
2
|
|
|
|
|
7629
|
%EXPORT_TAGS = ( |
14
|
|
|
|
|
|
|
'all' => \@EXPORT_OK |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _stream |
19
|
|
|
|
|
|
|
{ |
20
|
5
|
|
|
5
|
|
8
|
my ($old_stream, $new_stream) = @_; |
21
|
5
|
|
|
|
|
9
|
my @stream = (); |
22
|
5
|
|
|
|
|
27
|
tie @stream, 'Devel::Declare::Lexer::Stream'; |
23
|
|
|
|
|
|
|
|
24
|
5
|
100
|
|
|
|
35
|
if($old_stream) { |
25
|
4
|
|
|
|
|
22
|
push @stream, shift @$old_stream; # declarator |
26
|
4
|
|
|
|
|
38
|
push @stream, shift @$old_stream; # whitespace |
27
|
|
|
|
|
|
|
} |
28
|
5
|
50
|
|
|
|
32
|
if($new_stream) { |
29
|
5
|
|
|
|
|
17
|
push @stream, @$new_stream; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
5
|
|
|
|
|
58
|
return @stream; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub _statement |
36
|
|
|
|
|
|
|
{ |
37
|
7
|
|
|
7
|
|
11
|
my ($tokens) = @_; |
38
|
7
|
|
|
|
|
11
|
my @t = (); |
39
|
7
|
|
|
|
|
26
|
push @t, @$tokens; |
40
|
7
|
|
|
|
|
26
|
push @t, new Devel::Declare::Lexer::Token::EndOfStatement; |
41
|
7
|
|
|
|
|
39
|
return @t; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _reference |
45
|
|
|
|
|
|
|
{ |
46
|
0
|
|
|
0
|
|
0
|
my ($refto) = @_; |
47
|
0
|
|
|
|
|
0
|
my @tokens = (); |
48
|
0
|
|
|
|
|
0
|
push @tokens, new Devel::Declare::Lexer::Token::Operator( value => '\\' ); |
49
|
0
|
|
|
|
|
0
|
push @tokens, @$refto; |
50
|
0
|
|
|
|
|
0
|
return @tokens; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _operator |
54
|
|
|
|
|
|
|
{ |
55
|
1
|
|
|
1
|
|
3
|
my ($operator) = @_; |
56
|
1
|
|
|
|
|
12
|
return ( new Devel::Declare::Lexer::Token::Operator( value => $operator ) ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _variable |
60
|
|
|
|
|
|
|
{ |
61
|
11
|
|
|
11
|
|
26
|
my ($sigil, $name) = @_; |
62
|
11
|
|
|
|
|
17
|
my @tokens = (); |
63
|
11
|
|
|
|
|
25
|
while($sigil) { |
64
|
11
|
|
|
|
|
51
|
push @tokens, new Devel::Declare::Lexer::Token::Variable( value => substr($sigil, 0, 1) ); |
65
|
11
|
|
|
|
|
37
|
$sigil = substr($sigil, 1); |
66
|
|
|
|
|
|
|
} |
67
|
11
|
|
|
|
|
48
|
push @tokens, new Devel::Declare::Lexer::Token::Bareword( value => $name ); |
68
|
11
|
|
|
|
|
55
|
return @tokens; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub _bareword |
72
|
|
|
|
|
|
|
{ |
73
|
5
|
|
|
5
|
|
7615
|
my ($word) = @_; |
74
|
5
|
|
|
|
|
21
|
return ( new Devel::Declare::Lexer::Token::Bareword( value => $word ) ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _string |
78
|
|
|
|
|
|
|
{ |
79
|
1
|
|
|
1
|
|
3
|
my ($type, $value) = @_; |
80
|
1
|
|
|
|
|
6
|
return ( new Devel::Declare::Lexer::Token::String( start => $type, end => $type, value => $value ) ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _var_assign |
84
|
|
|
|
|
|
|
{ |
85
|
5
|
|
|
5
|
|
8
|
my ($var, $value) = @_; |
86
|
5
|
|
|
|
|
10
|
my @tokens = (); |
87
|
5
|
|
|
|
|
1370
|
push @tokens, @$var; |
88
|
5
|
|
|
|
|
19
|
push @tokens, new Devel::Declare::Lexer::Token::Whitespace( value => ' ' ); |
89
|
5
|
|
|
|
|
22
|
push @tokens, new Devel::Declare::Lexer::Token::Operator( value => '=' ); |
90
|
5
|
|
|
|
|
15
|
push @tokens, new Devel::Declare::Lexer::Token::Whitespace( value => ' ' ); |
91
|
5
|
100
|
|
|
|
19
|
if(ref($value) =~ /ARRAY/) { |
92
|
4
|
|
|
|
|
11
|
push @tokens, @$value; |
93
|
|
|
|
|
|
|
} else { |
94
|
1
|
|
|
|
|
3
|
push @tokens, $value; |
95
|
|
|
|
|
|
|
} |
96
|
5
|
|
|
|
|
32
|
return @tokens; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _list |
100
|
|
|
|
|
|
|
{ |
101
|
1
|
|
|
1
|
|
2
|
my @items = @_; |
102
|
1
|
|
|
|
|
3
|
my @tokens = (); |
103
|
1
|
|
|
|
|
3
|
for my $item (@items) { |
104
|
2
|
50
|
|
|
|
8
|
if(ref($item) =~ /ARRAY/) { |
105
|
2
|
|
|
|
|
4
|
push @tokens, @$item; |
106
|
|
|
|
|
|
|
} else { |
107
|
0
|
|
|
|
|
0
|
push @tokens, $item; |
108
|
|
|
|
|
|
|
} |
109
|
2
|
|
|
|
|
9
|
push @tokens, new Devel::Declare::Lexer::Token::Operator( value => ',' ); |
110
|
2
|
|
|
|
|
8
|
push @tokens, new Devel::Declare::Lexer::Token::Whitespace( value => ' ' ); |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
# Remove additional ,\s |
113
|
1
|
|
|
|
|
2
|
pop @tokens; |
114
|
1
|
|
|
|
|
2
|
pop @tokens; |
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
8
|
return @tokens; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub _keypair |
120
|
|
|
|
|
|
|
{ |
121
|
0
|
|
|
0
|
|
0
|
my ($var1, $var2) = @_; |
122
|
0
|
|
|
|
|
0
|
my @tokens = (); |
123
|
0
|
|
|
|
|
0
|
push @tokens, @$var1; |
124
|
0
|
|
|
|
|
0
|
push @tokens, @$var2; |
125
|
0
|
|
|
|
|
0
|
return @tokens; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _return |
129
|
|
|
|
|
|
|
{ |
130
|
1
|
|
|
1
|
|
2
|
my ($value) = @_; |
131
|
1
|
|
|
|
|
2
|
my @tokens = (); |
132
|
1
|
|
|
|
|
5
|
push @tokens, new Devel::Declare::Lexer::Token::Bareword( value => 'return' ); |
133
|
1
|
|
|
|
|
5
|
push @tokens, new Devel::Declare::Lexer::Token::Whitespace( value => ' ' ); |
134
|
1
|
|
|
|
|
2
|
push @tokens, @$value; |
135
|
1
|
|
|
|
|
6
|
return @tokens; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub _block |
139
|
|
|
|
|
|
|
{ |
140
|
5
|
|
|
5
|
|
61
|
my ($inner, $type, $args) = @_; |
141
|
5
|
|
100
|
|
|
22
|
$type = $type || '{'; |
142
|
5
|
|
|
|
|
7
|
my $etype = $type; |
143
|
5
|
|
|
|
|
8
|
$etype =~ tr/{([/})]/; |
144
|
5
|
|
|
|
|
5
|
my @tokens = (); |
145
|
5
|
|
|
|
|
22
|
push @tokens, new Devel::Declare::Lexer::Token::LeftBracket( value => $type ); |
146
|
5
|
|
|
|
|
25
|
push @tokens, @$inner; |
147
|
5
|
100
|
|
|
|
15
|
if(!$args->{no_close}) { |
148
|
4
|
|
|
|
|
96
|
push @tokens, new Devel::Declare::Lexer::Token::RightBracket( value => $etype ); |
149
|
|
|
|
|
|
|
} |
150
|
5
|
|
|
|
|
42
|
return @tokens; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
sub _whitespace |
154
|
|
|
|
|
|
|
{ |
155
|
2
|
|
|
2
|
|
4
|
my ($ws) = @_; |
156
|
2
|
|
|
|
|
9
|
return ( new Devel::Declare::Lexer::Token::Whitespace( value => $ws ) ); |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
sub _sub |
160
|
|
|
|
|
|
|
{ |
161
|
2
|
|
|
2
|
|
4
|
my ($name, $block) = @_; |
162
|
2
|
|
|
|
|
4
|
my @tokens = (); |
163
|
2
|
|
|
|
|
9
|
push @tokens, new Devel::Declare::Lexer::Token::Bareword( value => 'sub' ); |
164
|
2
|
|
|
|
|
7
|
push @tokens, new Devel::Declare::Lexer::Token::Whitespace( value => ' ' ); |
165
|
2
|
|
|
|
|
9
|
push @tokens, new Devel::Declare::Lexer::Token::Bareword( value => $name ); |
166
|
2
|
|
|
|
|
20
|
push @tokens, new Devel::Declare::Lexer::Token::Whitespace( value => ' ' ); |
167
|
2
|
|
|
|
|
18
|
push @tokens, @$block; |
168
|
2
|
|
|
|
|
36
|
return @tokens; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub _if |
172
|
|
|
|
|
|
|
{ |
173
|
1
|
|
|
1
|
|
2
|
my ($condition, $then, $elsifs, $else) = @_; |
174
|
|
|
|
|
|
|
|
175
|
1
|
|
|
|
|
3
|
my @tokens = (); |
176
|
|
|
|
|
|
|
|
177
|
1
|
|
|
|
|
6
|
push @tokens, new Devel::Declare::Lexer::Token::Bareword( value => 'if' ); |
178
|
1
|
|
|
|
|
6
|
push @tokens, new Devel::Declare::Lexer::Token::LeftBracket( value => '(' ); |
179
|
1
|
|
|
|
|
4
|
push @tokens, @$condition; |
180
|
1
|
|
|
|
|
5
|
push @tokens, new Devel::Declare::Lexer::Token::RightBracket( value => ')' ); |
181
|
1
|
|
|
|
|
5
|
push @tokens, new Devel::Declare::Lexer::Token::LeftBracket( value => '{' ); |
182
|
1
|
|
|
|
|
3
|
push @tokens, @$then; |
183
|
1
|
|
|
|
|
5
|
push @tokens, new Devel::Declare::Lexer::Token::RightBracket( value => '}' ); |
184
|
|
|
|
|
|
|
|
185
|
1
|
50
|
|
|
|
4
|
if($elsifs) { |
186
|
0
|
|
|
|
|
0
|
my @elsif = @$elsifs; |
187
|
0
|
0
|
|
|
|
0
|
if(scalar @elsif > 0) { |
188
|
0
|
|
|
|
|
0
|
for my $eif (@elsif) { |
189
|
0
|
|
|
|
|
0
|
push @tokens, new Devel::Declare::Lexer::Token::Bareword( value => 'elsif' ); |
190
|
0
|
|
|
|
|
0
|
push @tokens, new Devel::Declare::Lexer::Token::LeftBracket( value => '(' ); |
191
|
0
|
|
|
|
|
0
|
push @tokens, @{$eif->{condition}}; |
|
0
|
|
|
|
|
0
|
|
192
|
0
|
|
|
|
|
0
|
push @tokens, new Devel::Declare::Lexer::Token::RightBracket( value => ')' ); |
193
|
0
|
|
|
|
|
0
|
push @tokens, new Devel::Declare::Lexer::Token::LeftBracket( value => '{' ); |
194
|
0
|
|
|
|
|
0
|
push @tokens, @{$eif->{then}}; |
|
0
|
|
|
|
|
0
|
|
195
|
0
|
|
|
|
|
0
|
push @tokens, new Devel::Declare::Lexer::Token::RightBracket( value => '}' ); |
196
|
|
|
|
|
|
|
} |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
1
|
50
|
|
|
|
4
|
if($else) { |
201
|
0
|
|
|
|
|
0
|
push @tokens, new Devel::Declare::Lexer::Token::Bareword( value => 'else' ); |
202
|
0
|
|
|
|
|
0
|
push @tokens, new Devel::Declare::Lexer::Token::LeftBracket( value => '{' ); |
203
|
0
|
|
|
|
|
0
|
push @tokens, @$else; |
204
|
0
|
|
|
|
|
0
|
push @tokens, new Devel::Declare::Lexer::Token::RightBracket( value => '}' ); |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
1
|
|
|
|
|
7
|
return @tokens; |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
1; |