line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Partial::Google::Parser; |
2
|
|
|
|
|
|
|
our $VERSION = '0.00_01'; # VERSION |
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:ARODLAND'; # AUTHORITY |
4
|
3
|
|
|
3
|
|
83449
|
use Marpa::R2; |
|
3
|
|
|
|
|
293678
|
|
|
3
|
|
|
|
|
709
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
my $rules = q{ |
7
|
|
|
|
|
|
|
lexeme default = latm => 1 |
8
|
|
|
|
|
|
|
:default ::= action => [values] |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
TopLevel ::= Props action => toplevel |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Props ::= Prop+ separator => [,] action => props |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Prop ::= Object action => ::first bless => ::undef |
15
|
|
|
|
|
|
|
| Array action => ::first bless => ::undef |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Object ::= NAME action => object |
18
|
|
|
|
|
|
|
| NAME ('/') Object action => object |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
Array ::= NAME ('(') Props (')') action => array |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
NAME ~ [^,/()]+ |
23
|
|
|
|
|
|
|
}; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $grammar = Marpa::R2::Scanless::G->new({ |
26
|
|
|
|
|
|
|
source => \$rules, |
27
|
|
|
|
|
|
|
bless_package => 'Data::Partial::Google', |
28
|
|
|
|
|
|
|
}); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub parse { |
31
|
25
|
|
|
25
|
0
|
10772
|
my ($class, $input) = @_; |
32
|
|
|
|
|
|
|
|
33
|
25
|
|
|
|
|
137
|
my $recognizer = Marpa::R2::Scanless::R->new({ |
34
|
|
|
|
|
|
|
semantics_package => $class, |
35
|
|
|
|
|
|
|
grammar => $grammar, |
36
|
|
|
|
|
|
|
}); |
37
|
|
|
|
|
|
|
|
38
|
25
|
|
|
|
|
4040
|
$recognizer->read(\$input); |
39
|
25
|
|
|
|
|
3520
|
my $value = $recognizer->value; |
40
|
25
|
50
|
|
|
|
518
|
if ($value) { |
41
|
25
|
|
|
|
|
491
|
return $$value; |
42
|
|
|
|
|
|
|
} else { |
43
|
0
|
|
|
|
|
0
|
return undef; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub make_filter { |
48
|
88
|
|
|
88
|
0
|
75
|
my ($properties) = @_; |
49
|
88
|
100
|
|
|
|
314
|
return bless { |
50
|
|
|
|
|
|
|
($properties |
51
|
|
|
|
|
|
|
? (properties => $properties) |
52
|
|
|
|
|
|
|
: () |
53
|
|
|
|
|
|
|
) |
54
|
|
|
|
|
|
|
}, 'Data::Partial::Google::Filter'; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub merge_props { |
58
|
|
|
|
|
|
|
# Turn [[a, Filter], [b, Filter], [c, Filter]] |
59
|
|
|
|
|
|
|
# into { a => Filter, b => Filter, c => Filter } |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
return +{ |
62
|
48
|
|
|
48
|
0
|
76
|
map { @$_ } @_ |
|
63
|
|
|
|
|
165
|
|
63
|
|
|
|
|
|
|
}; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub toplevel { |
67
|
25
|
|
|
25
|
0
|
500
|
make_filter($_[1]); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub props { |
71
|
33
|
|
|
33
|
0
|
714
|
shift; # Unused global object |
72
|
33
|
|
|
|
|
51
|
merge_props(@_); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub object { |
76
|
55
|
100
|
|
55
|
0
|
31963
|
my $props = $_[2] ? merge_props($_[2]) : undef; |
77
|
|
|
|
|
|
|
|
78
|
55
|
|
|
|
|
82
|
[ $_[1], make_filter($props) ] |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub array { |
82
|
8
|
|
|
8
|
0
|
169
|
[ $_[1], make_filter($_[2]) ] |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
1; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__END__ |