line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::Format::Ini::Grammar; |
2
|
10
|
|
|
10
|
|
67672
|
use Parse::RecDescent; |
|
10
|
|
|
|
|
838206
|
|
|
10
|
|
|
|
|
91
|
|
3
|
10
|
|
|
10
|
|
460
|
use strict; |
|
10
|
|
|
|
|
21
|
|
|
10
|
|
|
|
|
319
|
|
4
|
10
|
|
|
10
|
|
55
|
use warnings; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
1038
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my $gram = <<'END_GRAMMAR' ; |
7
|
|
|
|
|
|
|
{ my $h ; |
8
|
|
|
|
|
|
|
use Data::Dumper; |
9
|
|
|
|
|
|
|
my %esc = map {$_ => pack 'H2', $_} 0..255; |
10
|
|
|
|
|
|
|
@esc{ '\n', '\t', '\r', '\a' } = ( "\n", "\t", "\r", "\a" ); |
11
|
|
|
|
|
|
|
sub merge2hash { my $aref = shift; my $h; |
12
|
|
|
|
|
|
|
ref eq 'HASH' and @{$h}{keys %$_} = values %$_ for @$aref; $h; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
sub postprocess { |
15
|
|
|
|
|
|
|
local $_ = shift ||return; |
16
|
|
|
|
|
|
|
s/ \\x([\d]{1,3})/ $esc{ "$1"+0 } /egx; |
17
|
|
|
|
|
|
|
s/ (\\[ntra]) / $esc{$1} /xge; |
18
|
|
|
|
|
|
|
$_ ; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
startrule : |
24
|
|
|
|
|
|
|
Section(s) |
25
|
|
|
|
|
|
|
{ $return = merge2hash( $item[2]) } |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Section: Title "\n" Pair(s?) |
28
|
|
|
|
|
|
|
{ $return = { $item[1]=> merge2hash( $item[3])||{} } } |
29
|
|
|
|
|
|
|
| COMMENT(s) |
30
|
|
|
|
|
|
|
| BLANK(s) |
31
|
|
|
|
|
|
|
| |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
Title: '[' /\w+/ ']' COM(?) |
34
|
|
|
|
|
|
|
{ $item[2] } |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Pair: KEY '=' VAL(s?) COM(?) "\n" |
37
|
|
|
|
|
|
|
{$return = {$item[1]=>$item[3]} } |
38
|
|
|
|
|
|
|
Pair: COMMENT(s){$return = 0} |
39
|
|
|
|
|
|
|
| BLANK(s) {$return = 0} |
40
|
|
|
|
|
|
|
Pair: |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
KEY: /\w+(?=\s*=)/ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
VAL: |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
{ $item[1]->[2] =~ s/\\\n//g } |
47
|
|
|
|
|
|
|
{ $item[1]->[2] } |
48
|
|
|
|
|
|
|
VAL: |
49
|
|
|
|
|
|
|
/.*? (?
|
50
|
|
|
|
|
|
|
{ $item[1] =~ s/\\\n//g } |
51
|
|
|
|
|
|
|
{ $item[1] =~ s/[;#].*\Z//m } |
52
|
|
|
|
|
|
|
{ $item[1] =~ s/^\s+|\s+$// } |
53
|
|
|
|
|
|
|
{ postprocess( $item[1] ) } |
54
|
|
|
|
|
|
|
VAL: ',' VAL |
55
|
|
|
|
|
|
|
{$item[2]} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
BLANK: "\n" |
60
|
|
|
|
|
|
|
COM: /^(?:[#;].*)/ |
61
|
|
|
|
|
|
|
COMMENT: COM "\n" |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
END_GRAMMAR |
64
|
|
|
|
|
|
|
|
65
|
24
|
|
|
24
|
0
|
233822
|
sub new { Parse::RecDescent->new( $gram ) } |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
__END__ |