| 1 | # RDF::Trine::Parser::Turtle::Lexer | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | RDF::Trine::Parser::Turtle::Lexer - Tokenizer for parsing Turtle, TriG, and N-Triples | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | This document describes RDF::Trine::Parser::Turtle::Lexer version 1.019 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | use RDF::Trine::Parser::Lexer; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | my $l = RDF::Trine::Parser::Lexer->new( file => $fh ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | while (my $t = $l->get_token) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | package RDF::Trine::Parser::Turtle::Lexer; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 68 | ▶ | use RDF::Trine::Parser::Turtle::Constants; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 68 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 68 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 68 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 68 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 68 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 68 | ▶ | use RDF::Trine::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 68 | our $VERSION; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 68 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 68 | $VERSION = '1.019'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 68 | my $r_nameChar_extra = qr'[-0-9\x{B7}\x{0300}-\x{036F}\x{203F}-\x{2040}]'o; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 68 | my $r_nameStartChar_minus_underscore = qr'[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{00010000}-\x{000EFFFF}]'o; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 68 | my $r_nameStartChar = qr/[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}]/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 68 | my $r_nameChar = qr/${r_nameStartChar}|[-0-9\x{b7}\x{0300}-\x{036f}\x{203F}-\x{2040}]/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 68 | my $r_prefixName = qr/(?:(?!_)${r_nameStartChar})(?:$r_nameChar)*/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 68 | my $r_nameChar_test = qr"(?:$r_nameStartChar|$r_nameChar_extra)"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 68 | my $r_double = qr'[+-]?([0-9]+\.[0-9]*[eE][+-]?[0-9]+|\.[0-9]+[eE][+-]?[0-9]+|[0-9]+[eE][+-]?[0-9]+)'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 68 | my $r_decimal = qr'[+-]?(([0-9]+\.[0-9]+)|\.([0-9])+)'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 68 | my $r_integer = qr'[+-]?[0-9]+'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 68 | my $r_PN_CHARS_U = qr/[_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}]/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 68 | my $r_PN_CHARS = qr"${r_PN_CHARS_U}|[-0-9\x{00B7}\x{0300}-\x{036F}\x{203F}-\x{2040}]"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 68 | my $r_bnode_id = qr"(?:${r_PN_CHARS_U}|[0-9])((${r_PN_CHARS}|[.])*${r_PN_CHARS})?"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 68 | 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}])/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # my $r_PN_CHARS_U = qr/([_]|${r_PN_CHARS_BASE})/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # my $r_PN_CHARS = qr/${r_PN_CHARS_U}|-|[0-9]|\x{00B7}|[\x{0300}-\x{036F}]|[\x{203F}-\x{2040}]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 68 | my $r_PN_PREFIX = qr/(${r_PN_CHARS_BASE}((${r_PN_CHARS}|[.])*${r_PN_CHARS})?)/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 68 | my $r_PN_LOCAL_ESCAPED = qr{(\\([-~.!&'()*+,;=/?#@%_\$]))|%[0-9A-Fa-f]{2}}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 68 | 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}))?)/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 68 | my $r_PN_LOCAL_BNODE = qr/((${r_PN_CHARS_U}|[0-9])((${r_PN_CHARS}|[.])*${r_PN_CHARS})?)/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 68 | my $r_PNAME_NS = qr/((${r_PN_PREFIX})?:)/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 68 | my $r_PNAME_LN = qr/(${r_PNAME_NS}${r_PN_LOCAL})/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 68 | has file => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | isa => 'FileHandle', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 68 | has linebuffer => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | default => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 68 | has line => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 68 | has column => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | default => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 68 | has buffer => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | isa => 'Str', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | default => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 68 | has start_column => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | default => -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 68 | has start_line => ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | isa => 'Int', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | default => -1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 412 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 412 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 412 | ▶ | if (scalar(@_) == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 412 | return { file => shift }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | return $class->SUPER::BUILDARGS(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | =item C<< new_token ( $type, @values ) >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | Returns a new token with the given type and optional values, capturing the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | current line and column of the input data. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 9482 | ▶ | sub new_token { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_token: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 9482 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 9482 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 9482 | my $start_line = $self->start_line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 9482 | my $start_col = $self->start_column; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 9482 | my $line = $self->line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 9482 | my $col = $self->column; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 9482 | return RDF::Trine::Parser::Turtle::Token->fast_constructor( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | $type, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | $start_line, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | $start_col, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | $line, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | $col, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 68 | my %CHAR_TOKEN = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | '.' => DOT, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | ';' => SEMICOLON, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | '[' => LBRACKET, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ']' => RBRACKET, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | '(' => LPAREN, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | ')' => RPAREN, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | '{' => LBRACE, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | '}' => RBRACE, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | ',' => COMMA, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | '=' => EQUALS, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | my %METHOD_TOKEN = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | # q[#] => '_get_comment', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | q[@] => '_get_keyword', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | q[<] => '_get_iriref', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | q[_] => '_get_bnode', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | q['] => '_get_single_literal', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | q["] => '_get_double_literal', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | q[:] => '_get_pname', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 68 | (map {$_ => '_get_number'} (0 .. 9, '-', '+')) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | =item C<< get_token >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | Returns the next token present in the input. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 9620 | ▶ | sub get_token { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_token: called CC=19 SCAR=29.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 9620 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 9620 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 18827 | ▶ | unless (length($self->{buffer})) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 516 | $self->fill_buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # warn "getting token with buffer: " . Dumper($self->{buffer}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 18827 | my $c = $self->_peek_char(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 18827 | ▶ | return unless (defined($c) and length($c)); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $c and length $c
MC/DC50%1/2
defined $c and length $c
defined $c
length $c
Truth table66%2/3
A and B
A= defined $cB= length $c
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 18526 | $self->start_column( $self->column ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 18526 | $self->start_line( $self->line ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 18526 | ▶ | if ($c eq '.' and $self->{buffer} =~ $r_decimal) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$c eq "." and $self->{"buffer"} =~ /$r_decimal/
MC/DC100%2/2
$c eq "." and $self->{"buffer"} =~ /$r_decimal/
$c eq "."
$self->{"buffer"} =~ /$r_decimal/
Truth table100%3/3
A and B
A= $c eq "."B= $self->{"buffer"} =~ /$r_decimal/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | return $self->_get_number(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 18525 | ▶ | if (defined(my $name = $CHAR_TOKEN{$c})) { $self->_get_char; return $self->new_token($name); } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 3672 | elsif (defined(my $method = $METHOD_TOKEN{$c})) { return $self->$method() } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | elsif ($c eq '#') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # we're ignoring comment tokens, but we could return them here instead of falling through to the 'next': | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 196 | $self->_get_comment(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 196 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | elsif ($c =~ /[ \r\n\t]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 9011 | ▶ | while (defined($c) and length($c) and $c =~ /[\t\r\n ]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
defined $c and length $c and $c =~ /[\t\r\n ]/
defined $c and length $c
MC/DC66%2/3
defined $c and length $c and $c =~ /[\t\r\n ]/
defined $c
length $c
$c =~ /[\t\r\n ]/
Truth table75%3/4
A and B and C
A= defined $cB= length $cC= $c =~ /[\t\r\n ]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 18407 | $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 18407 | $c = $self->_peek_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # we're ignoring whitespace tokens, but we could return them here instead of falling through to the 'next': | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | # return $self->new_token(WS); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 9011 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 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}]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 2649 | ▶ | if ($self->{buffer} =~ /^a(?!:)\s/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 60 | $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 60 | return $self->new_token(A); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } elsif ($self->{buffer} =~ /^(?:true|false)(?!:)\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 10 | my $bool = $self->_read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 10 | return $self->new_token(BOOLEAN, $bool); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } elsif ($self->{buffer} =~ /^BASE(?!:)\b/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 4 | $self->_read_length(4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 4 | return $self->new_token(SPARQLBASE); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } elsif ($self->{buffer} =~ /^PREFIX(?!:)\b/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 3 | $self->_read_length(6); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 3 | return $self->new_token(SPARQLPREFIX); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 2572 | return $self->_get_pname; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 38 | elsif ($c eq '^') { $self->_read_word('^^'); return $self->new_token(HATHAT); } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | # Carp::cluck sprintf("Unexpected byte '$c' (0x%02x)", ord($c)); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 6 | return $self->_throw_error(sprintf("Unexpected byte '%s' (0x%02x)", $c, ord($c))); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | warn 'byte: ' . Dumper($c); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | =begin private | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | =item C<< fill_buffer >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | Fills the internal parse buffer with a new line from the input source. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 4590 | ▶ | sub fill_buffer { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fill_buffer: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 4590 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 4590 | ▶ | unless (length($self->buffer)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 4590 | my $line = $self->file->getline; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 4590 | ▶ | if (defined($line)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 3698 | $self->{buffer} .= $line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | =item C<< check_for_bom >> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | Checks the input buffer for a Unicode BOM, and consumes it if it is present. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 387 | ▶ | sub check_for_bom { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
check_for_bom: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 387 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 387 | my $c = $self->_peek_char(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 387 | ▶ | if (defined($c) and $c eq "\x{FEFF}") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $c and $c eq "\x{feff}"
MC/DC100%2/2
defined $c and $c eq "\x{feff}"
defined $c
$c eq "\x{feff}"
Truth table100%3/3
A and B
A= defined $cB= $c eq "\x{feff}"
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1 | $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 5888 | ▶ | sub _get_char_safe { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_char_safe: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 5888 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 5888 | my $char = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 5888 | my $c = $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 5888 | ▶ | if ($c ne $char) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $self->_throw_error("Expected '$char' but got '$c'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 5888 | return $c; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 26 | ▶ | sub _get_char_fill_buffer { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_char_fill_buffer: called CC=4 SCAR=18.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 26 | ▶ | if (length($self->{buffer}) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $self->fill_buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | if (length($self->{buffer}) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 26 | my $c = substr($self->{buffer}, 0, 1, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 26 | ▶ | if ($c eq "\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # $self->{linebuffer} = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $self->{line} = 1+$self->{line}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | $self->{column} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | # $self->{linebuffer} .= $c; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 26 | $self->{column} = 1+$self->{column}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 26 | return $c; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 33052 | ▶ | sub _get_char { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_char: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 33052 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 33052 | my $c = substr($self->{buffer}, 0, 1, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 33052 | ▶ | if ($c eq "\n") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # $self->{linebuffer} = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 3555 | $self->{line} = 1+$self->{line}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 3555 | $self->{column} = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # $self->{linebuffer} .= $c; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 29497 | $self->{column} = 1+$self->{column}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 33052 | return $c; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 47760 | ▶ | sub _peek_char { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_peek_char: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 47760 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 47760 | ▶ | if (length($self->{buffer}) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 4047 | $self->fill_buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 4047 | ▶ | if (length($self->{buffer}) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 587 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 47173 | my $c = substr($self->{buffer}, 0, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 47173 | return $c; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 507 | ▶ | sub _read_word { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_word: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 507 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 507 | my $word = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 507 | ▶ | while (length($self->{buffer}) < length($word)) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $self->fill_buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 507 | ▶ | if (substr($self->{buffer}, 0, length($word)) ne $word) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 1 | $self->_throw_error("Expected '$word'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 506 | my $lines = ($word =~ tr/\n//); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 506 | my $lastnl = rindex($word, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 506 | my $cols = length($word) - $lastnl - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 506 | $self->{lines} += $lines; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 506 | ▶ | if ($lines) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $self->{column} = $cols; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 506 | $self->{column} += $cols; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 506 | substr($self->{buffer}, 0, length($word), ''); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 6029 | ▶ | sub _read_length { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_length: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 6029 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 6029 | my $len = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 6029 | ▶ | while (length($self->{buffer}) < $len) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $self->fill_buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 6029 | my $word = substr($self->{buffer}, 0, $len, ''); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 6029 | my $lines = ($word =~ tr/\n//); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 6029 | my $lastnl = rindex($word, "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 6029 | my $cols = length($word) - $lastnl - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 6029 | $self->{lines} += $lines; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 6029 | ▶ | if ($lines) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 31 | $self->{column} = $cols; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 5998 | $self->{column} += $cols; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 6029 | return $word; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 3119 | ▶ | sub _get_pname { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_pname: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 3119 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 3119 | my $prefix = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 3119 | ▶ | if ($self->{buffer} =~ /^$r_PNAME_LN/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 2839 | my $ln = $self->_read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 2839 | my ($ns,$local) = ($ln =~ /^([^:]*:)(.*)$/); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 68 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 2839 | $local =~ s{\\([-~.!&'()*+,;=:/?#@%_\$])}{$1}g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 2839 | return $self->new_token(PREFIXNAME, $ns, $local); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 280 | $self->{buffer} =~ $r_PNAME_NS; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 280 | my $ns = $self->_read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 280 | return $self->new_token(PREFIXNAME, $ns); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1876 | ▶ | sub _get_iriref { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_iriref: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 1876 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1876 | $self->_get_char_safe(q[<]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 1876 | my $iri = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 1876 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 3755 | my $c = $self->_peek_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 3755 | ▶ | last unless defined($c); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 3755 | ▶ | if (substr($self->{buffer}, 0, 1) eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 11 | $self->_get_char_safe('\\'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 11 | my $esc = $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 11 | ▶ | if ($esc eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | $iri .= "\\"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } elsif ($esc eq 'U') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 3 | my $codepoint = $self->_read_length(8); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 3 | ▶ | unless ($codepoint =~ /^[0-9A-Fa-f]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 1 | $self->_throw_error("Bad unicode escape codepoint '$codepoint'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 2 | $iri .= chr(hex($codepoint)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | } elsif ($esc eq 'u') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 6 | my $codepoint = $self->_read_length(4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 6 | ▶ | unless ($codepoint =~ /^[0-9A-Fa-f]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | $self->_throw_error("Bad unicode escape codepoint '$codepoint'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 5 | my $char = chr(hex($codepoint)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 5 | ▶ | if ($char =~ /[<>" {}|\\^`]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 3 | $self->_throw_error(sprintf("Bad IRI character: '%s' (0x%x)", $char, ord($char))); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 2 | $iri .= $char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 2 | $self->_throw_error("Unrecognized iri escape '$esc'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } elsif ($self->{buffer} =~ /^[^<>\x00-\x20\\"{}|^`]+/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 1875 | $iri .= $self->_read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } elsif (substr($self->{buffer}, 0, 1) eq '>') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 1865 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 4 | $self->_throw_error("Got '$c' while expecting IRI character"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1865 | $self->_get_char_safe(q[>]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1865 | return $self->new_token(IRI, $iri); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 83 | ▶ | sub _get_bnode { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_bnode: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 83 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 83 | $self->_read_word('_:'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 83 | ▶ | unless ($self->{buffer} =~ /^${r_bnode_id}/o) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $self->_throw_error("Expected: name"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 83 | my $name = substr($self->{buffer}, 0, $+[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 83 | $self->_read_word($name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 83 | return $self->new_token(BNODE, $name); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 81 | ▶ | sub _get_number { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_number: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 81 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 81 | ▶ | if ($self->{buffer} =~ /^${r_double}/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 9 | return $self->new_token(DOUBLE, $self->_read_length($+[0])); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | } elsif ($self->{buffer} =~ /^${r_decimal}/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 11 | return $self->new_token(DECIMAL, $self->_read_length($+[0])); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | } elsif ($self->{buffer} =~ /^${r_integer}/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 59 | return $self->new_token(INTEGER, $self->_read_length($+[0])); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 2 | $self->_throw_error("Expected number"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 196 | ▶ | sub _get_comment { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_comment: called CC=5 SCAR=16.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 196 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 196 | $self->_get_char_safe('#'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 196 | my $comment = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 196 | my $c = $self->_peek_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 196 | ▶ | while (length($c) and $c !~ /[\r\n]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $c and not $c =~ /[\r\n]/
MC/DC50%1/2
length $c and not $c =~ /[\r\n]/
length $c
not $c =~ /[\r\n]/
Truth table66%2/3
A and not(B)
A= length $cB= not $c =~ /[\r\n]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 5287 | $comment .= $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 5287 | $c = $self->_peek_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 196 | ▶ | if (length($c) and $c =~ /[\r\n]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
length $c and $c =~ /[\r\n]/
MC/DC0%0/2
length $c and $c =~ /[\r\n]/
length $c
$c =~ /[\r\n]/
Truth table33%1/3
A and B
A= length $cB= $c =~ /[\r\n]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 196 | $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 196 | return $self->new_token(COMMENT, $comment); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 765 | ▶ | sub _get_double_literal { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_double_literal: called CC=38 SCAR=38.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 765 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 765 | my $c = $self->_peek_char(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 765 | $self->_get_char_safe(q["]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 765 | ▶ | if (substr($self->{buffer}, 0, 2) eq q[""]) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # #x22 #x22 #x22 lcharacter* #x22 #x22 #x22 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 29 | $self->_read_word(q[""]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 29 | my $quote_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 29 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 29 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 184 | ▶ | if (length($self->{buffer}) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 23 | $self->fill_buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 23 | ▶ | if (length($self->{buffer}) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 3 | $self->_throw_error("Found EOF in string literal"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 181 | ▶ | if (substr($self->{buffer}, 0, 1) eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 88 | my $c = $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 88 | $quote_count++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 88 | ▶ | if ($quote_count == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 26 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 93 | ▶ | if ($quote_count) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 8 | $string .= '"' foreach (1..$quote_count); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 8 | $quote_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | 93 | ▶ | if (substr($self->{buffer}, 0, 1) eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 26 | my $c = $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | # $self->_get_char_safe('\\'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 26 | my $esc = $self->_get_char_fill_buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 26 | ▶ | if ($esc eq '\\'){ $string .= "\\" } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 11 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 5 | elsif ($esc eq '"'){ $string .= '"' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | elsif ($esc eq "'"){ $string .= "'" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 4 | elsif ($esc eq 'r'){ $string .= "\r" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 4 | elsif ($esc eq 't'){ $string .= "\t" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 4 | elsif ($esc eq 'n'){ $string .= "\n" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | elsif ($esc eq 'b'){ $string .= "\b" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | elsif ($esc eq 'f'){ $string .= "\f" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | elsif ($esc eq '>'){ $string .= ">" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | elsif ($esc eq 'U'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 4 | my $codepoint = $self->_read_length(8); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 4 | ▶ | unless ($codepoint =~ /^[0-9A-Fa-f]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | $self->_throw_error("Bad unicode escape codepoint '$codepoint'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 4 | $string .= chr(hex($codepoint)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | elsif ($esc eq 'u'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 4 | my $codepoint = $self->_read_length(4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 4 | ▶ | unless ($codepoint =~ /^[0-9A-Fa-f]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | $self->_throw_error("Bad unicode escape codepoint '$codepoint'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 4 | $string .= chr(hex($codepoint)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | $self->_throw_error("Unrecognized string escape '$esc'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 67 | $self->{buffer} =~ /^[^"\\]+/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 67 | $string .= $self->_read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 26 | return $self->new_token(STRING3D, $string); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | ### #x22 scharacter* #x22 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 736 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 736 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 1623 | ▶ | if (substr($self->{buffer}, 0, 1) eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 96 | my $c = $self->_peek_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 96 | $self->_get_char_safe('\\'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 96 | my $esc = $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 96 | ▶ | if ($esc eq '\\'){ $string .= "\\" } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 11 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 44 | elsif ($esc eq '"'){ $string .= '"' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | elsif ($esc eq "'"){ $string .= "'" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | elsif ($esc eq 'r'){ $string .= "\r" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | elsif ($esc eq 't'){ $string .= "\t" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 1 | elsif ($esc eq 'n'){ $string .= "\n" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | elsif ($esc eq 'b'){ $string .= "\b" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | elsif ($esc eq 'f'){ $string .= "\f" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | elsif ($esc eq '>'){ $string .= ">" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | elsif ($esc eq 'U'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 3 | my $codepoint = $self->_read_length(8); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 3 | ▶ | unless ($codepoint =~ /^[0-9A-Fa-f]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 2 | $self->_throw_error("Bad unicode escape codepoint '$codepoint'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 1 | $string .= chr(hex($codepoint)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | elsif ($esc eq 'u'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 2 | my $codepoint = $self->_read_length(4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 2 | ▶ | unless ($codepoint =~ /^[0-9A-Fa-f]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 1 | $self->_throw_error("Bad unicode escape codepoint '$codepoint'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 1 | $string .= chr(hex($codepoint)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 1 | $self->_throw_error("Unrecognized string escape '$esc'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | } elsif ($self->{buffer} =~ /^[^"\\]+/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 795 | $string .= $self->_read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | } elsif (substr($self->{buffer}, 0, 1) eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 730 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 2 | $self->_throw_error("Got '$c' while expecting string character"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 730 | $self->_get_char_safe(q["]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 730 | return $self->new_token(STRING1D, $string); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 32 | ▶ | sub _get_single_literal { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_single_literal: called CC=38 SCAR=49.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 32 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 32 | my $c = $self->_peek_char(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 32 | $self->_get_char_safe("'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 32 | ▶ | if (substr($self->{buffer}, 0, 2) eq q['']) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | # #x22 #x22 #x22 lcharacter* #x22 #x22 #x22 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 10 | $self->_read_word(q['']); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 10 | my $quote_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 10 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 10 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 47 | ▶ | if (length($self->{buffer}) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 4 | $self->fill_buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 4 | ▶ | if (length($self->{buffer}) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1 | $self->_throw_error("Found EOF in string literal"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 46 | ▶ | if (substr($self->{buffer}, 0, 1) eq "'") { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 31 | my $c = $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 31 | $quote_count++; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | 31 | ▶ | if ($quote_count == 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 9 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 15 | ▶ | if ($quote_count) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 3 | $string .= "'" foreach (1..$quote_count); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 3 | $quote_count = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 15 | ▶ | if (substr($self->{buffer}, 0, 1) eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | my $c = $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | # $self->_get_char_safe('\\'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | my $esc = $self->_get_char_fill_buffer; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | if ($esc eq '\\'){ $string .= "\\" } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 11 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | elsif ($esc eq '"'){ $string .= '"' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | elsif ($esc eq "'"){ $string .= "'" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | elsif ($esc eq 'r'){ $string .= "\r" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | elsif ($esc eq 't'){ $string .= "\t" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | elsif ($esc eq 'n'){ $string .= "\n" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | elsif ($esc eq 'b'){ $string .= "\b" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | elsif ($esc eq 'f'){ $string .= "\f" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | elsif ($esc eq '>'){ $string .= ">" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | elsif ($esc eq 'U'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | my $codepoint = $self->_read_length(8); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 0 | ▶ | unless ($codepoint =~ /^[0-9A-Fa-f]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | $self->_throw_error("Bad unicode escape codepoint '$codepoint'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | $string .= chr(hex($codepoint)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | elsif ($esc eq 'u'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | my $codepoint = $self->_read_length(4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | ▶ | unless ($codepoint =~ /^[0-9A-Fa-f]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | $self->_throw_error("Bad unicode escape codepoint '$codepoint'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | $string .= chr(hex($codepoint)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | $self->_throw_error("Unrecognized string escape '$esc'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 15 | $self->{buffer} =~ /^[^'\\]+/; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 15 | $string .= $self->_read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 9 | return $self->new_token(STRING3S, $string); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | ### #x22 scharacter* #x22 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 22 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 22 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 44 | ▶ | if (substr($self->{buffer}, 0, 1) eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 8 | my $c = $self->_peek_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 8 | $self->_get_char_safe('\\'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 8 | my $esc = $self->_get_char; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 8 | ▶ | if ($esc eq '\\'){ $string .= "\\" } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 11 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 0 | elsif ($esc eq '"'){ $string .= '"' } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | elsif ($esc eq "'"){ $string .= "'" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 1 | elsif ($esc eq 'r'){ $string .= "\r" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 1 | elsif ($esc eq 't'){ $string .= "\t" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 1 | elsif ($esc eq 'n'){ $string .= "\n" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 1 | elsif ($esc eq 'b'){ $string .= "\b" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 1 | elsif ($esc eq 'f'){ $string .= "\f" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | elsif ($esc eq '>'){ $string .= ">" } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | elsif ($esc eq 'U'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 1 | my $codepoint = $self->_read_length(8); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 1 | ▶ | unless ($codepoint =~ /^[0-9A-Fa-f]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 0 | $self->_throw_error("Bad unicode escape codepoint '$codepoint'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 1 | $string .= chr(hex($codepoint)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | elsif ($esc eq 'u'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | 1 | my $codepoint = $self->_read_length(4); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 1 | ▶ | unless ($codepoint =~ /^[0-9A-Fa-f]+$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | $self->_throw_error("Bad unicode escape codepoint '$codepoint'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 1 | $string .= chr(hex($codepoint)); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | $self->_throw_error("Unrecognized string escape '$esc'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | } elsif ($self->{buffer} =~ /^[^'\\]+/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 14 | $string .= $self->_read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | } elsif (substr($self->{buffer}, 0, 1) eq "'") { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 20 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 2 | $self->_throw_error("Got '$c' while expecting string character"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | 20 | $self->_get_char_safe(q[']); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 20 | return $self->new_token(STRING1S, $string); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 289 | ▶ | sub _get_keyword { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_keyword: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | 289 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 289 | $self->_get_char_safe('@'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 289 | ▶ | if ($self->{buffer} =~ /^base/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | 7 | $self->_read_word('base'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | 7 | return $self->new_token(BASE); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | } elsif ($self->{buffer} =~ /^prefix/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 257 | $self->_read_word('prefix'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 257 | return $self->new_token(PREFIX); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 25 | ▶ | if ($self->{buffer} =~ /^[a-zA-Z]+(-[a-zA-Z0-9]+)*\b/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 24 | my $lang = $self->_read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 24 | return $self->new_token(LANG, $lang); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 1 | $self->_throw_error("Expected keyword or language tag"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 37 | ▶ | sub _throw_error { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_throw_error: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 37 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | 37 | my $error = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 37 | my $line = $self->line; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 37 | my $col = $self->column; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | # Carp::cluck "$line:$col: $error: " . Dumper($self->{buffer}); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 37 | RDF::Trine::Error::ParserError::Positioned->throw( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | -text => "$error at $line:$col", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | -value => [$line, $col], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 68 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 68 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||