AtteanX/Parser/SPARQLLex.pm

filter: Statementstmt 74.4% 359 / 482 Branchbran 60.5% 132 / 218 Conditioncond 41.1% 21 / 51 MC/DCmcdc 26.4% 9 / 34 Subroutinesub 90.4% 57 / 63 Podpod 33.3% 6 / 18 totaltotal 67.4% 584 / 866 CC 130 SCAR 34.8
CC
130
Cov
68%
_get_iriref_or_relational
156.2
_get_escaped_char
48.1
get_token
37.3
CRAP 32.6
« AtteanX/Parser/Turtle/Lexer.pm ↑ Summary AtteanX/Serializer/TurtleTokens.pm »
1 14 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 =head1 NAME
5  
6 AtteanX::Parser::SPARQLLex - SPARQL Lexer
7  
8 =head1 VERSION
9  
10 This document describes AtteanX::Parser::SPARQLLex version 0.041
11  
12 =head1 SYNOPSIS
13  
14 use Attean;
15  
16 =head1 DESCRIPTION
17  
18 ...
19  
20 =head1 ATTRIBUTES
21  
22 =over 4
23  
24 =item C<< canonical_media_type >>
25  
26 =item C<< media_types >>
27  
28 =item C<< file_extensions >>
29  
30 =item C<< handled_type >>
31  
32 =item C<< extend >>
33  
34 =back
35  
36 =head1 METHODS
37  
38 =over 4
39  
40 =cut
41  
42 14 package AtteanX::Parser::SPARQLLex 0.041 {
43 14 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 14 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 14 ▶ use Attean;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 14 ▶ use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 14 ▶ use Encode qw(decode);
Subroutine BEGIN: called CC=1 SCAR=0.0
48 14 ▶ use Types::Standard qw(ArrayRef Bool Str);
Subroutine BEGIN: called CC=1 SCAR=0.0
49 14 ▶ use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 1 ▶ sub canonical_media_type { return "application/x-sparql-query-tokens" }
Subroutine canonical_media_type: called CC=1 SCAR=0.0
Pod documented
52  
53 # these pass through to the lexer iterator
54 118 ▶ has extend => ( is => 'ro', isa => ArrayRef, default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
55 14 has 'version' => (is => 'rw', isa => Str, default => '1.2');
56 14 has include_ws => (is => 'rw', isa => Bool, default => 0);
57  
58 4 ▶ sub media_types {
Subroutine media_types: called CC=1 SCAR=0.0
Pod documented
59 4 return [qw(application/x-sparql-query-tokens)];
60 }
61
62 2 ▶ sub handled_type {
Subroutine handled_type: called CC=1 SCAR=0.0
Pod documented
63 2 state $ITEM_TYPE = Type::Tiny::Role->new(role => 'AtteanX::SPARQL::Token');
64 2 return $ITEM_TYPE;
65 }
66  
67 =item C<< file_extensions >>
68  
69 Returns a list of file extensions that may be parsed with the parser.
70  
71 =cut
72  
73 4 ▶ sub file_extensions { return [qw(rq)] }
Subroutine file_extensions: called CC=1 SCAR=0.0
Pod documented
74  
75 14 with 'Attean::API::PullParser', 'Attean::API::Parser';
76  
77 =item C<< parse_iter_from_bytes( $data ) >>
78  
79 Returns an iterator of SPARQL tokens that result from parsing
80 the SPARQL query/update read from the UTF-8 encoded byte string C<< $data >>.
81  
82 =cut
83  
84 57 ▶ sub parse_iter_from_bytes {
Subroutine parse_iter_from_bytes: called CC=1 SCAR=0.0
Pod documented
85 57 my $self = shift;
86 57 my $data = shift;
87 57 open(my $fh, '<:encoding(UTF-8)', \$data);
88 57 return $self->parse_iter_from_io($fh);
89 }
90  
91 =item C<< parse_iter_from_io( $fh ) >>
92  
93 Returns an iterator of SPARQL tokens that result from parsing
94 the SPARQL query/update read from the L<IO::Handle> object C<< $fh >>.
95  
96 =cut
97  
98 67 ▶ sub parse_iter_from_io {
Subroutine parse_iter_from_io: called CC=1 SCAR=0.0
Pod documented
99 67 my $self = shift;
100 67 my $fh = shift;
101 67 return AtteanX::Parser::SPARQLLex::Iterator->new(
102 extend => $self->extend,
103 file => $fh,
104 version => $self->version,
105 include_ws => $self->include_ws,
106 );
107 }
108 }
109  
110 14 package AtteanX::Parser::SPARQLLex::Iterator 0.041 {
111 14 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
112 14 ▶ use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
113 14 ▶ use Attean;
Subroutine BEGIN: called CC=1 SCAR=0.0
114 14 ▶ use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 14 ▶ use Encode qw(decode);
Subroutine BEGIN: called CC=1 SCAR=0.0
116 14 ▶ use AtteanX::SPARQL::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
117 14 ▶ use AtteanX::SPARQL::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
118 14 ▶ use Types::Standard qw(FileHandle Bool Ref Str Int ArrayRef HashRef ConsumerOf InstanceOf);
Subroutine BEGIN: called CC=1 SCAR=0.0
119 14 ▶ use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
120
121 67 ▶ has lookahead_methods => ( is => 'ro', isa => HashRef, default => sub { +{} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
122 67 ▶ has lookahead_tokens => ( is => 'ro', isa => HashRef, default => sub { +{} } );
Subroutine __ANON__: called CC=1 SCAR=0.0
123 0 ▶ has extend => ( is => 'ro', isa => ArrayRef, default => sub { [] } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
124 67 ▶ has token_buffer => ( is => 'ro', isa => ArrayRef, default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
125 14 has 'version' => (is => 'rw', isa => Str, default => '1.2');
126 14 has include_ws => (is => 'rw', isa => Bool, default => 0);
127
128 14 with 'AtteanX::API::Lexer';
129
130 14 my $r_ECHAR = qr/\\([tbnrf\\"'])/o;
131 14 my $r_STRING_LITERAL1 = qr/'(([^\x{27}\x{5C}\x{0A}\x{0D}])|${r_ECHAR})*'/o;
132 14 my $r_STRING_LITERAL2 = qr/"(([^\x{22}\x{5C}\x{0A}\x{0D}])|${r_ECHAR})*"/o;
133 14 my $r_STRING_LITERAL_LONG1 = qr/'''(('|'')?([^'\\]|${r_ECHAR}))*'''/o;
134 14 my $r_STRING_LITERAL_LONG2 = qr/"""(("|"")?([^"\\]|${r_ECHAR}))*"""/o;
135 14 my $r_LANGTAG = qr/@[a-zA-Z]+(-[a-zA-Z0-9]+)*/o;
136 14 my $r_LANGTAG_12 = qr/@[a-zA-Z]+(-[a-zA-Z0-9]+)*(--[a-zA-Z]+)?/o;
137 14 my $r_IRI_REF = qr/<([^<>"{}|^`\\\x{00}-\x{20}])*>/o;
138 14 my $r_PN_CHARS_BASE = qr/([A-Z]|[a-z]|[\x{00C0}-\x{00D6}]|[\x{00D8}-\x{00F6}]|[\x{00F8}-\x{02FF}]|[\x{0370}-\x{037D}]|[\x{037F}-\x{1FFF}]|[\x{200C}-\x{200D}]|[\x{2070}-\x{218F}]|[\x{2C00}-\x{2FEF}]|[\x{3001}-\x{D7FF}]|[\x{F900}-\x{FDCF}]|[\x{FDF0}-\x{FFFD}]|[\x{10000}-\x{EFFFF}])/o;
139 14 my $r_PN_CHARS_U = qr/([_]|${r_PN_CHARS_BASE})/o;
140 14 my $r_VARNAME = qr/((${r_PN_CHARS_U}|[0-9])(${r_PN_CHARS_U}|[0-9]|\x{00B7}|[\x{0300}-\x{036F}]|[\x{203F}-\x{2040}])*)/o;
141 14 my $r_VAR1 = qr/[?]${r_VARNAME}/o;
142 14 my $r_VAR2 = qr/[\$]${r_VARNAME}/o;
143 14 my $r_PN_CHARS = qr/${r_PN_CHARS_U}|-|[0-9]|\x{00B7}|[\x{0300}-\x{036F}]|[\x{203F}-\x{2040}]/o;
144 14 my $r_PN_PREFIX = qr/(${r_PN_CHARS_BASE}((${r_PN_CHARS}|[.])*${r_PN_CHARS})?)/o;
145 14 my $r_PN_LOCAL_ESCAPED = qr{(\\([-~.!&'()*+,;=/?#@%_\$]))|%[0-9A-Fa-f]{2}}o;
146 14 my $r_PN_LOCAL = qr/((${r_PN_CHARS_U}|[:0-9]|${r_PN_LOCAL_ESCAPED})((${r_PN_CHARS}|${r_PN_LOCAL_ESCAPED}|[:.])*(${r_PN_CHARS}|[:]|${r_PN_LOCAL_ESCAPED}))?)/o;
147 14 my $r_PN_LOCAL_BNODE = qr/((${r_PN_CHARS_U}|[0-9])((${r_PN_CHARS}|[.])*${r_PN_CHARS})?)/o;
148 14 my $r_PNAME_NS = qr/((${r_PN_PREFIX})?:)/o;
149 14 my $r_PNAME_LN = qr/(${r_PNAME_NS}${r_PN_LOCAL})/o;
150 14 my $r_EXPONENT = qr/[eE][-+]?\d+/o;
151 14 my $r_DOUBLE = qr/\d+[.]\d*${r_EXPONENT}|[.]\d+${r_EXPONENT}|\d+${r_EXPONENT}/o;
152 14 my $r_DECIMAL = qr/(\d+[.]\d*)|([.]\d+)/o;
153 14 my $r_INTEGER = qr/\d+/o;
154 14 my $r_BLANK_NODE_LABEL = qr/_:${r_PN_LOCAL_BNODE}/o;
155 14 my $r_ANON = qr/\[[\t\r\n ]*\]/o;
156 14 my $r_NIL = qr/\([\n\r\t ]*\)/o;
157 14 my $r_KEYWORDS = qr/(ABS|ADD|ALL|ASC|ASK|AS|AVG|BASE|BIND|BNODE|BOUND|BY|CEIL|CLEAR|COALESCE|CONCAT|CONSTRUCT|CONTAINS|COPY|COUNT|CREATE|DATA|DATATYPE|DAY|DEFAULT|DELETE|DELETE WHERE|DESCRIBE|DESC|DISTINCT|DISTINCT|DROP|ENCODE_FOR_URI|EXISTS|FILTER|FLOOR|FOLD|FROM|GRAPH|GROUP_CONCAT|GROUP|HASLANG|HASLANGDIR|HAVING|HINT|HOURS|IF|IN|INSERT|INTO|IRI|ISBLANK|ISIRI|ISLITERAL|ISNUMERIC|ISURI|LANGDIR|LANGMATCHES|LANG|LCASE|LIMIT|LOAD|MAX|MD5|MINUS|MINUTES|MIN|MONTH|MOVE|NAMED|NOT|NOW|OFFSET|OPTIONAL|ORDER|PREFIX|RAND|REDUCED|REGEX|REPLACE|ROUND|SAMETERM|SAMPLE|SECONDS|SELECT|SEPARATOR|SERVICE|SHA1|SHA256|SHA384|SHA512|SILENT|STR|STRAFTER|STRBEFORE|STRDT|STRENDS|STRLANG|STRLEN|STRSTARTS|STRUUID|SUBSTR|SUM|TIMEZONE|TO|TZ|UCASE|UNDEF|UNFOLD|UNION|URI|USING|UUID|VALUES|WHERE|WITH|YEAR)(?!:)\b/io;
158 14 my $r_KEYWORDS_12 = qr/(VERSION|ABS|ADD|ALL|ASC|ASK|AS|AVG|BASE|BIND|BNODE|BOUND|BY|CEIL|CLEAR|COALESCE|CONCAT|CONSTRUCT|CONTAINS|COPY|COUNT|CREATE|DATA|DATATYPE|DAY|DEFAULT|DELETE|DELETE WHERE|DESCRIBE|DESC|DISTINCT|DISTINCT|DROP|ENCODE_FOR_URI|EXISTS|FILTER|FLOOR|FOLD|FROM|GRAPH|GROUP_CONCAT|GROUP|HASLANG|HASLANGDIR|HAVING|HINT|HOURS|IF|IN|INSERT|INTO|IRI|ISBLANK|ISIRI|ISLITERAL|ISNUMERIC|ISTRIPLE|ISURI|LANGDIR|LANGMATCHES|LANG|LCASE|LIMIT|LOAD|MAX|MD5|MINUS|MINUTES|MIN|MONTH|MOVE|NAMED|NOT|NOW|OBJECT|OFFSET|OPTIONAL|ORDER|PREDICATE|PREFIX|RAND|REDUCED|REGEX|REPLACE|ROUND|SAMETERM|SAMPLE|SECONDS|SELECT|SEPARATOR|SERVICE|SHA1|SHA256|SHA384|SHA512|SILENT|STR|STRAFTER|STRBEFORE|STRDT|STRENDS|STRLANGDIR|STRLANG|STRLEN|STRSTARTS|STRUUID|SUBJECT|SUBSTR|SUM|TIMEZONE|TO|TRIPLE|TZ|UCASE|UNDEF|UNFOLD|UNION|URI|USING|UUID|VALUES|WHERE|WITH|YEAR)(?!:)\b/io;
159  
160 67 ▶ sub BUILD {
Subroutine BUILD: called CC=8 SCAR=21.9
Pod undocumented
161 67 my $self = shift;
162 my %METHOD_TOKEN = (
163 # q[#] => '_get_comment',
164 q[@] => '_get_lang',
165 q[<] => '_get_iriref_or_relational',
166 q[{] => '_get_brace_or_annotation_or_or',
167 q[}] => '_get_brace_or_annotation_or_or',
168 q[|] => '_get_brace_or_annotation_or_or',
169 q[_] => '_get_bnode',
170 q['] => '_get_single_literal',
171 q["] => '_get_double_literal',
172 q[:] => '_get_pname',
173 q[?] => '_get_variable',
174 q[$] => '_get_variable',
175 q[!] => '_get_bang',
176 q[>] => '_get_iriref_or_relational',
177 q([) => '_get_lbracket_or_anon',
178 q[(] => '_get_lparen_or_nil',
179 q[)] => '_get_rparen_or_pgtgt',
180 67 (map {$_ => '_get_number'} (0 .. 9, '-', '+'))
181 );
182 67 ▶ while (my ($k,$v) = each(%METHOD_TOKEN)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %METHOD_TOKEN) 1876 67 1943
183 1876 ▶ if (length($k) != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $k != 1) 0 1876 1876
184 0 die "Cannot set a lookahead token handler method with lookahead > 1 char";
185 }
186 1876 ▶ $self->lookahead_methods->{$k} //= $v;
Condition33%1/3
$self->lookahead_methods->{$k} //= $v
l!l&&r!l&&!r
018760
MC/DC0%0/2
$self->lookahead_methods->{$k} //= $v
$self->lookahead_methods->{$k} $v
Truth table33%1/3
A //= B
A= $self->lookahead_methods->{$k}B= $v
ABresult
1X1
011
000
187 }
188  
189 67 my %CHAR_TOKEN = (
190 ',' => COMMA,
191 '.' => DOT,
192 '=' => EQUALS,
193 ']' => RBRACKET,
194 '-' => MINUS,
195 '+' => PLUS,
196 ';' => SEMICOLON,
197 '/' => SLASH,
198 '*' => STAR,
199 '~' => TILDE,
200 );
201 67 ▶ while (my ($k,$v) = each(%CHAR_TOKEN)) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %CHAR_TOKEN) 670 67 737
202 670 ▶ if (length($k) != 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $k != 1) 0 670 670
203 0 die "Cannot set a lookahead token with lookahead > 1 char";
204 }
205 670 ▶ $self->lookahead_tokens->{$k} //= $v;
Condition33%1/3
$self->lookahead_tokens->{$k} //= $v
l!l&&r!l&&!r
06700
MC/DC0%0/2
$self->lookahead_tokens->{$k} //= $v
$self->lookahead_tokens->{$k} $v
Truth table33%1/3
A //= B
A= $self->lookahead_tokens->{$k}B= $v
ABresult
1X1
011
000
206 }
207
208 67 ▶ if ($self->version ge '1.2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->version ge '1.2') { } 63 4 67
209 63 ▶ $self->add_regex_rule( $r_KEYWORDS_12, KEYWORD, sub { return uc(shift) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
210 } else {
211 4 ▶ $self->add_regex_rule( $r_KEYWORDS, KEYWORD, sub { return uc(shift) } );
Subroutine __ANON__: called CC=1 SCAR=0.0
212 }
213 }
214  
215 349 ▶ sub sparql12 {
Subroutine sparql12: called CC=1 SCAR=0.0
Pod undocumented
216 349 my $self = shift;
217 349 return ($self->version ge '1.2');
218 }
219  
220 5848 ▶ sub peek {
Subroutine peek: called CC=2 SCAR=6.9
Pod undocumented
221 5848 my $self = shift;
222 5848 my $b = $self->token_buffer;
223 5848 my $t = $self->next;
224 5847 ▶ return unless ($t);
Branch: 1 branch
BranchTrueFalseTotal
unless $t 279 5568 5847
225 5568 push(@$b, $t);
226 5568 return $t;
227 }
228
229 6649 ▶ sub next {
Subroutine next: called CC=2 SCAR=6.9
Pod undocumented
230 6649 my $self = shift;
231 6649 my $b = $self->token_buffer;
232 6649 ▶ if (scalar(@$b)) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$b) { } 5567 1082 6649
233 5567 return shift(@$b);
234 } else {
235 1082 return $self->get_token();
236 }
237 }
238
239 4 ▶ sub codepoint_unescape {
Subroutine codepoint_unescape: called CC=3 SCAR=11.4
Pod undocumented
240 4 my $self = shift;
241 4 my $value = shift;
242 14 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
243 4 $value =~ s{\\(?:(?:u([0-9A-Fa-f]{4}))|(?:U([0-9A-Fa-f]{8})))}{
244 4 my $h = $1 . $2;
245 4 my $codepoint = hex($h);
246 4 ▶ if ($codepoint >= 0xD800 and $codepoint <= 0xDFFF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($codepoint >= 55296 and $codepoint <= 57343) 0 4 4
Condition33%1/3
$codepoint >= 55296 and $codepoint <= 57343
!ll&&!rl&&r
400
MC/DC0%0/2
$codepoint >= 55296 and $codepoint <= 57343
$codepoint >= 55296 $codepoint <= 57343
Truth table33%1/3
A and B
A= $codepoint >= 55296B= $codepoint <= 57343
ABresult
0X0
100
111
247 0 die "Unicode surrogate U+$h is illegal in UTF-8";
248 }
249 4 chr($codepoint);
250 }ge;
251 4 return $value;
252 }
253
254 662 ▶ sub fill_buffer {
Subroutine fill_buffer: called CC=5 SCAR=16.4
Pod undocumented
255 662 my $self = shift;
256 662 ▶ unless (length($self->buffer)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $self->buffer) 662 0 662
257 662 AGAIN:
258 my $line = $self->file->getline;
259 662 ▶ if (defined($line)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $line) 92 570 662
260 92 ▶ if ($self->version lt '1.2') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->version lt "1.2") 4 88 92
261 # codepoint escape handling has moved into the literal and IRI handling in SPARQL 1.2+
262 4 $line = $self->codepoint_unescape($line);
263 }
264 92 $self->{buffer} .= $line;
265 92 ▶ if ($line =~ /[[(]\s*$/) { # might be a NIL or ANON that spans a line
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /[[(]\s*$/u) 0 92 92
266 0 goto AGAIN;
267 }
268 }
269 }
270 }
271
272 794 ▶ sub new_token {
Subroutine new_token: called CC=1 SCAR=0.0
Pod undocumented
273 794 my $self = shift;
274 794 my $type = shift;
275 794 my $start_line = shift;
276 794 my $start_col = shift;
277 794 my $line = $self->line;
278 794 my $col = $self->column;
279 794 return AtteanX::SPARQL::Token->fast_constructor( $type, $start_line, $start_col, $line, $col, \@_ );
280 }
281  
282 120 ▶ sub add_regex_rule {
Subroutine add_regex_rule: called CC=1 SCAR=0.0
Pod undocumented
283 120 my $self = shift;
284 120 my $r = shift;
285 120 my $ttype = shift;
286 120 my $convert = shift;
287 120 my $extend = $self->extend;
288 1357 ▶ push(@$extend, sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
289 1357 my $l = shift;
290
291 1357 ▶ if ($l->buffer =~ /^$r\b/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($l->buffer =~ /^$r\b/u) 183 1174 1357
292 183 my $value = $self->read_length($+[0]);
293 183 ▶ my $c = $convert ? $convert->($value) : $value;
Branch: 1 branch
BranchTrueFalseTotal
$convert ? : 183 0 183
294 183 return $l->new_token($ttype, $l->start_line, $l->start_column, $c);
295 }
296 120 });
297 }
298
299 1082 ▶ sub get_token {
Subroutine get_token: called CC=21 SCAR=36.2
Pod undocumented
300 1082 my $self = shift;
301 1082 while (1) {
302 1756 ▶ $self->fill_buffer unless (length($self->buffer));
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->buffer 377 1379 1756
303  
304 1756 my $start_column = $self->column;
305 1756 my $start_line = $self->line;
306
307 1756 $self->start_column( $start_column );
308 1756 $self->start_line( $start_line );
309
310 1756 ▶ if ($self->buffer =~ /^[ \r\n\t]+/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffer =~ /^[ \r\n\t]+/ou) 674 1082 1756
311 674 my $ws = $self->read_length($+[0]);
312 # we're ignoring whitespace tokens, but we could return them here instead of falling through to the 'next':
313 674 ▶ if ($self->include_ws) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->include_ws) 0 674 674
314 0 return $self->new_token(WS, $start_line, $start_column, $ws);
315 }
316 674 next;
317 }
318  
319 1082 my $c = $self->peek_char();
320 1082 ▶ return unless (defined($c));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 285 797 1082
321  
322 797 ▶ if ($c eq '#') {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "#") 0 797 797
323 # we're ignoring comment tokens, but we could return them here instead of falling through to the 'next':
324 0 my $c = $self->_get_comment();
325 0 ▶ if ($self->include_ws) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->include_ws) 0 0 0
326 0 return $c;
327 }
328 0 next;
329 }
330
331 797 foreach my $e (@{ $self->extend }) {
332 1357 ▶ if (my $t = $e->( $self )) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $t = &$e($self)) 183 1174 1357
333 183 return $t;
334 }
335 }
336
337 614 ▶ if ($c eq '.' and $self->buffer =~ /^$r_DECIMAL/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c eq "." and $self->buffer =~ /^$r_DECIMAL/u) 0 614 614
Condition66%2/3
$c eq "." and $self->buffer =~ /^$r_DECIMAL/u
!ll&&!rl&&r
60590
MC/DC0%0/2
$c eq "." and $self->buffer =~ /^$r_DECIMAL/u
$c eq "." $self->buffer =~ /^$r_DECIMAL/u
Truth table66%2/3
A and B
A= $c eq "."B= $self->buffer =~ /^$r_DECIMAL/u
ABresult
0X0
100
111
338 0 return $self->_get_number();
339 }
340
341 614 ▶ if (defined(my $name = $self->lookahead_tokens->{$c})) { $self->get_char; return $self->new_token($name, $start_line, $start_column, $c); }
Branch: 5 branches
BranchTrueFalseTotal
if (defined(my $name = $self->lookahead_tokens->{$c})) { } 66 548 614
elsif (defined(my $method = $self->lookahead_methods->{$c})) { } 486 62 548
elsif ($c =~ /[A-Za-z\x{00C0}-\x{00D6}\x{00D8}-\x{00F6}\x{00F8}-\x{02FF}\x{0370}-\x{037D}\x{037F}-\x{1FFF}\x{200C}-\x{200D}\x{2070}-\x{218F}\x{2C00}-\x{2FEF}\x{3001}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFFD}\x{10000}-\x{EFFFF}]/ou) { } 61 1 62
elsif ($c eq '^') { } 0 1 1
elsif ($c eq '&') { } 1 0 1
342 486 elsif (defined(my $method = $self->lookahead_methods->{$c})) { return $self->$method() }
343 elsif ($c =~ /[A-Za-z\x{00C0}-\x{00D6}\x{00D8}-\x{00F6}\x{00F8}-\x{02FF}\x{0370}-\x{037D}\x{037F}-\x{1FFF}\x{200C}-\x{200D}\x{2070}-\x{218F}\x{2C00}-\x{2FEF}\x{3001}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFFD}\x{10000}-\x{EFFFF}]/o) {
344 61 ▶ if ($self->buffer =~ /^a(?!:)\s/o) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->buffer =~ /^a(?!:)\s/ou) { } 13 48 61
elsif ($self->buffer =~ /^(?i:true|false)(?!:)\b/ou) { } 6 42 48
elsif ($self->buffer =~ /^BASE(?!:)\b/iou) { } 0 42 42
elsif ($self->buffer =~ /^PREFIX(?!:)\b/iou) { } 0 42 42
345 13 $self->get_char;
346 13 return $self->new_token(A, $start_line, $start_column, 'a');
347 } elsif ($self->buffer =~ /^(?i:true|false)(?!:)\b/o) {
348 6 my $bool = $self->read_length($+[0]);
349 6 return $self->new_token(BOOLEAN, $start_line, $start_column, lc($bool));
350 # } elsif ($self->buffer =~ /^$r_KEYWORDS/) {
351 # my $bool = $self->read_length($+[0]);
352 # return $self->new_token(KEYWORD, $start_line, $start_column, $bool);
353 } elsif ($self->buffer =~ /^BASE(?!:)\b/oi) {
354 0 $self->read_length(4);
355 0 return $self->new_token(BASE, $start_line, $start_column, 'BASE');
356 } elsif ($self->buffer =~ /^PREFIX(?!:)\b/io) {
357 0 $self->read_length(6);
358 0 return $self->new_token(PREFIX, $start_line, $start_column, 'PREFIX');
359 } else {
360 42 return $self->_get_pname;
361 }
362 } elsif ($c eq '^') {
363 0 ▶ if ($self->buffer =~ /^\^\^/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffer =~ /^\^\^/u) { } 0 0 0
364 0 $self->read_word('^^');
365 0 return $self->new_token(HATHAT, $start_line, $start_column, '^^');
366 } else {
367 0 $self->read_word('^');
368 0 return $self->new_token(HAT, $start_line, $start_column, '^');
369 }
370 } elsif ($c eq '&') {
371 1 $self->read_word('&&');
372 1 return $self->new_token(ANDAND, $start_line, $start_column, '&&');
373 } else {
374 # Carp::cluck sprintf("Unexpected byte '$c' (0x%02x)", ord($c));
375 0 return $self->_throw_error(sprintf("Unexpected byte '%s' (0x%02x)", $c, ord($c)));
376 }
377 0 warn sprintf('byte: 0x%x', ord($c));
378 }
379 }
380  
381 53 ▶ sub _get_pname {
Subroutine _get_pname: called CC=3 SCAR=11.0
382 53 my $self = shift;
383 53 my $prefix = '';
384
385 53 ▶ if ($self->buffer =~ /^$r_PNAME_LN/o) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->buffer =~ /^$r_PNAME_LN/ou) { } 35 18 53
elsif ($self->buffer =~ /$r_PNAME_NS/u) { } 16 2 18
386 35 my $ln = $self->read_length($+[0]);
387 35 my ($ns, $local) = ($ln =~ /^([^:]*:)(.*)$/);
388 14 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
389 35 $local =~ s{\\([-~.!&'()*+,;=:/?#@%_\$])}{$1}g;
390 35 return $self->new_token(PREFIXNAME, $self->start_line, $self->start_column, $ns, $local);
391 } elsif ($self->buffer =~ $r_PNAME_NS) {
392 16 my $ns = $self->read_length($+[0]);
393 16 return $self->new_token(PREFIXNAME, $self->start_line, $self->start_column, $ns);
394 } else {
395 2 $self->_throw_error("Expected PNAME");
396 }
397 }
398  
399 144 ▶ sub _get_variable {
Subroutine _get_variable: called CC=4 SCAR=19.1
400 144 my $self = shift;
401 144 ▶ if (substr($self->buffer, 0, 1) eq '$') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->buffer, 0, 1) eq '$') { } 0 144 144
402 0 $self->get_char_safe('$');
403 0 ▶ if ($self->buffer =~ /^$r_VARNAME/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffer =~ /^$r_VARNAME/u) { } 0 0 0
404 0 my $name = $self->read_length($+[0]);
405 0 return $self->new_token(VAR, $self->start_line, $self->start_column, $name);
406 } else {
407 0 $self->_throw_error("Invalid variable name");
408 }
409 } else {
410 144 $self->get_char_safe('?');
411 144 ▶ if ($self->buffer =~ /^$r_VARNAME/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffer =~ /^$r_VARNAME/u) { } 144 0 144
412 144 my $name = $self->read_length($+[0]);
413 144 return $self->new_token(VAR, $self->start_line, $self->start_column, $name);
414 } else {
415 0 return $self->new_token(QUESTION, $self->start_line, $self->start_column, '?');
416 }
417 }
418 }
419
420 99 ▶ sub _get_iriref_or_relational {
Subroutine _get_iriref_or_relational: called CC=24 SCAR=50.5
421 99 my $self = shift;
422 99 my $buffer = $self->buffer;
423 99 ▶ if ($buffer =~ m/^<([^<>"{}|^`\x00-\x20])*>/) {
Branch: 8 branches
BranchTrueFalseTotal
if ($buffer =~ /^<([^<>"{}|^`\x00-\x20])*>/u) { } 87 12 99
elsif (substr($buffer, 0, 2) eq '<=') { } 0 12 12
elsif (substr($buffer, 0, 2) eq '>=') { } 0 12 12
elsif ($self->sparql12 and substr($buffer, 0, 3) eq '<<(') { } 1 11 12
elsif ($self->sparql12 and substr($buffer, 0, 2) eq '<<') { } 4 7 11
elsif ($self->sparql12 and substr($buffer, 0, 2) eq '>>') { } 4 3 7
elsif (substr($buffer, 0, 1) eq '>') { } 1 2 3
elsif (substr($buffer, 0, 1) eq '<') { } 2 0 2
424 87 $self->get_char_safe(q[<]);
425 87 ▶ if ($self->buffer =~ m/^[\x23-\x3d\x3f-\x5a\x5d-\x7e]*>/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffer =~ /^[\x23-\x3d\x3f-\x5a\x5d-\x7e]*>/ou) 87 0 87
426 87 my $iri .= $self->read_length($+[0]);
427 87 chop($iri);
428 87 return $self->new_token(IRI, $self->start_line, $self->start_column, $iri);
429 }
430
431 0 my $iri = '';
432 0 while (1) {
433 0 ▶ if (length($self->buffer) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->buffer == 0) 0 0 0
434 0 my $c = $self->peek_char;
435 0 ▶ last unless defined($c);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $c 0 0 0
436 }
437 0 ▶ if (substr($self->buffer, 0, 1) eq '\\') {
Branch: 3 branches
BranchTrueFalseTotal
if (substr($self->buffer, 0, 1) eq '\\') { } 0 0 0
elsif ($self->buffer =~ /^[^<>\x00-\x20\\"{}|^`]+/ou) { } 0 0 0
elsif (substr($self->buffer, 0, 1) eq '>') { } 0 0 0
438 0 $self->get_char_safe('\\');
439 0 my $esc = $self->get_char;
440 0 ▶ if ($esc eq '\\') {
Branch: 3 branches
BranchTrueFalseTotal
if ($esc eq '\\') { } 0 0 0
elsif ($esc eq 'U') { } 0 0 0
elsif ($esc eq 'u') { } 0 0 0
441 0 $iri .= "\\";
442 } elsif ($esc eq 'U') {
443 0 my $codepoint = $self->read_length(8);
444 0 ▶ $self->_throw_error("Bad unicode escape codepoint '$codepoint'") unless ($codepoint =~ /^[0-9A-Fa-f]+$/o);
Branch: 1 branch
BranchTrueFalseTotal
unless $codepoint =~ /^[0-9A-Fa-f]+$/ou 0 0 0
445 0 $iri .= chr(hex($codepoint));
446 } elsif ($esc eq 'u') {
447 0 my $codepoint = $self->read_length(4);
448 0 ▶ $self->_throw_error("Bad unicode escape codepoint '$codepoint'") unless ($codepoint =~ /^[0-9A-Fa-f]+$/o);
Branch: 1 branch
BranchTrueFalseTotal
unless $codepoint =~ /^[0-9A-Fa-f]+$/ou 0 0 0
449 0 my $char = chr(hex($codepoint));
450 0 ▶ if ($char =~ /[<>" {}|\\^`]/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char =~ /[<>" {}|\\^`]/ou) 0 0 0
451 0 $self->_throw_error(sprintf("Bad IRI character: '%s' (0x%x)", $char, ord($char)));
452 }
453 0 $iri .= $char;
454 } else {
455 0 $self->_throw_error("Unrecognized iri escape '$esc'");
456 }
457 } elsif ($self->buffer =~ /^[^<>\x00-\x20\\"{}|^`]+/o) {
458 0 $iri .= $self->read_length($+[0]);
459 } elsif (substr($self->buffer, 0, 1) eq '>') {
460 0 last;
461 } else {
462 0 my $c = $self->peek_char;
463 0 $self->_throw_error("Got '$c' while expecting IRI character");
464 }
465 }
466 0 $self->get_char_safe(q[>]);
467 0 return $self->new_token(IRI, $self->start_line, $self->start_column, $iri);
468 } elsif (substr($buffer, 0, 2) eq '<=') {
469 0 $self->read_length(2);
470 0 return $self->new_token(LE, $self->start_line, $self->start_column, '<=');
471 } elsif (substr($buffer, 0, 2) eq '>=') {
472 0 $self->read_length(2);
473 0 return $self->new_token(GE, $self->start_line, $self->start_column, '>=');
474 ▶ } elsif ($self->sparql12 and substr($buffer, 0, 3) eq '<<(') {
Condition66%2/3
$self->sparql12 and substr($buffer, 0, 3) eq "<<("
!ll&&!rl&&r
0111
MC/DC50%1/2
$self->sparql12 and substr($buffer, 0, 3) eq "<<("
$self->sparql12 substr($buffer, 0, 3) eq "<<("
Truth table66%2/3
A and B
A= $self->sparql12B= substr($buffer, 0, 3) eq "<<("
ABresult
0X0
100
111
475 1 $self->read_length(3);
476 1 return $self->new_token(LTLTP, $self->start_line, $self->start_column, '<<(');
477 ▶ } elsif ($self->sparql12 and substr($buffer, 0, 2) eq '<<') {
Condition66%2/3
$self->sparql12 and substr($buffer, 0, 2) eq "<<"
!ll&&!rl&&r
074
MC/DC50%1/2
$self->sparql12 and substr($buffer, 0, 2) eq "<<"
$self->sparql12 substr($buffer, 0, 2) eq "<<"
Truth table66%2/3
A and B
A= $self->sparql12B= substr($buffer, 0, 2) eq "<<"
ABresult
0X0
100
111
478 4 $self->read_length(2);
479 4 return $self->new_token(LTLT, $self->start_line, $self->start_column, '<<');
480 ▶ } elsif ($self->sparql12 and substr($buffer, 0, 2) eq '>>') {
Condition66%2/3
$self->sparql12 and substr($buffer, 0, 2) eq ">>"
!ll&&!rl&&r
034
MC/DC50%1/2
$self->sparql12 and substr($buffer, 0, 2) eq ">>"
$self->sparql12 substr($buffer, 0, 2) eq ">>"
Truth table66%2/3
A and B
A= $self->sparql12B= substr($buffer, 0, 2) eq ">>"
ABresult
0X0
100
111
481 4 $self->read_length(2);
482 4 return $self->new_token(GTGT, $self->start_line, $self->start_column, '>>');
483 } elsif (substr($buffer, 0, 1) eq '>') {
484 1 $self->get_char;
485 1 return $self->new_token(GT, $self->start_line, $self->start_column, '>');
486 } elsif (substr($buffer, 0, 1) eq '<') {
487 2 $self->get_char;
488 2 return $self->new_token(LT, $self->start_line, $self->start_column, '<');
489 } else {
490 0 die "Unrecognized relational op near '$buffer'";
491 }
492 }
493  
494 1 ▶ sub _get_bang {
Subroutine _get_bang: called CC=2 SCAR=7.9
495 1 my $self = shift;
496 1 ▶ if ($self->buffer =~ /^!=/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffer =~ /^!=/u) { } 0 1 1
497 0 $self->read_length(2);
498 0 return $self->new_token(NOTEQUALS, $self->start_line, $self->start_column, '!=');
499 } else {
500 1 $self->get_char;
501 1 return $self->new_token(BANG, $self->start_line, $self->start_column, '!');
502 }
503 }
504
505 0 ▶ sub _get_bnode {
Subroutine _get_bnode: not called CC=2 SCAR=17.9
506 0 my $self = shift;
507 0 ▶ unless ($self->buffer =~ /^$r_BLANK_NODE_LABEL/o) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->buffer =~ /^$r_BLANK_NODE_LABEL/ou) 0 0 0
508 0 $self->_throw_error("Expected: name");
509 }
510 0 my $ln = $self->read_length($+[0]);
511 0 my $name = substr($ln, 2);
512 0 return $self->new_token(BNODE, $self->start_line, $self->start_column, $name);
513 }
514  
515 18 ▶ sub _get_number {
Subroutine _get_number: called CC=4 SCAR=14.0
516 18 my $self = shift;
517 18 ▶ if ($self->buffer =~ /^${r_DOUBLE}/o) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->buffer =~ /^$r_DOUBLE/ou) { } 1 17 18
elsif ($self->buffer =~ /^$r_DECIMAL/ou) { } 1 16 17
elsif ($self->buffer =~ /^$r_INTEGER/ou) { } 16 0 16
518 1 return $self->new_token(DOUBLE, $self->start_line, $self->start_column, $self->read_length($+[0]));
519 } elsif ($self->buffer =~ /^${r_DECIMAL}/o) {
520 1 return $self->new_token(DECIMAL, $self->start_line, $self->start_column, $self->read_length($+[0]));
521 } elsif ($self->buffer =~ /^${r_INTEGER}/o) {
522 16 return $self->new_token(INTEGER, $self->start_line, $self->start_column, $self->read_length($+[0]));
523 }
524 0 $self->_throw_error("Expected number");
525 }
526  
527 20 ▶ sub _get_lparen_or_nil {
Subroutine _get_lparen_or_nil: called CC=2 SCAR=6.9
528 20 my $self = shift;
529 20 ▶ if ($self->buffer =~ /^$r_NIL/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffer =~ /^$r_NIL/u) { } 1 19 20
530 1 $self->read_length($+[0]);
531 1 return $self->new_token(NIL, $self->start_line, $self->start_column, '()');
532 } else {
533 19 $self->get_char_safe('(');
534 19 return $self->new_token(LPAREN, $self->start_line, $self->start_column, '(');
535 }
536 }
537
538 19 ▶ sub _get_rparen_or_pgtgt {
Subroutine _get_rparen_or_pgtgt: called CC=3 SCAR=11.0
539 19 my $self = shift;
540 19 ▶ if ($self->sparql12 and substr($self->buffer, 0, 3) eq ')>>') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->sparql12 and substr($self->buffer, 0, 3) eq ')>>') { } 1 18 19
Condition66%2/3
$self->sparql12 and substr($self->buffer, 0, 3) eq ")>>"
!ll&&!rl&&r
0181
MC/DC50%1/2
$self->sparql12 and substr($self->buffer, 0, 3) eq ")>>"
$self->sparql12 substr($self->buffer, 0, 3) eq ")>>"
Truth table66%2/3
A and B
A= $self->sparql12B= substr($self->buffer, 0, 3) eq ")>>"
ABresult
0X0
100
111
541 1 $self->read_length(3);
542 1 return $self->new_token(PGTGT, $self->start_line, $self->start_column, ')>>');
543 } else {
544 18 $self->get_char_safe(')');
545 18 return $self->new_token(RPAREN, $self->start_line, $self->start_column, ')');
546 }
547 }
548
549 148 ▶ sub _get_brace_or_annotation_or_or {
Subroutine _get_brace_or_annotation_or_or: called CC=8 SCAR=21.4
550 148 my $self = shift;
551 148 ▶ if ($self->sparql12 and substr($self->buffer, 0, 2) eq '{|') {
Branch: 5 branches
BranchTrueFalseTotal
if ($self->sparql12 and substr($self->buffer, 0, 2) eq '{|') { } 2 146 148
elsif ($self->sparql12 and substr($self->buffer, 0, 2) eq '|}') { } 2 144 146
elsif (substr($self->buffer, 0, 2) eq '||') { } 0 144 144
elsif (substr($self->buffer, 0, 1) eq '{') { } 73 71 144
elsif (substr($self->buffer, 0, 1) eq '}') { } 71 0 71
Condition100%3/3
$self->sparql12 and substr($self->buffer, 0, 2) eq "{|"
!ll&&!rl&&r
41422
MC/DC100%2/2
$self->sparql12 and substr($self->buffer, 0, 2) eq "{|"
$self->sparql12 substr($self->buffer, 0, 2) eq "{|"
Truth table100%3/3
A and B
A= $self->sparql12B= substr($self->buffer, 0, 2) eq "{|"
ABresult
0X0
100
111
552 2 $self->read_length(2);
553 2 return $self->new_token(LANNOT, $self->start_line, $self->start_column, '{|');
554 ▶ } elsif ($self->sparql12 and substr($self->buffer, 0, 2) eq '|}') {
Condition100%3/3
$self->sparql12 and substr($self->buffer, 0, 2) eq "|}"
!ll&&!rl&&r
41402
MC/DC100%2/2
$self->sparql12 and substr($self->buffer, 0, 2) eq "|}"
$self->sparql12 substr($self->buffer, 0, 2) eq "|}"
Truth table100%3/3
A and B
A= $self->sparql12B= substr($self->buffer, 0, 2) eq "|}"
ABresult
0X0
100
111
555 2 $self->read_length(2);
556 2 return $self->new_token(RANNOT, $self->start_line, $self->start_column, '|}');
557 } elsif (substr($self->buffer, 0, 2) eq '||') {
558 0 $self->read_length(2);
559 0 return $self->new_token(OROR, $self->start_line, $self->start_column, '||');
560 } elsif (substr($self->buffer, 0, 1) eq '{') {
561 73 $self->get_char_safe('{');
562 73 return $self->new_token(LBRACE, $self->start_line, $self->start_column, '{');
563 } elsif (substr($self->buffer, 0, 1) eq '}') {
564 71 $self->get_char_safe('}');
565 71 return $self->new_token(RBRACE, $self->start_line, $self->start_column, '}');
566 } else {
567 0 $self->get_char_safe('|');
568 0 return $self->new_token(OR, $self->start_line, $self->start_column, '|');
569 }
570 }
571  
572 0 ▶ sub _get_lbracket_or_anon {
Subroutine _get_lbracket_or_anon: not called CC=2 SCAR=17.9
573 0 my $self = shift;
574 0 ▶ if ($self->buffer =~ /^$r_ANON/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffer =~ /^$r_ANON/u) { } 0 0 0
575 0 $self->read_length($+[0]);
576 0 return $self->new_token(ANON, $self->start_line, $self->start_column, '[]');
577 } else {
578 0 $self->get_char_safe('[');
579 0 return $self->new_token(LBRACKET, $self->start_line, $self->start_column, '[');
580 }
581 }
582
583 0 ▶ sub _get_comment {
Subroutine _get_comment: not called CC=5 SCAR=34.0
584 0 my $self = shift;
585 0 $self->get_char_safe('#');
586 0 my $comment = '';
587 0 my $c = $self->peek_char;
588 0 ▶ while (length($c) and $c !~ /[\r\n]/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $c and not $c =~ /[\r\n]/ou) 0 0 0
Condition0%0/3
length $c and not $c =~ /[\r\n]/ou
!ll&&!rl&&r
000
MC/DC0%0/2
length $c and not $c =~ /[\r\n]/ou
length $c not $c =~ /[\r\n]/ou
Truth table0%0/3
A and not(B)
A= length $cB= not $c =~ /[\r\n]/ou
ABresult
0X0
100
111
589 0 $comment .= $self->get_char;
590 0 $c = $self->peek_char;
591 }
592 0 ▶ if (length($c) and $c =~ /[\r\n]/o) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $c and $c =~ /[\r\n]/ou) 0 0 0
Condition0%0/3
length $c and $c =~ /[\r\n]/ou
!ll&&!rl&&r
000
MC/DC0%0/2
length $c and $c =~ /[\r\n]/ou
length $c $c =~ /[\r\n]/ou
Truth table0%0/3
A and B
A= length $cB= $c =~ /[\r\n]/ou
ABresult
0X0
100
111
593 0 $self->get_char;
594 }
595 0 return $self->new_token(COMMENT, $self->start_line, $self->start_column, $comment);
596 }
597  
598 2 ▶ sub _get_lang {
Subroutine _get_lang: called CC=3 SCAR=11.6
599 2 my $self = shift;
600 2 ▶ my $lang_re = ($self->version ge '1.2') ? $r_LANGTAG_12 : $r_LANGTAG;
Branch: 1 branch
BranchTrueFalseTotal
$self->version ge '1.2' ? : 2 0 2
601 2 ▶ if ($self->buffer =~ $lang_re) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->buffer =~ /$lang_re/u) 2 0 2
602 2 my $lang = $self->read_length($+[0]);
603 2 substr($lang, 0, 1, ''); # remove the '@' prefix
604 2 return $self->new_token(LANG, $self->start_line, $self->start_column, $lang);
605 }
606 0 $self->_throw_error("Expected keyword or language tag");
607 }
608
609 16 ▶ sub _get_double_literal {
Subroutine _get_double_literal: called CC=12 SCAR=26.6
610 16 my $self = shift;
611 # my $c = $self->peek_char();
612 16 $self->get_char_safe(q["]);
613 16 ▶ if (substr($self->buffer, 0, 2) eq q[""]) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->buffer, 0, 2) eq '""') { } 4 12 16
614 # #x22 #x22 #x22 lcharacter* #x22 #x22 #x22
615 4 $self->read_word(q[""]);
616
617 4 my $quote_count = 0;
618 4 my $string = '';
619 4 while (1) {
620 16 ▶ if (length($self->buffer) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->buffer == 0) 0 16 16
621 0 $self->fill_buffer;
622 0 ▶ $self->_throw_error("Found EOF in string literal") if (length($self->buffer) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if length $self->buffer == 0 0 0 0
623 }
624 16 ▶ if (substr($self->buffer, 0, 1) eq '"') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->buffer, 0, 1) eq '"') { } 12 4 16
625 12 my $c = $self->get_char;
626 12 $quote_count++;
627 12 ▶ last if ($quote_count == 3);
Branch: 1 branch
BranchTrueFalseTotal
if $quote_count == 3 4 8 12
628 } else {
629 4 ▶ if ($quote_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_count) 0 4 4
630 0 $string .= '"' foreach (1..$quote_count);
631 0 $quote_count = 0;
632 }
633 4 ▶ if (substr($self->buffer, 0, 1) eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->buffer, 0, 1) eq '\\') { } 0 4 4
634 0 $string .= $self->read_backslash_escape();
635 } else {
636 4 $self->{buffer} =~ /^[^"\\]+/;
637 4 $string .= $self->read_length($+[0]);
638 }
639 }
640 }
641 4 return $self->new_token(STRING3D, $self->start_line, $self->start_column, $string);
642 } else {
643 ### #x22 scharacter* #x22
644 12 my $string = '';
645 12 while (1) {
646 26 ▶ if (substr($self->buffer, 0, 1) eq '\\') {
Branch: 3 branches
BranchTrueFalseTotal
if (substr($self->buffer, 0, 1) eq '\\') { } 5 21 26
elsif ($self->buffer =~ /^[^"\\]+/ou) { } 10 11 21
elsif (substr($self->buffer, 0, 1) eq '"') { } 11 0 11
647 5 $string .= $self->read_backslash_escape();
648 } elsif ($self->buffer =~ /^[^"\\]+/o) {
649 10 $string .= $self->read_length($+[0]);
650 } elsif (substr($self->buffer, 0, 1) eq '"') {
651 11 last;
652 } else {
653 0 my $c = $self->peek_char;
654 0 $self->_throw_error("Got '$c' while expecting string character");
655 }
656 }
657 11 $self->get_char_safe(q["]);
658 11 return $self->new_token(STRING1D, $self->start_line, $self->start_column, $string);
659 }
660 }
661  
662 8 ▶ sub _get_single_literal {
Subroutine _get_single_literal: called CC=12 SCAR=26.6
663 8 my $self = shift;
664 8 $self->get_char_safe("'");
665 8 ▶ if (substr($self->buffer, 0, 2) eq q['']) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->buffer, 0, 2) eq q['']) { } 5 3 8
666 # #x22 #x22 #x22 lcharacter* #x22 #x22 #x22
667 5 $self->read_word(q['']);
668
669 5 my $quote_count = 0;
670 5 my $string = '';
671 5 while (1) {
672 20 ▶ if (length($self->buffer) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $self->buffer == 0) 0 20 20
673 0 $self->fill_buffer;
674 0 ▶ $self->_throw_error("Found EOF in string literal") if (length($self->buffer) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if length $self->buffer == 0 0 0 0
675 }
676 20 ▶ if (substr($self->buffer, 0, 1) eq "'") {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->buffer, 0, 1) eq q[']) { } 15 5 20
677 15 my $c = $self->get_char;
678 15 $quote_count++;
679 15 ▶ last if ($quote_count == 3);
Branch: 1 branch
BranchTrueFalseTotal
if $quote_count == 3 5 10 15
680 } else {
681 5 ▶ if ($quote_count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($quote_count) 0 5 5
682 0 $string .= "'" foreach (1..$quote_count);
683 0 $quote_count = 0;
684 }
685 5 ▶ if (substr($self->buffer, 0, 1) eq '\\') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->buffer, 0, 1) eq '\\') { } 0 5 5
686 0 $string .= $self->read_backslash_escape();
687 } else {
688 5 $self->{buffer} =~ /^[^'\\]+/;
689 5 $string .= $self->read_length($+[0]);
690 }
691 }
692 }
693 5 return $self->new_token(STRING3S, $self->start_line, $self->start_column, $string);
694 } else {
695 ### #x22 scharacter* #x22
696 3 my $string = '';
697 3 while (1) {
698 6 ▶ if (substr($self->buffer, 0, 1) eq '\\') {
Branch: 3 branches
BranchTrueFalseTotal
if (substr($self->buffer, 0, 1) eq '\\') { } 1 5 6
elsif ($self->buffer =~ /^[^'\\]+/ou) { } 2 3 5
elsif (substr($self->buffer, 0, 1) eq q[']) { } 3 0 3
699 1 $string .= $self->read_backslash_escape();
700 } elsif ($self->buffer =~ /^[^'\\]+/o) {
701 2 $string .= $self->read_length($+[0]);
702 } elsif (substr($self->buffer, 0, 1) eq "'") {
703 3 last;
704 } else {
705 0 my $c = $self->peek_char();
706 0 $self->_throw_error("Got '$c' while expecting string character");
707 }
708 }
709 3 $self->get_char_safe(q[']);
710 3 return $self->new_token(STRING1S, $self->start_line, $self->start_column, $string);
711 }
712 }
713  
714 6 ▶ sub read_backslash_escape {
Subroutine read_backslash_escape: called CC=2 SCAR=6.9
Pod undocumented
715 6 my $self = shift;
716 6 ▶ if ($self->sparql12) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->sparql12) { } 2 4 6
717 # In SPARQL 1.2 all escape logic happens here, including multi-character
718 # escape sequences such as \uXXXX and \UXXXXXXXX.
719 2 return $self->_get_escaped_char(1);
720 } else {
721 # In SPARQL 1.1, multi-character codepoint escape sequences \uXXXX and \UXXXXXXXX
722 # are handled before parsing begins. What is left should only be single-character
723 # escapes such as \t and \n.
724 4 return $self->_get_escaped_char(0);
725 }
726 }
727  
728 6 ▶ sub _get_escaped_char {
Subroutine _get_escaped_char: called CC=17 SCAR=38.7
729 6 my $self = shift;
730 6 my $allow_mb = shift; # allow multi-byte escape sequences such as \uXXXX
731 6 my $c = $self->peek_char;
732 6 $self->get_char_safe('\\');
733 6 my $esc = $self->get_char;
734 0 ▶ if ($esc eq '\\') { return "\\" }
Branch: 8 branches
BranchTrueFalseTotal
if ($esc eq '\\') { } 0 6 6
elsif ($esc =~ /^['">]$/u) { } 3 3 6
elsif ($esc eq 'r') { } 0 3 3
elsif ($esc eq 't') { } 1 2 3
elsif ($esc eq 'n') { } 0 2 2
elsif ($esc eq 'b') { } 0 2 2
elsif ($esc eq 'f') { } 0 2 2
elsif ($allow_mb) { } 2 0 2
735 3 elsif ($esc =~ /^['">]$/) { return $esc }
736 0 elsif ($esc eq 'r') { return "\r" }
737 1 elsif ($esc eq 't') { return "\t" }
738 0 elsif ($esc eq 'n') { return "\n" }
739 0 elsif ($esc eq 'b') { return "\b" }
740 0 elsif ($esc eq 'f') { return "\f" }
741 elsif ($allow_mb) {
742 2 ▶ if ($esc eq 'U') {
Branch: 2 branches
BranchTrueFalseTotal
if ($esc eq 'U') { } 0 2 2
elsif ($esc eq 'u') { } 2 0 2
743 0 my $h = $self->read_length(8);
744 0 my $codepoint = hex($h);
745 0 ▶ $self->_throw_error("Bad unicode escape codepoint '$codepoint'") unless ($h =~ /^[0-9A-Fa-f]+$/o);
Branch: 1 branch
BranchTrueFalseTotal
unless $h =~ /^[0-9A-Fa-f]+$/ou 0 0 0
746 0 ▶ if ($codepoint >= 0xD800 and $codepoint <= 0xDFFF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($codepoint >= 55296 and $codepoint <= 57343) 0 0 0
Condition0%0/3
$codepoint >= 55296 and $codepoint <= 57343
!ll&&!rl&&r
000
MC/DC0%0/2
$codepoint >= 55296 and $codepoint <= 57343
$codepoint >= 55296 $codepoint <= 57343
Truth table0%0/3
A and B
A= $codepoint >= 55296B= $codepoint <= 57343
ABresult
0X0
100
111
747 0 die "Surrogate U+$h is illegal as a codepoint escape value";
748 }
749 0 return chr($codepoint);
750 } elsif ($esc eq 'u'){
751 2 my $h = $self->read_length(4);
752 2 my $codepoint = hex($h);
753 2 ▶ $self->_throw_error("Bad unicode escape codepoint '$codepoint'") unless ($h =~ /^[0-9A-Fa-f]+$/o);
Branch: 1 branch
BranchTrueFalseTotal
unless $h =~ /^[0-9A-Fa-f]+$/ou 0 2 2
754 2 ▶ if ($codepoint >= 0xD800 and $codepoint <= 0xDFFF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($codepoint >= 55296 and $codepoint <= 57343) 1 1 2
Condition66%2/3
$codepoint >= 55296 and $codepoint <= 57343
!ll&&!rl&&r
101
MC/DC50%1/2
$codepoint >= 55296 and $codepoint <= 57343
$codepoint >= 55296 $codepoint <= 57343
Truth table66%2/3
A and B
A= $codepoint >= 55296B= $codepoint <= 57343
ABresult
0X0
100
111
755 1 die "Surrogate U+$h is illegal as a codepoint escape value";
756 }
757 1 return chr($codepoint);
758 }
759 }
760 0 $self->_throw_error("Unrecognized string escape '$esc'");
761 }
762
763 0 ▶ sub current_location {
Subroutine current_location: not called CC=1 SCAR=6.9
Pod undocumented
764 0 my $self = shift;
765 0 return ($self->line, $self->column, $self->buffer);
766 }
767
768 0 ▶ sub throw_near_error {
Subroutine throw_near_error: not called CC=4 SCAR=30.0
Pod undocumented
769 0 my $self = shift;
770 0 my $message = shift;
771 0 ▶ my $line = shift // $self->line;
Condition0%0/3
shift() // $self->line
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // $self->line
shift() $self->line
Truth table0%0/3
A // B
A= shift()B= $self->line
ABresult
1X1
011
000
772 0 ▶ my $col = shift // $self->column;
Condition0%0/3
shift() // $self->column
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // $self->column
shift() $self->column
Truth table0%0/3
A // B
A= shift()B= $self->column
ABresult
1X1
011
000
773 0 ▶ my $buffer = shift // $self->buffer;
Condition0%0/3
shift() // $self->buffer
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() // $self->buffer
shift() $self->buffer
Truth table0%0/3
A // B
A= shift()B= $self->buffer
ABresult
1X1
011
000
774 0 die "$message near $line:$col: " . $buffer;
775 }
776
777 2 ▶ sub _throw_error {
Subroutine _throw_error: called CC=1 SCAR=0.0
778 2 my $self = shift;
779 2 my $error = shift;
780 2 my $line = $self->line;
781 2 my $col = $self->column;
782 14 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
783 2 Carp::confess "$error at $line:$col with buffer: " . Dumper($self->buffer);
784 }
785 }
786  
787 14 1;
788  
789 __END__
« AtteanX/Parser/Turtle/Lexer.pm ↑ Summary AtteanX/Serializer/TurtleTokens.pm »