line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
347
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# DO NOT RELY ON THIS AS A REAL JSON PARSER |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# It is not intended to be used actually as a JSON parser, simply to stand as |
9
|
|
|
|
|
|
|
# an example of how you might use Parser::MGC to parse a JSON-like syntax |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# It doesn't handle things like floats, booleans or quoting of dict keys |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
package JsonlikeParser; |
14
|
1
|
|
|
1
|
|
4
|
use base qw( Parser::MGC ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
446
|
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
6
|
use Feature::Compat::Try; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
4
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub parse |
19
|
|
|
|
|
|
|
{ |
20
|
20
|
|
|
20
|
|
22
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$self->any_of( |
23
|
|
|
|
|
|
|
'token_int', |
24
|
|
|
|
|
|
|
'token_string', |
25
|
|
|
|
|
|
|
|
26
|
7
|
|
|
7
|
|
16
|
sub { $self->committed_scope_of( "[", 'parse_list', "]" ) }, |
27
|
|
|
|
|
|
|
|
28
|
3
|
|
|
3
|
|
4
|
sub { $self->committed_scope_of( "{", 'parse_dict', "}" ) }, |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
0
|
|
0
|
sub { $self->commit; $self->fail( "Expected integer, string, list, or dictionary" ) }, |
|
0
|
|
|
|
|
0
|
|
31
|
20
|
|
|
|
|
94
|
); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub parse_list |
35
|
|
|
|
|
|
|
{ |
36
|
4
|
|
|
4
|
|
4
|
my $self = shift; |
37
|
|
|
|
|
|
|
|
38
|
4
|
|
|
|
|
21
|
return $self->list_of( ",", 'parse' ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub parse_dict |
42
|
|
|
|
|
|
|
{ |
43
|
3
|
|
|
3
|
|
4
|
my $self = shift; |
44
|
|
|
|
|
|
|
|
45
|
3
|
|
|
|
|
3
|
my %ret; |
46
|
|
|
|
|
|
|
$self->list_of( ",", sub { |
47
|
5
|
|
|
5
|
|
12
|
my $key = $self->token_ident; |
48
|
|
|
|
|
|
|
|
49
|
5
|
|
|
|
|
14
|
$self->expect( ":" ); |
50
|
5
|
|
|
|
|
8
|
$self->commit; |
51
|
|
|
|
|
|
|
|
52
|
5
|
|
|
|
|
6
|
$ret{$key} = $self->parse; |
53
|
3
|
|
|
|
|
13
|
} ); |
54
|
|
|
|
|
|
|
|
55
|
3
|
|
|
|
|
9
|
return \%ret |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
1
|
|
|
1
|
|
759
|
use Data::Dumper; |
|
1
|
|
|
|
|
5710
|
|
|
1
|
|
|
|
|
145
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
if( !caller ) { |
61
|
|
|
|
|
|
|
my $parser = __PACKAGE__->new; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
while( defined( my $line = ) ) { |
64
|
|
|
|
|
|
|
try { |
65
|
|
|
|
|
|
|
my $ret = $parser->from_string( $line ); |
66
|
|
|
|
|
|
|
print Dumper( $ret ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
catch ( $e ) { |
69
|
|
|
|
|
|
|
print $e; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |