line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Language::Expr::EvaluatorRole; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2016-06-29'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.27'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
1868
|
use 5.010; |
|
5
|
|
|
|
|
11
|
|
7
|
5
|
|
|
5
|
|
14
|
use strict; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
75
|
|
8
|
5
|
|
|
5
|
|
13
|
use warnings; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
83
|
|
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
14
|
use Role::Tiny; |
|
5
|
|
|
|
|
4
|
|
|
5
|
|
|
|
|
24
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
requires 'rule_pair_simple'; |
13
|
|
|
|
|
|
|
requires 'rule_pair_string'; |
14
|
|
|
|
|
|
|
requires 'rule_or_xor'; |
15
|
|
|
|
|
|
|
requires 'rule_ternary'; |
16
|
|
|
|
|
|
|
requires 'rule_and'; |
17
|
|
|
|
|
|
|
requires 'rule_bit_or_xor'; |
18
|
|
|
|
|
|
|
requires 'rule_bit_and'; |
19
|
|
|
|
|
|
|
requires 'rule_comparison3'; |
20
|
|
|
|
|
|
|
requires 'rule_comparison'; |
21
|
|
|
|
|
|
|
requires 'rule_bit_shift'; |
22
|
|
|
|
|
|
|
requires 'rule_add'; |
23
|
|
|
|
|
|
|
requires 'rule_mult'; |
24
|
|
|
|
|
|
|
requires 'rule_unary'; |
25
|
|
|
|
|
|
|
requires 'rule_power'; |
26
|
|
|
|
|
|
|
requires 'rule_subscripting_var'; |
27
|
|
|
|
|
|
|
requires 'rule_subscripting_expr'; |
28
|
|
|
|
|
|
|
requires 'rule_array'; |
29
|
|
|
|
|
|
|
requires 'rule_hash'; |
30
|
|
|
|
|
|
|
requires 'rule_undef'; |
31
|
|
|
|
|
|
|
requires 'rule_squotestr'; |
32
|
|
|
|
|
|
|
requires 'rule_dquotestr'; |
33
|
|
|
|
|
|
|
requires 'rule_var'; |
34
|
|
|
|
|
|
|
requires 'rule_func'; |
35
|
|
|
|
|
|
|
requires 'rule_func_map'; |
36
|
|
|
|
|
|
|
requires 'rule_func_grep'; |
37
|
|
|
|
|
|
|
requires 'rule_func_usort'; |
38
|
|
|
|
|
|
|
requires 'rule_bool'; |
39
|
|
|
|
|
|
|
requires 'rule_num'; |
40
|
|
|
|
|
|
|
requires 'rule_parenthesis'; |
41
|
|
|
|
|
|
|
requires 'expr_preprocess'; |
42
|
|
|
|
|
|
|
requires 'expr_postprocess'; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub parse_dquotestr { |
45
|
114
|
|
|
114
|
1
|
145
|
my ($self, @parts) = @_; |
46
|
114
|
100
|
|
|
|
289
|
if (ref($parts[0]) eq 'ARRAY') { splice @parts, 0, 1, @{ $parts[0] } } |
|
110
|
|
|
|
|
130
|
|
|
110
|
|
|
|
|
241
|
|
47
|
114
|
|
|
|
|
119
|
my @res; |
48
|
|
|
|
|
|
|
my @sbuf; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#say "D:parse_dquotestr:parts = ", join(", ", @parts); |
51
|
|
|
|
|
|
|
#for (grep {defined} @parts) { |
52
|
114
|
|
|
|
|
199
|
for (@parts) { |
53
|
5
|
|
|
5
|
|
1029
|
no warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
2034
|
|
54
|
114
|
|
|
|
|
186
|
my $s01 = substr($_, 0, 1); |
55
|
114
|
|
|
|
|
109
|
my $s02 = substr($_, 0, 2); |
56
|
114
|
|
|
|
|
110
|
my $l = length(); |
57
|
114
|
100
|
100
|
|
|
1574
|
if ($_ eq "\\'" ) { push @sbuf, "'" } |
|
2
|
100
|
66
|
|
|
6
|
|
|
|
100
|
33
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
100
|
|
|
|
|
|
|
100
|
66
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
58
|
2
|
|
|
|
|
7
|
elsif ($_ eq "\\\"") { push @sbuf, '"' } |
59
|
2
|
|
|
|
|
7
|
elsif ($_ eq "\\\\") { push @sbuf, "\\" } |
60
|
2
|
|
|
|
|
5
|
elsif ($_ eq "\\\$") { push @sbuf, '$' } |
61
|
2
|
|
|
|
|
6
|
elsif ($_ eq "\\t" ) { push @sbuf, "\t" } |
62
|
2
|
|
|
|
|
6
|
elsif ($_ eq "\\n" ) { push @sbuf, "\n" } |
63
|
2
|
|
|
|
|
5
|
elsif ($_ eq "\\f" ) { push @sbuf, "\f" } |
64
|
2
|
|
|
|
|
6
|
elsif ($_ eq "\\b" ) { push @sbuf, "\b" } |
65
|
2
|
|
|
|
|
6
|
elsif ($_ eq "\\a" ) { push @sbuf, "\a" } |
66
|
2
|
|
|
|
|
6
|
elsif ($_ eq "\\e" ) { push @sbuf, "\e" } |
67
|
|
|
|
|
|
|
elsif ($l >= 2 && $l <= 4 && $s01 eq "\\" && |
68
|
|
|
|
|
|
|
substr($_, 1, 1) >= "0" && substr($_, 1, 1) <= "7") { |
69
|
|
|
|
|
|
|
# \000 octal escape |
70
|
0
|
|
|
|
|
0
|
push @sbuf, chr(oct(substr($_, 1))) } |
71
|
|
|
|
|
|
|
elsif ($l >= 3 && $l <= 4 && $s02 eq "\\x") { |
72
|
|
|
|
|
|
|
# \xFF hex escape |
73
|
0
|
|
|
|
|
0
|
push @sbuf, chr(hex(substr($_, 1))) } |
74
|
|
|
|
|
|
|
elsif ($l >= 5 && $l <= 8 && substr($_, 0, 3) eq "\\x{") { |
75
|
|
|
|
|
|
|
# \x{1234} wide hex escape |
76
|
0
|
|
|
|
|
0
|
push @sbuf, chr(hex(substr($_, 3, length()-4))) } |
77
|
|
|
|
|
|
|
elsif ($s02 eq '${') { |
78
|
|
|
|
|
|
|
# ${var} |
79
|
2
|
50
|
|
|
|
6
|
push @res, {type=>"STR", value=>join("", @sbuf)} if @sbuf; @sbuf=(); |
|
2
|
|
|
|
|
4
|
|
80
|
2
|
|
|
|
|
12
|
push @res, {type=>"VAR", value=>substr($_, 2, length()-3)} } |
81
|
|
|
|
|
|
|
elsif ($s01 eq '$') { |
82
|
|
|
|
|
|
|
# $var |
83
|
2
|
50
|
|
|
|
7
|
push @res, {type=>"STR", value=>join("", @sbuf)} if @sbuf; @sbuf=(); |
|
2
|
|
|
|
|
3
|
|
84
|
2
|
|
|
|
|
10
|
push @res, {type=>"VAR", value=>substr($_, 1, length()-1)} } |
85
|
|
|
|
|
|
|
else { |
86
|
90
|
|
|
|
|
191
|
push @sbuf, $_; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
114
|
100
|
|
|
|
280
|
push @res, {type=>"STR", value=>join("", grep {defined} @sbuf)} if @sbuf; |
|
110
|
|
|
|
|
408
|
|
90
|
114
|
|
|
|
|
303
|
\@res; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub parse_squotestr { |
94
|
20
|
|
|
20
|
1
|
29
|
my ($self, @parts) = @_; |
95
|
20
|
100
|
|
|
|
48
|
if (ref($parts[0]) eq 'ARRAY') { splice @parts, 0, 1, @{ $parts[0] } } |
|
18
|
|
|
|
|
19
|
|
|
18
|
|
|
|
|
35
|
|
96
|
20
|
|
|
|
|
21
|
my @res; |
97
|
|
|
|
|
|
|
my @sbuf; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
#say "D:parse_dquotestr:parts = ", join(", ", @parts); |
100
|
|
|
|
|
|
|
#for (grep {defined} @parts) { |
101
|
20
|
|
|
|
|
32
|
for (@parts) { |
102
|
5
|
|
|
5
|
|
20
|
no warnings; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
530
|
|
103
|
24
|
100
|
|
|
|
55
|
if ($_ eq "\\'" ) { push @sbuf, "'" } |
|
2
|
100
|
|
|
|
5
|
|
104
|
2
|
|
|
|
|
6
|
elsif ($_ eq "\\\\") { push @sbuf, "\\" } |
105
|
20
|
|
|
|
|
34
|
else { push @sbuf, $_ } |
106
|
|
|
|
|
|
|
} |
107
|
20
|
50
|
|
|
|
54
|
push @res, {type=>"STR", value=>join("", grep {defined} @sbuf)} if @sbuf; |
|
24
|
|
|
|
|
77
|
|
108
|
20
|
|
|
|
|
54
|
\@res; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
1; |
112
|
|
|
|
|
|
|
# ABSTRACT: Specification for Language::Expr interpreter/compiler |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__END__ |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=pod |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=encoding UTF-8 |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 NAME |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Language::Expr::EvaluatorRole - Specification for Language::Expr interpreter/compiler |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 VERSION |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This document describes version 0.27 of Language::Expr::EvaluatorRole (from Perl distribution Language-Expr), released on 2016-06-29. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 METHODS |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 parse_dquotestr($raw_parts) -> [{type=>"STR"|"VAR"}, value=>...}, ...] |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Instead of parsing parts themselves, consumers can use this method (typically in |
133
|
|
|
|
|
|
|
their rule_dquotestr). This method converts each Expr escapes into Perl string |
134
|
|
|
|
|
|
|
and variables. For example: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
parse_dquotestr('abc', "\\t", '\\\\', '$foo', ' ', '${bar baz}') -> ( |
137
|
|
|
|
|
|
|
{type=>"STR", value=>'abc\t\\'}, |
138
|
|
|
|
|
|
|
{type=>"VAR", value=>'foo'}, |
139
|
|
|
|
|
|
|
{type=>"STR", value=>' '}, |
140
|
|
|
|
|
|
|
{type=>"VAR", value=>'bar baz'}, |
141
|
|
|
|
|
|
|
) |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=head2 parse_squotestr($raw_parts) => [{type=>STR, value=>...}, ...] |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
Instead of parsing parts themselves, consumers can use this method (typically in |
146
|
|
|
|
|
|
|
their rule_squotestr). This method converts Expr single quoted string into Perl |
147
|
|
|
|
|
|
|
string. |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
parse_dquotestr('abc', "\\t", '\\\\', '$foo', ' ', '${bar baz}') -> ( |
150
|
|
|
|
|
|
|
{type=>"STR", value=>'abc\t\\$foo ${bar baz}'}, |
151
|
|
|
|
|
|
|
) |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 HOMEPAGE |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Language-Expr>. |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 SOURCE |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Language-Expr>. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head1 BUGS |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Language-Expr> |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
166
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
167
|
|
|
|
|
|
|
feature. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 AUTHOR |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
This software is copyright (c) 2016 by perlancar@cpan.org. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
178
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |