line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::IOD::Expr; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2021-06-23'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.343'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
45
|
use 5.010; |
|
2
|
|
|
|
|
8
|
|
7
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
43
|
|
8
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1185
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $EXPR_RE = qr{ |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
(?&ANSWER) |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
(?(DEFINE) |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
(? (?&ADD)) |
17
|
|
|
|
|
|
|
(? (?&MULT) | (?&MULT) (?: \s* ([+.-]) \s* (?&MULT) )+) |
18
|
|
|
|
|
|
|
(? (?&UNARY) | (?&UNARY) (?: \s* ([*/x%]) \s* (?&UNARY))+) |
19
|
|
|
|
|
|
|
(? (?&POWER) | [!~+-] (?&POWER)) |
20
|
|
|
|
|
|
|
(? (?&TERM) | (?&TERM) (?: \s* \*\* \s* (?&TERM))+) |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
(? |
23
|
|
|
|
|
|
|
(?&NUM) |
24
|
|
|
|
|
|
|
| (?&STR_SINGLE) |
25
|
|
|
|
|
|
|
| (?&STR_DOUBLE) |
26
|
|
|
|
|
|
|
| undef |
27
|
|
|
|
|
|
|
| (?&VAR) |
28
|
|
|
|
|
|
|
| (?&FUNC) |
29
|
|
|
|
|
|
|
| \( \s* ((?&ANSWER)) \s* \) |
30
|
|
|
|
|
|
|
) |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
(? val \s* \( (?&TERM) \)) |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
(? |
35
|
|
|
|
|
|
|
( |
36
|
|
|
|
|
|
|
-? |
37
|
|
|
|
|
|
|
(?: 0 | [1-9][0-9]* ) |
38
|
|
|
|
|
|
|
(?: \. [0-9]+ )? |
39
|
|
|
|
|
|
|
(?: [eE] [-+]? [0-9]+ )? |
40
|
|
|
|
|
|
|
) |
41
|
|
|
|
|
|
|
) |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
(? \$[A-Za-z_][A-Za-z0-9_]{0,63}) |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
(? |
46
|
|
|
|
|
|
|
( |
47
|
|
|
|
|
|
|
' |
48
|
|
|
|
|
|
|
(?: |
49
|
|
|
|
|
|
|
[^\\']+ |
50
|
|
|
|
|
|
|
| |
51
|
|
|
|
|
|
|
\\ ['\\] |
52
|
|
|
|
|
|
|
| |
53
|
|
|
|
|
|
|
\\ |
54
|
|
|
|
|
|
|
)* |
55
|
|
|
|
|
|
|
' |
56
|
|
|
|
|
|
|
) |
57
|
|
|
|
|
|
|
) |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
(? |
60
|
|
|
|
|
|
|
( |
61
|
|
|
|
|
|
|
" |
62
|
|
|
|
|
|
|
(?: |
63
|
|
|
|
|
|
|
[^\\"]+ |
64
|
|
|
|
|
|
|
| |
65
|
|
|
|
|
|
|
\\ ["'\\\$tnrfbae] |
66
|
|
|
|
|
|
|
# octal, hex, wide hex |
67
|
|
|
|
|
|
|
)* |
68
|
|
|
|
|
|
|
" |
69
|
|
|
|
|
|
|
) |
70
|
|
|
|
|
|
|
) |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
) # DEFINE |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
}msx; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub _parse_expr { |
77
|
6
|
|
|
6
|
|
10
|
my $str = shift; |
78
|
|
|
|
|
|
|
|
79
|
6
|
100
|
|
|
|
1490
|
return [400, 'Not a valid expr'] unless $str =~ m{\A$EXPR_RE\z}o; |
80
|
2
|
|
|
2
|
|
12
|
my $res = eval "package Config::IOD::Expr::_Compiled; no strict; no warnings; $str"; |
|
2
|
|
|
2
|
|
4
|
|
|
2
|
|
|
2
|
|
44
|
|
|
2
|
|
|
2
|
|
9
|
|
|
2
|
|
|
1
|
|
4
|
|
|
2
|
|
|
1
|
|
75
|
|
|
2
|
|
|
|
|
18
|
|
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
55
|
|
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
55
|
|
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
|
5
|
|
|
|
|
314
|
|
81
|
5
|
50
|
|
|
|
18
|
return [500, "Died when evaluating expr: $@"] if $@; |
82
|
5
|
|
|
|
|
29
|
[200, "OK", $res]; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
# ABSTRACT: Parse expression |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |