line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package GraphQL::Language::Parser; |
2
|
|
|
|
|
|
|
|
3
|
21
|
|
|
21
|
|
103380
|
use 5.014; |
|
21
|
|
|
|
|
86
|
|
4
|
21
|
|
|
21
|
|
131
|
use strict; |
|
650
|
|
|
|
|
7330
|
|
|
469
|
|
|
|
|
4525
|
|
5
|
380
|
|
|
21
|
|
49997
|
use warnings; |
|
380
|
|
|
|
|
17495
|
|
|
21
|
|
|
|
|
630
|
|
6
|
21
|
|
|
21
|
|
112
|
use base qw(Pegex::Parser); |
|
21
|
|
|
|
|
138
|
|
|
21
|
|
|
|
|
10069
|
|
7
|
21
|
|
|
21
|
|
253210
|
use Exporter 'import'; |
|
21
|
|
|
|
|
54
|
|
|
21
|
|
|
|
|
750
|
|
8
|
21
|
|
|
21
|
|
606
|
use Types::Standard -all; |
|
21
|
|
|
|
|
67655
|
|
|
21
|
|
|
|
|
306
|
|
9
|
21
|
|
|
21
|
|
920926
|
use GraphQL::MaybeTypeCheck; |
|
21
|
|
|
|
|
64
|
|
|
21
|
|
|
|
|
232
|
|
10
|
21
|
|
|
21
|
|
16158
|
use GraphQL::Language::Grammar; |
|
21
|
|
|
|
|
76
|
|
|
21
|
|
|
|
|
290
|
|
11
|
21
|
|
|
21
|
|
12492
|
use GraphQL::Language::Receiver; |
|
21
|
|
|
|
|
85
|
|
|
21
|
|
|
|
|
267
|
|
12
|
21
|
|
|
21
|
|
11729
|
use GraphQL::Error; |
|
21
|
|
|
|
|
93
|
|
|
21
|
|
|
|
|
207
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
16
|
|
|
|
|
|
|
parse |
17
|
|
|
|
|
|
|
); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 NAME |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
GraphQL::Language::Parser - GraphQL Pegex parser |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 SYNOPSIS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
use GraphQL::Language::Parser qw(parse); |
26
|
|
|
|
|
|
|
my $parsed = parse( |
27
|
|
|
|
|
|
|
$source |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Provides both an outside-accessible point of entry into the GraphQL |
33
|
|
|
|
|
|
|
parser (see above), and a subclass of L<Pegex::Parser> to parse a document |
34
|
|
|
|
|
|
|
into an AST usable by GraphQL. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 METHODS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head2 parse |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
parse($source, $noLocation); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
B<NB> that unlike in C<Pegex::Parser> this is a function, not an instance |
43
|
|
|
|
|
|
|
method. This achieves hiding of Pegex implementation details. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $GRAMMAR = GraphQL::Language::Grammar->new; # singleton |
48
|
|
|
|
|
|
|
fun parse( |
49
|
|
|
|
|
|
|
Str $source, |
50
|
|
|
|
|
|
|
Bool $noLocation = undef, |
51
|
359
|
50
|
|
359
|
1
|
270906
|
) :ReturnType(ArrayRef[HashRef]) { |
|
359
|
50
|
|
|
|
1170
|
|
|
359
|
100
|
|
|
|
901
|
|
|
359
|
50
|
|
|
|
1257
|
|
|
21
|
|
|
|
|
11900
|
|
|
21
|
|
|
|
|
55
|
|
52
|
21
|
|
|
|
|
102
|
my $parser = __PACKAGE__->SUPER::new( |
53
|
|
|
|
|
|
|
grammar => $GRAMMAR, |
54
|
|
|
|
|
|
|
receiver => GraphQL::Language::Receiver->new, |
55
|
|
|
|
|
|
|
); |
56
|
35
|
|
|
|
|
30750
|
my $input = Pegex::Input->new(string => $source); |
57
|
35
|
|
|
|
|
61
|
scalar $parser->SUPER::parse($input); |
58
|
21
|
|
|
21
|
|
6681
|
} |
|
21
|
|
|
|
|
59
|
|
|
21
|
|
|
|
|
140
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 format_error |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Override of parent method. Returns a L<GraphQL::Error>. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub format_error :ReturnType(InstanceOf['GraphQL::Error']) { |
67
|
35
|
|
|
35
|
1
|
86
|
my ($self, $msg) = @_; |
68
|
35
|
|
|
|
|
775
|
my $buffer = $self->{buffer}; |
69
|
35
|
|
|
|
|
67
|
my $position = $self->{farthest}; |
70
|
35
|
|
|
|
|
88
|
my $real_pos = $self->{position}; |
71
|
35
|
|
|
|
|
75
|
my ($line, $column) = @{$self->line_column($position)}; |
|
35
|
|
|
|
|
160
|
|
72
|
35
|
|
|
|
|
1169
|
my $pretext = substr( |
73
|
|
|
|
|
|
|
$$buffer, |
74
|
|
|
|
|
|
|
$position < 50 ? 0 : $position - 50, |
75
|
|
|
|
|
|
|
$position < 50 ? $position : 50 |
76
|
|
|
|
|
|
|
); |
77
|
|
|
|
|
|
|
my $context = substr($$buffer, $position, 50); |
78
|
|
|
|
|
|
|
$pretext =~ s/.*\n//gs; |
79
|
|
|
|
|
|
|
$context =~ s/\n/\\n/g; |
80
|
|
|
|
|
|
|
return GraphQL::Error->new( |
81
|
|
|
|
|
|
|
locations => [ { line => $line, column => $column } ], |
82
|
|
|
|
|
|
|
message => <<EOF); |
83
|
|
|
|
|
|
|
Error parsing Pegex document: |
84
|
|
|
|
|
|
|
msg: $msg |
85
|
|
|
|
|
|
|
context: $pretext$context |
86
|
|
|
|
|
|
|
${\ (' ' x (length($pretext)) . '^')} |
87
|
|
|
|
|
|
|
position: $position ($real_pos pre-lookahead) |
88
|
|
|
|
|
|
|
EOF |
89
|
35
|
|
|
21
|
|
71
|
} |
|
35
|
|
|
|
|
49
|
|
|
35
|
|
|
|
|
48
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |