| 1 | 50 | ▶ | use v5.14; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 50 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | =head1 NAME | ||||||||||
| 5 | |||||||||||
| 6 | AtteanX::SPARQL::Token - Token objects used for parsing and serializing SPARQL | ||||||||||
| 7 | |||||||||||
| 8 | =head1 VERSION | ||||||||||
| 9 | |||||||||||
| 10 | This document describes AtteanX::SPARQL::Token version 0.040 | ||||||||||
| 11 | |||||||||||
| 12 | =head1 SYNOPSIS | ||||||||||
| 13 | |||||||||||
| 14 | use v5.14; | ||||||||||
| 15 | use Attean; | ||||||||||
| 16 | |||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||
| 18 | |||||||||||
| 19 | The AtteanX::SPARQL::Token class represents tokens produced and used | ||||||||||
| 20 | during parsing and serializing of SPARQL. | ||||||||||
| 21 | |||||||||||
| 22 | =head1 ATTRIBUTES | ||||||||||
| 23 | |||||||||||
| 24 | =over 4 | ||||||||||
| 25 | |||||||||||
| 26 | =item C<< type >> | ||||||||||
| 27 | |||||||||||
| 28 | An integer indicating the token type, defined in L<AtteanX::Parser::Turtle::Constants> | ||||||||||
| 29 | |||||||||||
| 30 | =item C<< start_line >> | ||||||||||
| 31 | |||||||||||
| 32 | The line number in the source text that this token begins on. | ||||||||||
| 33 | |||||||||||
| 34 | =item C<< start_column >> | ||||||||||
| 35 | |||||||||||
| 36 | The column number in the source text that this token begins on. | ||||||||||
| 37 | |||||||||||
| 38 | =item C<< line >> | ||||||||||
| 39 | |||||||||||
| 40 | The line number in the source text that this token ends on. | ||||||||||
| 41 | |||||||||||
| 42 | =item C<< column >> | ||||||||||
| 43 | |||||||||||
| 44 | The column number in the source text that this token ends on. | ||||||||||
| 45 | |||||||||||
| 46 | =item C<< args >> | ||||||||||
| 47 | |||||||||||
| 48 | An array of values associated with the token (e.g. the integer value of an INT token). | ||||||||||
| 49 | |||||||||||
| 50 | =back | ||||||||||
| 51 | |||||||||||
| 52 | =head1 METHODS | ||||||||||
| 53 | |||||||||||
| 54 | =over 4 | ||||||||||
| 55 | |||||||||||
| 56 | =cut | ||||||||||
| 57 | |||||||||||
| 58 | package AtteanX::SPARQL::Token 0.040; | ||||||||||
| 59 | |||||||||||
| 60 | 50 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 61 | 50 | ▶ | use Types::Standard qw(ArrayRef Str); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 62 | 50 | ▶ | use List::Util qw(mesh); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 63 | 50 | ▶ | use Sub::Util qw(set_subname); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 64 | 50 | ▶ | use AtteanX::SPARQL::Constants; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 65 | 50 | ▶ | use namespace::clean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 66 | |||||||||||
| 67 | 50 | has type => ( is => 'ro', ); | |||||||||
| 68 | 50 | has start_line => ( is => 'ro', ); | |||||||||
| 69 | 50 | has start_column => ( is => 'ro', ); | |||||||||
| 70 | 50 | has line => ( is => 'ro', ); | |||||||||
| 71 | 50 | has column => ( is => 'ro', ); | |||||||||
| 72 | 50 | has args => ( is => 'ro', isa => ArrayRef[Str]); | |||||||||
| 73 | |||||||||||
| 74 | 50 | extends 'AtteanX::Parser::Turtle::Token'; | |||||||||
| 75 | |||||||||||
| 76 | =item C<< value >> | ||||||||||
| 77 | |||||||||||
| 78 | Returns the token value. | ||||||||||
| 79 | |||||||||||
| 80 | =cut | ||||||||||
| 81 | |||||||||||
| 82 | 1750 | ▶ | sub value { | ||||||||
|
Subroutine
value: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 83 | 1750 | my $self = shift; | |||||||||
| 84 | 1750 | my $args = $self->args; | |||||||||
| 85 | 1750 | return $args->[0]; | |||||||||
| 86 | } | ||||||||||
| 87 | |||||||||||
| 88 | =item C<< fast_constructor ( $type, $start_line, $start_col, $line, $col, \@args ) >> | ||||||||||
| 89 | |||||||||||
| 90 | Returns a new token object. | ||||||||||
| 91 | |||||||||||
| 92 | =cut | ||||||||||
| 93 | |||||||||||
| 94 | 50 | my @KEYS = qw(type start_line start_column line column args); | |||||||||
| 95 | 2746 | ▶ | sub fast_constructor { | ||||||||
|
Subroutine
fast_constructor: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 96 | 2746 | my $class = shift; | |||||||||
| 97 | 2746 | return $class->new( | |||||||||
| 98 | mesh \@KEYS, \@_ | ||||||||||
| 99 | ); | ||||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | { | ||||||||||
| 103 | 50 | my %tokens = ( | |||||||||
| 104 | a => [A, 'a'], | ||||||||||
| 105 | prefix => [PREFIX, '@prefix'], | ||||||||||
| 106 | base => [BASE, '@base'], | ||||||||||
| 107 | lparen => [LPAREN, '('], | ||||||||||
| 108 | rparen => [RPAREN, ')'], | ||||||||||
| 109 | lbracket => [LBRACKET, '['], | ||||||||||
| 110 | rbracket => [RBRACKET, ']'], | ||||||||||
| 111 | dot => [DOT, '.'], | ||||||||||
| 112 | comma => [COMMA, ','], | ||||||||||
| 113 | semicolon => [SEMICOLON, ';'], | ||||||||||
| 114 | hathat => [HATHAT, '^^'], | ||||||||||
| 115 | |||||||||||
| 116 | lbrace => [LBRACE, '{'], | ||||||||||
| 117 | rbrace => [RBRACE, '}'], | ||||||||||
| 118 | op_andand => [ANDAND, '&&'], | ||||||||||
| 119 | anon => [ANON, '[]'], | ||||||||||
| 120 | op_bang => [BANG, '!'], | ||||||||||
| 121 | op_ge => [GE, '>='], | ||||||||||
| 122 | op_gt => [GT, '>'], | ||||||||||
| 123 | path_hat => [HAT, '^'], | ||||||||||
| 124 | op_le => [LE, '<='], | ||||||||||
| 125 | op_lt => [LT, '<'], | ||||||||||
| 126 | minus => [MINUS, '-'], | ||||||||||
| 127 | nil => [NIL, '()'], | ||||||||||
| 128 | op_ne => [NOTEQUALS, '!='], | ||||||||||
| 129 | path_or => [OR, '|'], | ||||||||||
| 130 | op_oror => [OROR, '||'], | ||||||||||
| 131 | op_plus => [PLUS, '+'], | ||||||||||
| 132 | question => [QUESTION, '?'], | ||||||||||
| 133 | slash => [SLASH, '/'], | ||||||||||
| 134 | star => [STAR, '*'], | ||||||||||
| 135 | |||||||||||
| 136 | ltlt => [LTLT, '<<'], | ||||||||||
| 137 | gtgt => [GTGT, '>>'], | ||||||||||
| 138 | lannot => [LANNOT, '{|'], | ||||||||||
| 139 | rannot => [RANNOT, '|}'], | ||||||||||
| 140 | tilde => [TILDE, '~'], | ||||||||||
| 141 | ); | ||||||||||
| 142 | 50 | for my $name (keys %tokens) { | |||||||||
| 143 | 1750 | my ($type, $value) = @{ $tokens{ $name } }; | |||||||||
| 144 | 4 | ▶ | my $code = sub { | ||||||||
|
Subroutine
lparen: called CC=1 SCAR=0.0
Subroutine
comma: called CC=1 SCAR=0.0
| |||||||||||
| 145 | 4 | my $class = shift; | |||||||||
| 146 | 4 | return $class->fast_constructor($type, -1, -1, -1, -1, [$value]); | |||||||||
| 147 | 1750 | }; | |||||||||
| 148 | 1750 | Sub::Install::install_sub({ | |||||||||
| 149 | code => set_subname($name, $code), | ||||||||||
| 150 | as => $name | ||||||||||
| 151 | }); | ||||||||||
| 152 | } | ||||||||||
| 153 | } | ||||||||||
| 154 | |||||||||||
| 155 | =item C<< keyword( $kw ) >> | ||||||||||
| 156 | |||||||||||
| 157 | Returns a new L<AtteanX::SPARQL::Token> object with the C<KEYWORD> type and | ||||||||||
| 158 | C<$kw> value. | ||||||||||
| 159 | |||||||||||
| 160 | =cut | ||||||||||
| 161 | |||||||||||
| 162 | 224 | ▶ | sub keyword { | ||||||||
|
Subroutine
keyword: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 163 | 224 | my $class = shift; | |||||||||
| 164 | 224 | my $kw = shift; | |||||||||
| 165 | 224 | return $class->fast_constructor(KEYWORD, -1, -1, -1, -1, [uc($kw)]); | |||||||||
| 166 | } | ||||||||||
| 167 | |||||||||||
| 168 | =item C<< integer( $value ) >> | ||||||||||
| 169 | |||||||||||
| 170 | Returns a new L<AtteanX::SPARQL::Token> object with the C<INTEGER> type and | ||||||||||
| 171 | the given C<$value>. | ||||||||||
| 172 | |||||||||||
| 173 | =cut | ||||||||||
| 174 | |||||||||||
| 175 | 10 | ▶ | sub integer { | ||||||||
|
Subroutine
integer: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 176 | 10 | my $class = shift; | |||||||||
| 177 | 10 | my $value = shift; | |||||||||
| 178 | 10 | return $class->fast_constructor(INTEGER, -1, -1, -1, -1, [+$value] ); | |||||||||
| 179 | } | ||||||||||
| 180 | |||||||||||
| 181 | =item C<< as_string >> | ||||||||||
| 182 | |||||||||||
| 183 | Returns a string description of the token including the token type and any | ||||||||||
| 184 | associated values. | ||||||||||
| 185 | |||||||||||
| 186 | =cut | ||||||||||
| 187 | |||||||||||
| 188 | 1 | ▶ | sub as_string { | ||||||||
|
Subroutine
as_string: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 189 | 1 | my $self = shift; | |||||||||
| 190 | 1 | my $type = decrypt_constant($self->type); | |||||||||
| 191 | 1 | my @args = @{ $self->args }; | |||||||||
| 192 | 1 | ▶ | if (scalar(@args)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 193 | 1 | return "$type(" . join(', ', @args) . ")"; | |||||||||
| 194 | } else { | ||||||||||
| 195 | 0 | return $type; | |||||||||
| 196 | } | ||||||||||
| 197 | } | ||||||||||
| 198 | |||||||||||
| 199 | 50 | __PACKAGE__->meta->make_immutable; | |||||||||
| 200 | |||||||||||
| 201 | 50 | 1; | |||||||||
| 202 | |||||||||||
| 203 | =back | ||||||||||
| 204 | |||||||||||
| 205 | =head1 BUGS | ||||||||||
| 206 | |||||||||||
| 207 | Please report any bugs or feature requests to through the GitHub web interface | ||||||||||
| 208 | at L<https://github.com/kasei/attean/issues>. | ||||||||||
| 209 | |||||||||||
| 210 | =head1 SEE ALSO | ||||||||||
| 211 | |||||||||||
| 212 | |||||||||||
| 213 | |||||||||||
| 214 | =head1 AUTHOR | ||||||||||
| 215 | |||||||||||
| 216 | Gregory Todd Williams C<< <gwilliams@cpan.org> >> | ||||||||||
| 217 | |||||||||||
| 218 | =head1 COPYRIGHT | ||||||||||
| 219 | |||||||||||
| 220 | Copyright (c) 2014--2026 Gregory Todd Williams. | ||||||||||
| 221 | This program is free software; you can redistribute it and/or modify it under | ||||||||||
| 222 | the same terms as Perl itself. | ||||||||||
| 223 | |||||||||||
| 224 | =cut | ||||||||||