|  line  | 
 stmt  | 
 bran  | 
 cond  | 
 sub  | 
 pod  | 
 time  | 
 code  | 
| 
1
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 package Pistachio::Token;  | 
| 
2
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # ABSTRACT: expresses a single source code language token as an object  | 
| 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
4
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
15
 | 
 use strict;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
100
 | 
    | 
| 
5
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
16
 | 
 use warnings;  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
4
 | 
    | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
150
 | 
    | 
| 
6
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 our $VERSION = '0.10'; # VERSION  | 
| 
7
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
8
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 use constant {  | 
| 
9
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
1025
 | 
     TYP => 0,   | 
| 
10
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
     VAL => 1  | 
| 
11
 | 
3
 | 
 
 | 
 
 | 
  
3
  
 | 
 
 | 
17
 | 
 };  | 
| 
 
 | 
3
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5
 | 
    | 
| 
12
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
13
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @param string $type    object type  | 
| 
14
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @param string $token_type    token type  | 
| 
15
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @param string  $token_value    token value  | 
| 
16
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @return Pistachio::Token  | 
| 
17
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub new {  | 
| 
18
 | 
30
 | 
 
 | 
 
 | 
  
30
  
 | 
  
0
  
 | 
39
 | 
     my $type = shift;  | 
| 
19
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
55
 | 
     my ($token_type, $token_value) = @_;  | 
| 
20
 | 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
178
 | 
     bless [$token_type, $token_value], $type;  | 
| 
21
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
22
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
23
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @param object $this    a Pistachio::Token  | 
| 
24
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @param string [optional] $set    set to value, if any  | 
| 
25
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @return string    token type  | 
| 
26
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub type {   | 
| 
27
 | 
503
 | 
 
 | 
 
 | 
  
503
  
 | 
  
0
  
 | 
920
 | 
     my ($this, $set) = @_;  | 
| 
28
 | 
503
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
1012
 | 
     $this->[TYP] = $set if $set;  | 
| 
29
 | 
503
 | 
 
 | 
 
 | 
 
 | 
 
 | 
5260
 | 
     $this->[TYP];  | 
| 
30
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
31
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
32
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @param Pistachio::Token  | 
| 
33
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @return string    token value  | 
| 
34
 | 
28
 | 
 
 | 
 
 | 
  
28
  
 | 
  
0
  
 | 
114
 | 
 sub value { shift->[VAL] }  | 
| 
35
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
36
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @param Pistachio::Token  | 
| 
37
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @return int    1 if contained token type is Whitespace, or 0  | 
| 
38
 | 
40
 | 
  
100
  
 | 
 
 | 
  
40
  
 | 
  
0
  
 | 
72
 | 
 sub whitespace { shift->type eq 'Whitespace' ? 1 : 0 }  | 
| 
39
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
40
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @param Pistachio::Token $this  | 
| 
41
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @param string $type    a type to match against  | 
| 
42
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @param coderef [optional] $val    a value match sub, or undef  | 
| 
43
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 # @return int    1 if token object matches $type and $val, or 0  | 
| 
44
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 sub match {  | 
| 
45
 | 
411
 | 
 
 | 
 
 | 
  
411
  
 | 
  
0
  
 | 
697
 | 
     my ($this, $type, $val) = @_;  | 
| 
46
 | 
411
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
742
 | 
     return 0 unless $this->type =~ /^$type/;  | 
| 
47
 | 
60
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
238
 | 
     return 1 unless defined $val;  | 
| 
48
 | 
24
 | 
  
100
  
 | 
 
 | 
 
 | 
 
 | 
53
 | 
     $val->($this->value) ? 1 : 0;  | 
| 
49
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 }  | 
| 
50
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
51
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 1;  | 
| 
52
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
    | 
| 
53
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 
 | 
 __END__  |