| 1 | # AtteanX::Parser::Turtle::Lexer | ||||||||||||||||||||||||||||||||||||||||||||
| 2 | # ----------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||
| 4 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||
| 6 | AtteanX::Parser::Turtle::Lexer - Tokenizer for parsing Turtle, TriG, and N-Triples | ||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||
| 8 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | This document describes AtteanX::Parser::Turtle::Lexer version 0.040 | ||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | use AtteanX::Parser::Turtle::Lexer; | ||||||||||||||||||||||||||||||||||||||||||||
| 15 | my $l = AtteanX::Parser::Turtle::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 | 50 | package AtteanX::Parser::Turtle::Lexer 0.040 { | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 50 | ▶ | use AtteanX::Parser::Turtle::Constants; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 50 | ▶ | use v5.14; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 50 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 30 | 50 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 31 | 50 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 50 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 33 | 50 | ▶ | use Types::Standard qw(FileHandle Ref Str Int Bool ArrayRef HashRef ConsumerOf InstanceOf); | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 50 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||
| 36 | 50 | my $r_nameChar_extra = qr'[-0-9\x{B7}\x{0300}-\x{036F}\x{203F}-\x{2040}]'o; | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 50 | 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; | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 50 | 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}]/o; | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 50 | my $r_nameChar = qr/${r_nameStartChar}|[-0-9\x{b7}\x{0300}-\x{036f}\x{203F}-\x{2040}]/o; | |||||||||||||||||||||||||||||||||||||||||||
| 40 | 50 | my $r_prefixName = qr/(?:(?!_)${r_nameStartChar})(?:$r_nameChar)*/o; | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 50 | my $r_nameChar_test = qr"(?:$r_nameStartChar|$r_nameChar_extra)"o; | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 50 | my $r_double = qr'[+-]?([0-9]+\.[0-9]*[eE][+-]?[0-9]+|\.[0-9]+[eE][+-]?[0-9]+|[0-9]+[eE][+-]?[0-9]+)'o; | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 50 | my $r_decimal = qr'[+-]?(([0-9]+\.[0-9]+)|\.([0-9])+)'o; | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 50 | my $r_integer = qr'[+-]?[0-9]+'o; | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 50 | 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}]/o; | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 50 | my $r_PN_CHARS = qr"${r_PN_CHARS_U}|[-0-9\x{00B7}\x{0300}-\x{036F}\x{203F}-\x{2040}]"o; | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 50 | my $r_bnode_id = qr"(?:${r_PN_CHARS_U}|[0-9])((${r_PN_CHARS}|[.])*${r_PN_CHARS})?"o; | |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 50 | 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; | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 50 | my $r_PN_PREFIX = qr/(?:${r_PN_CHARS_BASE}(?:(?:${r_PN_CHARS}|[.])*${r_PN_CHARS})?)/o; | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 50 | my $r_PN_LOCAL_ESCAPED = qr{(?:\\(?:[-~.!&'()*+,;=/?#@%_\$]))|%[0-9A-Fa-f]{2}}o; | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 50 | our $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; | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 50 | my $r_PN_LOCAL_BNODE = qr/(?:(?:${r_PN_CHARS_U}|[0-9])(?:(?:${r_PN_CHARS}|[.])*${r_PN_CHARS})?)/o; | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 50 | our $r_PNAME_NS = qr/(?:(?:${r_PN_PREFIX})?:)/o; | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 50 | our $r_PNAME_LN = qr/(?:${r_PNAME_NS}${r_PN_LOCAL})/o; | |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 50 | with 'AtteanX::API::Lexer'; | |||||||||||||||||||||||||||||||||||||||||||
| 58 | 50 | has 'ignore_whitespace' => (is => 'rw', isa => Bool, default => 1); | |||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | =item C<< new_token ( $type, $start_line, $start_column, @values ) >> | ||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | Returns a new token with the given type and optional values, capturing the | ||||||||||||||||||||||||||||||||||||||||||||
| 63 | current line and column of the input data. | ||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||
| 67 | 470 | ▶ | sub new_token { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_token: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 470 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 470 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 470 | my $start_line = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 470 | my $start_col = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 470 | my $line = $self->line; | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 470 | my $col = $self->column; | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 470 | return AtteanX::Parser::Turtle::Token->fast_constructor( $type, $start_line, $start_col, $line, $col, \@_ ); | |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 50 | my %CHAR_TOKEN = ( | |||||||||||||||||||||||||||||||||||||||||||
| 78 | '.' => DOT, | ||||||||||||||||||||||||||||||||||||||||||||
| 79 | ';' => SEMICOLON, | ||||||||||||||||||||||||||||||||||||||||||||
| 80 | '[' => LBRACKET, | ||||||||||||||||||||||||||||||||||||||||||||
| 81 | ']' => RBRACKET, | ||||||||||||||||||||||||||||||||||||||||||||
| 82 | '(' => LPAREN, | ||||||||||||||||||||||||||||||||||||||||||||
| 83 | '}' => RBRACE, | ||||||||||||||||||||||||||||||||||||||||||||
| 84 | ',' => COMMA, | ||||||||||||||||||||||||||||||||||||||||||||
| 85 | '=' => EQUALS, | ||||||||||||||||||||||||||||||||||||||||||||
| 86 | '~' => TILDE, | ||||||||||||||||||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | my %METHOD_TOKEN = ( | ||||||||||||||||||||||||||||||||||||||||||||
| 90 | # q[#] => '_get_comment', | ||||||||||||||||||||||||||||||||||||||||||||
| 91 | q[@] => '_get_keyword', | ||||||||||||||||||||||||||||||||||||||||||||
| 92 | q[<] => '_get_iriref_or_ltlt', | ||||||||||||||||||||||||||||||||||||||||||||
| 93 | q[>] => '_get_gtgt', | ||||||||||||||||||||||||||||||||||||||||||||
| 94 | q[)] => '_get_rparen_or_pgtgt', | ||||||||||||||||||||||||||||||||||||||||||||
| 95 | q[|] => '_get_rannot', | ||||||||||||||||||||||||||||||||||||||||||||
| 96 | q[{] => '_get_lbrace_or_lannot', | ||||||||||||||||||||||||||||||||||||||||||||
| 97 | q[_] => '_get_bnode', | ||||||||||||||||||||||||||||||||||||||||||||
| 98 | q['] => '_get_single_literal', | ||||||||||||||||||||||||||||||||||||||||||||
| 99 | q["] => '_get_double_literal', | ||||||||||||||||||||||||||||||||||||||||||||
| 100 | q[:] => '_get_pname', | ||||||||||||||||||||||||||||||||||||||||||||
| 101 | 50 | (map {$_ => '_get_number'} (0 .. 9, '-', '+')) | |||||||||||||||||||||||||||||||||||||||||||
| 102 | ); | ||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | =item C<< get_token >> | ||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | Returns the next token present in the input. | ||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 503 | ▶ | sub get_token { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_token: called CC=20 SCAR=36.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 503 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 503 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||
| 113 | 978 | ▶ | $self->fill_buffer unless (length($self->buffer)); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 978 | my $start_column = $self->column; | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 978 | my $start_line = $self->line; | |||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 978 | ▶ | if ($self->buffer =~ /^[ \r\n\t]+/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 475 | my $ws = $self->read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 120 | # we're ignoring whitespace tokens, but we could return them here instead of falling through to the 'next': | ||||||||||||||||||||||||||||||||||||||||||||
| 121 | 475 | ▶ | unless ($self->ignore_whitespace) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | return $self->new_token(WS, $start_line, $start_column, $ws); | |||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 124 | 475 | next; | |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 503 | my $c = $self->peek_char(); | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 503 | ▶ | return unless (defined($c)); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | 471 | ▶ | if ($c eq '#') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 131 | # we're ignoring comment tokens, but we could return them here instead of falling through to the 'next': | ||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $self->_get_comment(); | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||
| 136 | 471 | $self->start_column( $start_column ); | |||||||||||||||||||||||||||||||||||||||||||
| 137 | 471 | $self->start_line( $start_line ); | |||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 471 | ▶ | if ($c eq '.' and $self->buffer =~ /^$r_decimal/) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$c eq "." and $self->buffer =~ /^$r_decimal/u
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
| |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | return $self->_get_number(); | |||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 471 | ▶ | if ($c eq '[' and $self->buffer =~ /^\[\s*\]/) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition100%3/3
$c eq "[" and $self->buffer =~ /^\[\s*\]/u
MC/DC100%2/2
$c eq "[" and $self->buffer =~ /^\[\s*\]/u
$c eq "["
$self->buffer =~ /^\[\s*\]/u
Truth table100%3/3
A and B
A= $c eq "["B= $self->buffer =~ /^\[\s*\]/u
| |||||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | $self->read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | return $self->new_token(ANON, $start_line, $start_column, '[]'); | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 129 | } elsif (defined(my $name = $CHAR_TOKEN{$c})) { $self->get_char; return $self->new_token($name, $start_line, $start_column, $c); } | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 220 | elsif (defined(my $method = $METHOD_TOKEN{$c})) { return $self->$method() } | |||||||||||||||||||||||||||||||||||||||||||
| 148 | 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) { | ||||||||||||||||||||||||||||||||||||||||||||
| 149 | 120 | ▶ | if ($self->buffer =~ /^a(?!:)\s/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 150 | 22 | $self->get_char; | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 22 | return $self->new_token(A, $start_line, $start_column, 'a'); | |||||||||||||||||||||||||||||||||||||||||||
| 152 | } elsif ($self->buffer =~ /^(?:true|false)(?!:)\b/o) { | ||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $bool = $self->read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | return $self->new_token(BOOLEAN, $start_line, $start_column, $bool); | |||||||||||||||||||||||||||||||||||||||||||
| 155 | } elsif ($self->buffer =~ /^BASE(?!:)\b/oi) { | ||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $self->read_length(4); | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | return $self->new_token(BASE, $start_line, $start_column); | |||||||||||||||||||||||||||||||||||||||||||
| 158 | } elsif ($self->buffer =~ /^PREFIX(?!:)\b/io) { | ||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $self->read_length(6); | |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | return $self->new_token(PREFIX, $start_line, $start_column); | |||||||||||||||||||||||||||||||||||||||||||
| 161 | } elsif ($self->buffer =~ /^VERSION(?!:)\b/io) { | ||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $self->read_length(7); | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | return $self->new_token(VERSION, $start_line, $start_column); | |||||||||||||||||||||||||||||||||||||||||||
| 164 | } elsif ($self->buffer =~ /^GRAPH(?!:)\b/io) { | ||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | $self->read_length(5); | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | return $self->new_token(GRAPH, $start_line, $start_column); | |||||||||||||||||||||||||||||||||||||||||||
| 167 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 168 | 98 | return $self->_get_pname; | |||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 171 | elsif ($c eq '^') { | ||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | $self->read_word('^^'); return $self->new_token(HATHAT, $start_line, $start_column); } | |||||||||||||||||||||||||||||||||||||||||||
| 173 | else { | ||||||||||||||||||||||||||||||||||||||||||||
| 174 | # Carp::cluck sprintf("Unexpected byte '$c' (0x%02x)", ord($c)); | ||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | return $self->_throw_error(sprintf("Unexpected byte '%s' (0x%02x)", $c, ord($c))); | |||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | warn sprintf('byte: 0x%x', ord($c)); | |||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||
| 181 | =begin private | ||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | =cut | ||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 126 | ▶ | sub _get_pname { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_pname: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 187 | 126 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 126 | my $prefix = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | 126 | ▶ | if ($self->buffer =~ /^$r_PNAME_LN/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 191 | 95 | my $ln = $self->read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 95 | my ($ns, $local) = ($ln =~ /^([^:]*:)(.*)$/); | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 50 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 194 | 95 | $local =~ s{\\([-~.!&'()*+,;=:/?#@%_\$])}{$1}g; | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 95 | return $self->new_token(PREFIXNAME, $self->start_line, $self->start_column, $ns, $local); | |||||||||||||||||||||||||||||||||||||||||||
| 196 | } elsif ($self->buffer =~ /^$r_PNAME_NS/) { | ||||||||||||||||||||||||||||||||||||||||||||
| 197 | 31 | my $ns = $self->read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 31 | return $self->new_token(PREFIXNAME, $self->start_line, $self->start_column, $ns); | |||||||||||||||||||||||||||||||||||||||||||
| 199 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $self->_throw_error("Invalid PrefixedName"); | |||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | sub _get_gtgt { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_gtgt: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $self->read_word('>>'); | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | return $self->new_token(GTGT, $self->start_line, $self->start_column, '>>'); | |||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | ▶ | sub _get_lbrace_or_lannot { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_lbrace_or_lannot: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $self->get_char_safe(q[{]); | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if ($self->buffer =~ /^\|/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | $self->get_char_safe(q[|]); | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | return $self->new_token(LANNOT, $self->start_line, $self->start_column, '{|'); | |||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | return $self->new_token(LBRACE, $self->start_line, $self->start_column, '{'); | |||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | sub _get_rannot { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_rannot: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | $self->read_word('|}'); | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | return $self->new_token(RANNOT, $self->start_line, $self->start_column, '|}'); | |||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | ▶ | sub _get_rparen_or_pgtgt { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_rparen_or_pgtgt: called CC=2 SCAR=8.5
| |||||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | $self->get_char_safe(q[)]); | |||||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | ▶ | if ($self->buffer =~ /^>>/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $self->get_char_safe(q[>]); | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $self->get_char_safe(q[>]); | |||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | return $self->new_token(PGTGT, $self->start_line, $self->start_column, 'PGTGT'); | |||||||||||||||||||||||||||||||||||||||||||
| 233 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 234 | 1 | return $self->new_token(RPAREN, $self->start_line, $self->start_column, ')'); | |||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | 89 | ▶ | sub _get_iriref_or_ltlt { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_iriref_or_ltlt: called CC=15 SCAR=50.3
| |||||||||||||||||||||||||||||||||||||||||||||
| 239 | 89 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 240 | 89 | $self->get_char_safe(q[<]); | |||||||||||||||||||||||||||||||||||||||||||
| 241 | 89 | ▶ | if ($self->buffer =~ /^<\(/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | $self->get_char_safe(q[<]); | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $self->get_char_safe(q[(]); | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | return $self->new_token(LTLTP, $self->start_line, $self->start_column, '<<('); | |||||||||||||||||||||||||||||||||||||||||||
| 245 | } elsif ($self->buffer =~ /^</o) { | ||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | $self->get_char_safe(q[<]); | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | return $self->new_token(LTLT, $self->start_line, $self->start_column, '<<'); | |||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | 89 | ▶ | if ($self->buffer =~ m/^[\x23-\x3d\x3f-\x5a\x5d-\x7e]*>/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 251 | 89 | my $iri .= $self->read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 89 | chop($iri); | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 89 | return $self->new_token(IRI, $self->start_line, $self->start_column, $iri); | |||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | my $iri = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if (length($self->buffer) == 0) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | my $c = $self->peek_char; | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | last unless defined($c); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | ▶ | if (substr($self->buffer, 0, 1) eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $self->get_char_safe('\\'); | |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | my $esc = $self->get_char; | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | if ($esc eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | $iri .= "\\"; | |||||||||||||||||||||||||||||||||||||||||||
| 267 | } elsif ($esc eq 'U') { | ||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my $codepoint = $self->read_length(8); | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | $self->_throw_error("Bad unicode escape codepoint '$codepoint'") unless ($codepoint =~ /^[0-9A-Fa-f]+$/o); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | $iri .= $self->unescape_hex($codepoint); | |||||||||||||||||||||||||||||||||||||||||||
| 271 | } elsif ($esc eq 'u') { | ||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | my $codepoint = $self->read_length(4); | |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | $self->_throw_error("Bad unicode escape codepoint '$codepoint'") unless ($codepoint =~ /^[0-9A-Fa-f]+$/o); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $char = $self->unescape_hex($codepoint); | |||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ($char =~ /[<>" {}|\\^`]/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | $self->_throw_error(sprintf("Bad IRI character: '%s' (0x%x)", $char, ord($char))); | |||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $iri .= $char; | |||||||||||||||||||||||||||||||||||||||||||
| 279 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $self->_throw_error("Unrecognized iri escape '$esc'"); | |||||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 282 | } elsif ($self->buffer =~ /^[^<>\x00-\x20\\"{}|^`]+/o) { | ||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | $iri .= $self->read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 284 | } elsif (substr($self->buffer, 0, 1) eq '>') { | ||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||||
| 286 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my $c = $self->peek_char; | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $self->_throw_error("Got '$c' while expecting IRI character"); | |||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $self->get_char_safe(q[>]); | |||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | return $self->new_token(IRI, $self->start_line, $self->start_column, $iri); | |||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||
| 295 | 5 | ▶ | sub unescape_hex { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unescape_hex: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 296 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 5 | my $codepoint = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 5 | my $cp = hex($codepoint); | |||||||||||||||||||||||||||||||||||||||||||
| 299 | 5 | ▶ | if ($cp >= 0xd800 && $cp <= 0xdfff) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$cp >= 55296 and $cp <= 57343
MC/DC50%1/2
$cp >= 55296 and $cp <= 57343
$cp >= 55296
$cp <= 57343
Truth table66%2/3
A and B
A= $cp >= 55296B= $cp <= 57343
| |||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | $self->_throw_error("Invalid use of surrogate codepoint in escape sequence: '$codepoint'", $codepoint); | |||||||||||||||||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 302 | 4 | return chr($cp); | |||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | 24 | ▶ | sub _get_bnode { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_bnode: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 306 | 24 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 24 | $self->read_word('_:'); | |||||||||||||||||||||||||||||||||||||||||||
| 308 | 24 | ▶ | $self->_throw_error("Expected: name") unless ($self->buffer =~ /^${r_bnode_id}/o); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 309 | 24 | my $name = substr($self->buffer, 0, $+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 310 | 24 | $self->read_word($name); | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 24 | return $self->new_token(BNODE, $self->start_line, $self->start_column, $name); | |||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||
| 314 | 10 | ▶ | sub _get_number { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_number: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 315 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 316 | 10 | ▶ | if ($self->buffer =~ /^${r_double}/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | return $self->new_token(DOUBLE, $self->start_line, $self->start_column, $self->read_length($+[0])); | |||||||||||||||||||||||||||||||||||||||||||
| 318 | } elsif ($self->buffer =~ /^${r_decimal}/o) { | ||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | return $self->new_token(DECIMAL, $self->start_line, $self->start_column, $self->read_length($+[0])); | |||||||||||||||||||||||||||||||||||||||||||
| 320 | } elsif ($self->buffer =~ /^${r_integer}/o) { | ||||||||||||||||||||||||||||||||||||||||||||
| 321 | 10 | return $self->new_token(INTEGER, $self->start_line, $self->start_column, $self->read_length($+[0])); | |||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $self->_throw_error("Expected number"); | |||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | sub _get_comment { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_comment: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | $self->get_char_safe('#'); | |||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $comment = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my $c = $self->peek_char; | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | while (length($c) and $c !~ /[\r\n]/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $c and not $c =~ /[\r\n]/ou
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
| |||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | $comment .= $self->get_char; | |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $c = $self->peek_char; | |||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | if (length($c) and $c =~ /[\r\n]/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $c and $c =~ /[\r\n]/ou
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
| |||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $self->get_char; | |||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | return $self->new_token(COMMENT, $self->start_line, $self->start_column, $comment); | |||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||
| 341 | 26 | ▶ | sub _get_double_literal { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_double_literal: called CC=13 SCAR=28.5
| |||||||||||||||||||||||||||||||||||||||||||||
| 342 | 26 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 343 | # my $c = $self->peek_char(); | ||||||||||||||||||||||||||||||||||||||||||||
| 344 | 26 | $self->get_char_safe(q["]); | |||||||||||||||||||||||||||||||||||||||||||
| 345 | 26 | ▶ | if (substr($self->buffer, 0, 2) eq q[""]) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 346 | # #x22 #x22 #x22 lcharacter* #x22 #x22 #x22 | ||||||||||||||||||||||||||||||||||||||||||||
| 347 | 3 | $self->read_word(q[""]); | |||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||
| 349 | 3 | my $quote_count = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 3 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 3 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||
| 352 | 12 | ▶ | if (length($self->buffer) == 0) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $self->fill_buffer; | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | $self->_throw_error("Found EOF in string literal") if (length($self->buffer) == 0); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 355 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 356 | 12 | ▶ | if (substr($self->buffer, 0, 1) eq '"') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 357 | 9 | my $c = $self->get_char; | |||||||||||||||||||||||||||||||||||||||||||
| 358 | 9 | $quote_count++; | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 9 | ▶ | last if ($quote_count == 3); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 360 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 361 | 3 | ▶ | if ($quote_count) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $string .= '"' foreach (1..$quote_count); | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $quote_count = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 365 | 3 | ▶ | if (substr($self->buffer, 0, 1) eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $string .= $self->_get_escaped_char(); | |||||||||||||||||||||||||||||||||||||||||||
| 367 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 368 | 3 | $self->{buffer} =~ /^[^"\\]+/; | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 3 | $string .= $self->read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 373 | 3 | return $self->new_token(STRING3D, $self->start_line, $self->start_column, $string); | |||||||||||||||||||||||||||||||||||||||||||
| 374 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 375 | ### #x22 scharacter* #x22 | ||||||||||||||||||||||||||||||||||||||||||||
| 376 | 23 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 23 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 46 | ▶ | if (substr($self->buffer, 0, 1) eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1 | my $c = $self->_get_escaped_char(); | |||||||||||||||||||||||||||||||||||||||||||
| 380 | 1 | $string .= $c; | |||||||||||||||||||||||||||||||||||||||||||
| 381 | } elsif ($self->buffer =~ /^[^"\\]+/o) { | ||||||||||||||||||||||||||||||||||||||||||||
| 382 | 22 | my $s = $self->read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 22 | $string .= $s; | |||||||||||||||||||||||||||||||||||||||||||
| 384 | } elsif (substr($self->buffer, 0, 1) eq '"') { | ||||||||||||||||||||||||||||||||||||||||||||
| 385 | 23 | last; | |||||||||||||||||||||||||||||||||||||||||||
| 386 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | my $c = $self->peek_char; | |||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if (defined($c)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | $self->_throw_error("Got '$c' while expecting string character"); | |||||||||||||||||||||||||||||||||||||||||||
| 390 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $self->_throw_error("Got EOF while expecting string character"); | |||||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 394 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 395 | 23 | $self->get_char_safe(q["]); | |||||||||||||||||||||||||||||||||||||||||||
| 396 | 23 | return $self->new_token(STRING1D, $self->start_line, $self->start_column, $string); | |||||||||||||||||||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||||
| 400 | 7 | ▶ | sub _get_single_literal { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_single_literal: called CC=14 SCAR=30.7
| |||||||||||||||||||||||||||||||||||||||||||||
| 401 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 7 | $self->get_char_safe("'"); | |||||||||||||||||||||||||||||||||||||||||||
| 403 | 7 | ▶ | if (substr($self->buffer, 0, 2) eq q['']) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 404 | # #x22 #x22 #x22 lcharacter* #x22 #x22 #x22 | ||||||||||||||||||||||||||||||||||||||||||||
| 405 | 2 | $self->read_word(q['']); | |||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||
| 407 | 2 | my $quote_count = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 408 | 2 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 2 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 8 | ▶ | if (length($self->buffer) == 0) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $self->fill_buffer; | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | $self->_throw_error("Found EOF in string literal") if (length($self->buffer) == 0); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 414 | 8 | ▶ | if (substr($self->buffer, 0, 1) eq "'") { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 415 | 6 | my $c = $self->get_char; | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 6 | $quote_count++; | |||||||||||||||||||||||||||||||||||||||||||
| 417 | 6 | ▶ | last if ($quote_count == 3); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 418 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 419 | 2 | ▶ | if ($quote_count) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | $string .= "'" foreach (1..$quote_count); | |||||||||||||||||||||||||||||||||||||||||||
| 421 | 0 | $quote_count = 0; | |||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 423 | 2 | ▶ | if (substr($self->buffer, 0, 1) eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | $string .= $self->_get_escaped_char(); | |||||||||||||||||||||||||||||||||||||||||||
| 425 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 426 | 2 | $self->{buffer} =~ /^[^'\\]+/; | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 2 | $string .= $self->read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 431 | 2 | return $self->new_token(STRING3S, $self->start_line, $self->start_column, $string); | |||||||||||||||||||||||||||||||||||||||||||
| 432 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 433 | ### #x22 scharacter* #x22 | ||||||||||||||||||||||||||||||||||||||||||||
| 434 | 5 | my $string = ''; | |||||||||||||||||||||||||||||||||||||||||||
| 435 | 5 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 10 | ▶ | $self->fill_buffer unless (length($self->buffer)); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 437 | 10 | ▶ | if (substr($self->buffer, 0, 1) eq '\\') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 438 | 6 | $string .= $self->_get_escaped_char(); | |||||||||||||||||||||||||||||||||||||||||||
| 439 | } elsif ($self->buffer =~ /^[^'\\]+/o) { | ||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | $string .= $self->read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 441 | } elsif (substr($self->buffer, 0, 1) eq "'") { | ||||||||||||||||||||||||||||||||||||||||||||
| 442 | 4 | last; | |||||||||||||||||||||||||||||||||||||||||||
| 443 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | my $c = $self->peek_char(); | |||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | if (defined($c)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | $self->_throw_error("Got '$c' while expecting string character"); | |||||||||||||||||||||||||||||||||||||||||||
| 447 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | $self->_throw_error("Got EOF while expecting string character"); | |||||||||||||||||||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 452 | 4 | $self->get_char_safe(q[']); | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 4 | return $self->new_token(STRING1S, $self->start_line, $self->start_column, $string); | |||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | 7 | ▶ | sub _get_escaped_char { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_escaped_char: called CC=12 SCAR=30.2
| |||||||||||||||||||||||||||||||||||||||||||||
| 458 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 459 | 7 | my $c = $self->peek_char; | |||||||||||||||||||||||||||||||||||||||||||
| 460 | 7 | $self->get_char_safe('\\'); | |||||||||||||||||||||||||||||||||||||||||||
| 461 | 7 | my $esc = $self->get_char; | |||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | ▶ | if ($esc eq '\\') { return "\\" } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 9 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 463 | 2 | elsif ($esc =~ /^['">]$/) { return $esc } | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | elsif ($esc eq 'r') { return "\r" } | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | elsif ($esc eq 't') { return "\t" } | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 0 | elsif ($esc eq 'n') { return "\n" } | |||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | elsif ($esc eq 'b') { return "\b" } | |||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | elsif ($esc eq 'f') { return "\f" } | |||||||||||||||||||||||||||||||||||||||||||
| 469 | elsif ($esc eq 'U') { | ||||||||||||||||||||||||||||||||||||||||||||
| 470 | 2 | my $codepoint = $self->read_length(8); | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 2 | ▶ | $self->_throw_error("Bad unicode escape codepoint '$codepoint'") unless ($codepoint =~ /^[0-9A-Fa-f]+$/o); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 472 | 2 | return $self->unescape_hex($codepoint); | |||||||||||||||||||||||||||||||||||||||||||
| 473 | } elsif ($esc eq 'u'){ | ||||||||||||||||||||||||||||||||||||||||||||
| 474 | 3 | my $codepoint = $self->read_length(4); | |||||||||||||||||||||||||||||||||||||||||||
| 475 | 3 | ▶ | $self->_throw_error("Bad unicode escape codepoint '$codepoint'") unless ($codepoint =~ /^[0-9A-Fa-f]+$/o); | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 476 | 3 | return $self->unescape_hex($codepoint); | |||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | $self->_throw_error("Unrecognized string escape '$esc'"); | |||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||
| 481 | 35 | ▶ | sub _get_keyword { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_keyword: called CC=7 SCAR=23.8
| |||||||||||||||||||||||||||||||||||||||||||||
| 482 | 35 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 483 | 35 | $self->get_char_safe('@'); | |||||||||||||||||||||||||||||||||||||||||||
| 484 | 35 | ▶ | if ($self->buffer =~ /^base/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | $self->read_word('base'); | |||||||||||||||||||||||||||||||||||||||||||
| 486 | 0 | return $self->new_token(TURTLEBASE, $self->start_line, $self->start_column); | |||||||||||||||||||||||||||||||||||||||||||
| 487 | } elsif ($self->buffer =~ /^prefix/o) { | ||||||||||||||||||||||||||||||||||||||||||||
| 488 | 31 | $self->read_word('prefix'); | |||||||||||||||||||||||||||||||||||||||||||
| 489 | 31 | return $self->new_token(TURTLEPREFIX, $self->start_line, $self->start_column); | |||||||||||||||||||||||||||||||||||||||||||
| 490 | } elsif ($self->buffer =~ /^version/o) { | ||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | $self->read_word('version'); | |||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | return $self->new_token(TURTLEVERSION, $self->start_line, $self->start_column); | |||||||||||||||||||||||||||||||||||||||||||
| 493 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 494 | 4 | ▶ | if ($self->buffer =~ /^[a-zA-Z]+(-[a-zA-Z0-9]+)*(--[a-zA-Z]+)?\b/o) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 495 | 4 | my $lang = $self->read_length($+[0]); | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 4 | ▶ | if ($lang !~ /--(ltr|rtl)$/ and $lang =~ /--(\w+)$/) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $lang =~ /--(ltr|rtl)$/u and $lang =~ /--(\w+)$/u
MC/DC0%0/2
not $lang =~ /--(ltr|rtl)$/u and $lang =~ /--(\w+)$/u
not $lang =~ /--(ltr|rtl)$/u
$lang =~ /--(\w+)$/u
Truth table33%1/3
not(A) and B
A= not $lang =~ /--(ltr|rtl)$/uB= $lang =~ /--(\w+)$/u
| |||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | $self->_throw_error("Expected base direction to be 'ltr' or 'rtl', but found '$1'"); | |||||||||||||||||||||||||||||||||||||||||||
| 498 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 499 | 4 | return $self->new_token(LANG, $self->start_line, $self->start_column, $lang); | |||||||||||||||||||||||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | $self->_throw_error("Expected keyword or language tag"); | |||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||
| 505 | 1 | ▶ | sub _throw_error { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_throw_error: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||
| 506 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 507 | 1 | my $error = shift; | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | ▶ | my $text = shift // ''; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() // ""
MC/DC0%0/1
shift() // ""
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||
| 509 | 1 | my $len = length($text); | |||||||||||||||||||||||||||||||||||||||||||
| 510 | 1 | my $line = $self->line; | |||||||||||||||||||||||||||||||||||||||||||
| 511 | 1 | my $col = $self->column; | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 1 | my $loc = "at $line:$col"; | |||||||||||||||||||||||||||||||||||||||||||
| 513 | 1 | ▶ | if ($len > 0) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 514 | 1 | ▶ | if ($col >= $len) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 515 | 1 | $col -= $len; | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 1 | $loc = "at $line:$col"; | |||||||||||||||||||||||||||||||||||||||||||
| 517 | } else { | ||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | $loc = "near $line:$col" | |||||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | Carp::confess "$error $loc with buffer: " . Dumper($self->buffer); | |||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||
| 525 | 50 | 1; | |||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||||
| 527 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||