| 1 | package PPI::Token::Operator; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | =pod | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | PPI::Token::Operator - Token class for operators | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | =head1 INHERITANCE | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | PPI::Token::Operator | ||||||||||||||||||||||||||||
| 12 | isa PPI::Token | ||||||||||||||||||||||||||||
| 13 | isa PPI::Element | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # This is the list of valid operators | ||||||||||||||||||||||||||||
| 18 | ++ -- ** ! ~ + - | ||||||||||||||||||||||||||||
| 19 | =~ !~ * / % x | ||||||||||||||||||||||||||||
| 20 | << >> lt gt le ge cmp ~~ | ||||||||||||||||||||||||||||
| 21 | == != <=> . .. ... , | ||||||||||||||||||||||||||||
| 22 | & | ^ && || // | ||||||||||||||||||||||||||||
| 23 | ? : **= += -= .= *= /= | ||||||||||||||||||||||||||||
| 24 | %= x= &= |= ^= <<= >>= &&= | ||||||||||||||||||||||||||||
| 25 | ||= //= < > <= >= <> => -> | ||||||||||||||||||||||||||||
| 26 | and or xor not eq ne <<>> | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | All operators in PPI are created as C<PPI::Token::Operator> objects, | ||||||||||||||||||||||||||||
| 32 | including the ones that may superficially look like a L<PPI::Token::Word> | ||||||||||||||||||||||||||||
| 33 | object. | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | =head1 METHODS | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | There are no additional methods beyond those provided by the parent | ||||||||||||||||||||||||||||
| 38 | L<PPI::Token> and L<PPI::Element> classes. | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | =cut | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 63 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 63 | ▶ | use PPI::Token (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | 63 | ▶ | use PPI::Singletons '%OPERATOR'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 63 | our $VERSION = '1.260'; # VERSION | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 63 | our @ISA = "PPI::Token"; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | ##################################################################### | ||||||||||||||||||||||||||||
| 55 | # Tokenizer Methods | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | sub __TOKENIZER__on_char { | ||||||||||||||||||||||||||||
| 58 | 45182 | ▶ | my $t = $_[1]; | ||||||||||||||||||||||||||
|
Subroutine
__TOKENIZER__on_char: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||
| 59 | 45182 | my $char = substr( $t->{line}, $t->{line_cursor}, 1 ); | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | # Are we still an operator if we add the next character | ||||||||||||||||||||||||||||
| 62 | 45182 | my $content = $t->{token}->{content}; | |||||||||||||||||||||||||||
| 63 | # special case for <<>> operator | ||||||||||||||||||||||||||||
| 64 | 45182 | ▶ | if(length($content) < 4 && | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
length $content < 4 and $content . substr($t->{"line"}, $t->{"line_cursor"}, 4 - length($content)) eq "<<>>"
MC/DC100%2/2
length $content < 4 and $content . substr($t->{"line"}, $t->{"line_cursor"}, 4 - length($content)) eq "<<>>"
length $content < 4
$content . substr($t->{"line"}, $t->{"line_cursor"}, 4 - length($content)) eq "<<>>"
Truth table100%3/3
A and B
A= length $content < 4B= $content . substr($t->{"line"}, $t->{"line_cursor"}, 4 - length($content)) eq "<<>>"
| |||||||||||||||||||||||||||||
| 65 | $content . substr( $t->{line}, $t->{line_cursor}, 4 - length($content) ) eq '<<>>') { | ||||||||||||||||||||||||||||
| 66 | 6 | return 1; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 45176 | ▶ | return 1 if $OPERATOR{ $content . $char }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # Handle the special case of a .1234 decimal number | ||||||||||||||||||||||||||||
| 71 | 33928 | ▶ | if ( $content eq '.' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 984 | ▶ | if ( $char =~ /^[0-9]$/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | # This is a decimal number | ||||||||||||||||||||||||||||
| 74 | 287 | $t->{class} = $t->{token}->set_class('Number::Float'); | |||||||||||||||||||||||||||
| 75 | 287 | return $t->{class}->__TOKENIZER__on_char( $t ); | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | # Handle the special case if we might be a here-doc | ||||||||||||||||||||||||||||
| 80 | 33641 | ▶ | if ( $content eq '<<' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 525 | pos $t->{line} = $t->{line_cursor}; | |||||||||||||||||||||||||||
| 82 | # Either <<FOO or << 'FOO' or <<\FOO or | ||||||||||||||||||||||||||||
| 83 | # <<~FOO or <<~ 'FOO' or <<~\FOO | ||||||||||||||||||||||||||||
| 84 | ### Is the zero-width look-ahead assertion really | ||||||||||||||||||||||||||||
| 85 | ### supposed to be there? | ||||||||||||||||||||||||||||
| 86 | 525 | ▶ | if ( $t->{line} =~ m/\G ~? (?: (?!\d)\w | \s*['"`] | \\\w ) /gcx ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | # This is a here-doc. | ||||||||||||||||||||||||||||
| 88 | # Change the class and move to the HereDoc's own __TOKENIZER__on_char method. | ||||||||||||||||||||||||||||
| 89 | 216 | $t->{class} = $t->{token}->set_class('HereDoc'); | |||||||||||||||||||||||||||
| 90 | 216 | return $t->{class}->__TOKENIZER__on_char( $t ); | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # Handle the special case of the null Readline | ||||||||||||||||||||||||||||
| 95 | 33425 | ▶ | $t->{class} = $t->{token}->set_class('QuoteLike::Readline') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$content eq "<>" or $content eq "<<>>"
MC/DC100%2/2
$content eq "<>" or $content eq "<<>>"
$content eq "<>"
$content eq "<<>>"
Truth table100%3/3
A or B
A= $content eq "<>"B= $content eq "<<>>"
| |||||||||||||||||||||||||||||
| 96 | if $content eq '<>' or $content eq '<<>>'; | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # Finalize normally | ||||||||||||||||||||||||||||
| 99 | 33425 | $t->_finalize_token->__TOKENIZER__on_char( $t ); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 63 | 1; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =pod | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | See the L<support section|PPI/SUPPORT> in the main module. | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | Adam Kennedy E<lt>adamk@cpan.orgE<gt> | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | Copyright 2001 - 2011 Adam Kennedy. | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | This program is free software; you can redistribute | ||||||||||||||||||||||||||||
| 119 | it and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | The full text of the license can be found in the | ||||||||||||||||||||||||||||
| 122 | LICENSE file included with this module. | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||||||||||