line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package DBIx::MyParsePP::Token; |
3
|
|
|
|
|
|
|
|
4
|
8
|
|
|
8
|
|
48
|
use DBIx::MyParsePP::Symbols; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
165
|
|
5
|
8
|
|
|
8
|
|
56
|
use strict; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
194
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
1; |
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
39
|
use constant TOKEN_TYPE => 0; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
600
|
|
10
|
8
|
|
|
8
|
|
40
|
use constant TOKEN_VALUE => 1; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
3937
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
769
|
|
|
769
|
0
|
1223
|
my ($class, $type, $value) = @_; |
14
|
769
|
|
|
|
|
1371
|
my $token = bless([], $class); |
15
|
769
|
|
|
|
|
1462
|
$token->[TOKEN_TYPE] = $type; |
16
|
769
|
|
|
|
|
1105
|
$token->[TOKEN_VALUE] = $value; |
17
|
769
|
|
|
|
|
1259
|
return $token; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub value { |
21
|
147
|
|
|
147
|
0
|
292
|
return $_[0]->[TOKEN_VALUE]; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub type { |
25
|
268
|
|
|
268
|
0
|
548
|
return $_[0]->[TOKEN_TYPE]; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub getValue { |
29
|
0
|
|
|
0
|
0
|
0
|
return $_[0]->[TOKEN_VALUE]; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub getType { |
33
|
0
|
|
|
0
|
0
|
0
|
return $_[0]->[TOKEN_TYPE]; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub setType { |
37
|
0
|
|
|
0
|
0
|
0
|
$_[0]->[TOKEN_TYPE] = $_[1]; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub setValue { |
41
|
0
|
|
|
0
|
0
|
0
|
$_[0]->[TOKEN_VALUE] = $_[1]; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub extract { |
45
|
58
|
|
|
58
|
0
|
73
|
my $token = shift; |
46
|
|
|
|
|
|
|
|
47
|
58
|
|
|
|
|
78
|
foreach my $match (@_) { |
48
|
118
|
100
|
|
|
|
151
|
return $token if $token->type() eq $match; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
54
|
|
|
|
|
83
|
return undef; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub extractInner { |
55
|
0
|
|
|
0
|
0
|
0
|
my $token = shift; |
56
|
0
|
|
|
|
|
0
|
return $token->extract(@_); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub children { |
60
|
1
|
|
|
1
|
0
|
3
|
return (); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Shrinking has no effect on tokens, just return original token |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub shrink { |
66
|
89
|
|
|
89
|
0
|
172
|
return $_[0]; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub toString { |
70
|
54
|
|
|
54
|
0
|
65
|
my $token = shift; |
71
|
54
|
|
|
|
|
71
|
my $type = $token->type(); |
72
|
54
|
|
|
|
|
69
|
my $value = $token->value(); |
73
|
54
|
|
|
|
|
72
|
my $result; |
74
|
|
|
|
|
|
|
|
75
|
54
|
50
|
66
|
|
|
244
|
if ($type eq 'NCHAR_STRING') { |
|
|
50
|
33
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
76
|
0
|
|
|
|
|
0
|
$result = $value; |
77
|
0
|
|
|
|
|
0
|
$result =~ s{\\}{\\\\}sgio; |
78
|
0
|
|
|
|
|
0
|
$result =~ s{'}{\\'}sgio; |
79
|
0
|
|
|
|
|
0
|
$result = "N'".$result."'"; |
80
|
|
|
|
|
|
|
} elsif ($type eq 'IDENT_QUOTED') { |
81
|
0
|
|
|
|
|
0
|
return '`'.$value.'` '; |
82
|
|
|
|
|
|
|
} elsif ($type eq 'GLOBAL_SYM') { |
83
|
0
|
|
|
|
|
0
|
return $value; # No spaces |
84
|
|
|
|
|
|
|
} elsif ($type eq 'SET_VAR') { |
85
|
0
|
|
|
|
|
0
|
$result = ':='; |
86
|
|
|
|
|
|
|
} elsif ($type eq 'BIN_NUM') { |
87
|
0
|
|
|
|
|
0
|
$result = "b'".$value."'"; |
88
|
|
|
|
|
|
|
} elsif ($type eq 'HEX_NUM') { |
89
|
0
|
|
|
|
|
0
|
$result = ' 0x'.$value.' '; |
90
|
|
|
|
|
|
|
} elsif ($type eq 'TEXT_STRING') { |
91
|
0
|
|
|
|
|
0
|
$result = $value; |
92
|
0
|
|
|
|
|
0
|
$result =~ s{\\}{\\\\}sgio; |
93
|
0
|
|
|
|
|
0
|
$result =~ s{'}{\\'}sgio; |
94
|
0
|
|
|
|
|
0
|
$result = "'".$result."'"; |
95
|
|
|
|
|
|
|
} elsif ($type eq 'UNDERSCORE_CHARSET') { |
96
|
0
|
|
|
|
|
0
|
$result = '_'.$value; |
97
|
|
|
|
|
|
|
} elsif ($type eq '@') { |
98
|
0
|
|
|
|
|
0
|
return '@'; # No leading space |
99
|
|
|
|
|
|
|
} elsif (($type eq 'IDENT') || ($type eq 'LEX_HOSTNAME')) { |
100
|
43
|
|
|
|
|
170
|
return $value.' '; # No leading space |
101
|
|
|
|
|
|
|
} elsif ($DBIx::MyParsePP::Symbols::functions->{uc($value)} eq $type) { |
102
|
0
|
|
|
|
|
0
|
return ' '.$value; # No trailing space |
103
|
|
|
|
|
|
|
} elsif ($type eq '(') { |
104
|
0
|
|
|
|
|
0
|
return $value.' '; # No leading space; |
105
|
|
|
|
|
|
|
} elsif (($type eq '.') || ($type eq '*')) { |
106
|
11
|
|
|
|
|
25
|
return $value; # No spaces around table.field, etc. |
107
|
|
|
|
|
|
|
} else { |
108
|
0
|
|
|
|
|
0
|
$result = ' '.$value.' '; |
109
|
|
|
|
|
|
|
} |
110
|
0
|
|
|
|
|
0
|
return $result; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub print { |
114
|
0
|
|
|
0
|
0
|
0
|
return $_[0]->toString(); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub isEqual { |
118
|
46
|
50
|
|
46
|
0
|
98
|
return 0 if !$_[1]->isa( 'DBIx::MyParsePP::Token' ); |
119
|
46
|
|
33
|
|
|
62
|
return $_[0]->type() eq $_[1]->type() && |
120
|
|
|
|
|
|
|
$_[0]->value() eq $_[1]->value(); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
1; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
__END__ |